1 /*
   2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /**
  27  *  <h1>JAX-WS 2.0.1 Client Runtime</h1>
  28  * <P>This document describes the architecture of client side
  29  * JAX-WS 2.0.1 runtime.
  30  *
  31  * <h3>JAX-WS 2.0.1 Client Sequence Diagram</h3>
  32  * <img src='../../../../../jaxws/basic-client.seq.png'>
  33   * <h3>JAX-WS 2.0.1 Asynchronous Invocation Sequence Diagram</h3>
  34  * <img src='../../../../../jaxws/client-async.seq.png'>
  35   * <h3>JAX-WS 2.0.1 Dispatch Invocation Sequence Diagram</h3>
  36  * <img src='../../../../../jaxws/dispatch.seq.png'>
  37 
  38  * <H3>Message Flow</H3>
  39  * {@link com.sun.xml.internal.ws.client.WebService} provides client view of a Web service.
  40  * WebService.getPort returns an instance of {@link com.sun.xml.internal.ws.client.EndpointIFInvocationHandler}
  41  * with {@link com.sun.pept.ept.ContactInfoList} and {@link com.sun.pept.Delegate}
  42  * initialized. A method invocation on the port, obtained from WebService, invokes
  43  * {@link com.sun.xml.internal.ws.client.EndpointIFInvocationHandler#invoke}. This method
  44  * then creates a {@link com.sun.pept.ept.MessageInfo} and populates the data
  45  * (parameters specified by the user) and metadata such as RuntimeContext, RequestContext,
  46  * Message Exchange Pattern into this MessageInfo. This method then invokes
  47  * {@link com.sun.pept.Delegate#send} and returns the response.
  48  * <P></P>
  49  * The Delegate.send method iterates through the ContactInfoList and picks up the
  50  * correct {@link com.sun.pept.ept.ContactInfo} based upon the binding id of
  51  * {@link javax.xml.ws.BindingProvider} and sets it on the MessageInfo. After the
  52  * Delegate obtains a specific ContactInfo it uses that ContactInfo to obtain a
  53  * protocol-specific {@link com.sun.pept.protocol.MessageDispatcher}. There will be
  54  * two types of client-side MessageDispatchers for JAX-WS 2.0.1,
  55  * {@link com.sun.xml.internal.ws.protocol.soap.client.SOAPMessageDispatcher} and
  56  * {@link com.sun.xml.internal.ws.protocol.xml.client.XMLMessageDispatcher}. The Delegate
  57  * then invokes {@link com.sun.pept.protocol.MessageDispatcher#send}. The
  58  * MessageDispatcher.send method makes a decision about the synchronous and
  59  * asynchronous nature of the message exchange pattern and invokes separate methods
  60  * accordingly.
  61  * <p></P>
  62  * The MessageDispatcher uses ContactInfo to obtain
  63  * a {@link com.sun.xml.internal.ws.encoding.soap.client.SOAPXMLEncoder} which converts
  64  * the MessageInfo to {@link com.sun.xml.internal.ws.encoding.soap.internal.InternalMessage}.
  65  * There will be two types of client-side SOAPXMLEncoder for JAX-WS 2.0.1,
  66  * SOAPXMEncoder for SOAP 1.1 and {@link com.sun.xml.internal.ws.encoding.soap.client.SOAP12XMLEncoder}
  67  * for SOAP 1.2. The MessageDispatcher invokes configured handlers and use the
  68  * codec to convert the InternalMessage to a {@link javax.xml.soap.SOAPMessage}.
  69  * The metadata from the MessageInfo is classified into {@link javax.xml.soap.MimeHeaders}
  70  * of this SOAPMessage and context information for {@link com.sun.xml.internal.ws.api.server.WSConnection}.
  71  * The SOAPMessge is then written to the output stream of the WSConnection
  72  * obtained from MessageInfo.
  73  *<P></P>
  74  * The MessageDispatcher.receive method handles the response. The
  75  * SOAPMessageDispatcher extracts the SOAPMessage from the input stream of
  76  * WSConnection and performs the mustUnderstand processing followed by invocation
  77  * of any handlers. The MessageDispatcher uses ContactInfo to obtain a
  78  * {@link com.sun.xml.internal.ws.encoding.soap.client.SOAPXMLDecoder} which converts the SOAPMessage
  79  * to InternalMessage and then InternalMessage to MessageInfo. There will be two types of
  80  * client-side SOAPXMLDecoder for JAX-WS 2.0.1, SOAPXMLDencoder for SOAP 1.1 and
  81  * {@link com.sun.xml.internal.ws.encoding.soap.client.SOAP12XMLDecoder} for SOAP 1.2. The
  82  * response is returned back to the client code via Delegate.
  83  *
  84  * <H3>External Interactions</H3>
  85  * <H4>SAAJ API</H4>
  86  * <UL>
  87  *      <LI><P>JAX-WS creates SAAJ SOAPMessage from the HttpServletRequest.
  88  *      At present, JAX-WS reads all the bytes from the request stream and
  89  *      then creates SOAPMessage along with the HTTP headers.</P>
  90  * </UL>
  91  * <P>MessageFactory(binding).createMessage(MimeHeaders, InputStream)</P>
  92  * <UL>
  93  *      <LI><P>SOAPMessage parses the content from the stream including MIME
  94  *      data</P>
  95  *      <LI><P>com.sun.xml.internal.ws.server.SOAPMessageDispatcher::checkHeadersPeekBody()</P>
  96  *      <P>SOAPMessage.getSOAPHeader() is used for mustUnderstand processing
  97  *      of headers. It further uses
  98  *      SOAPHeader.examineMustUnderstandHeaderElements(role)</P>
  99  *      <P>SOAPMessage.getSOAPBody().getFistChild() is used for guessing the
 100  *      MEP of the request</P>
 101  *      <LI><P>com.sun.xml.internal.ws.handler.HandlerChainCaller:insertFaultMessage()</P>
 102  *      <P>SOAPMessage.getSOAPPart().getEnvelope() and some other SAAJ calls
 103  *      are made to create a fault in the SOAPMessage</P>
 104  *      <LI><P>com.sun.xml.internal.ws.handler.LogicalMessageImpl::getPayload()
 105  *      interacts with SAAJ to get body from SOAPMessage</P>
 106  *      <LI><P>com.sun.xml.internal.ws.encoding.soap.SOAPEncoder.toSOAPMessage(com.sun.xml.internal.ws.encoding.soap.internal.InternalMessage,
 107  *      SOAPMessage). There is a scenario where there is SOAPMessage and a
 108  *      logical handler sets payload as Source. To write to the stream,
 109  *      SOAPMessage.writeTo() is used but before that the body needs to be
 110  *      updated with logical handler' Source. Need to verify if this
 111  *      scenario is still happening since Handler.close() is changed to take
 112  *      MessageContext.</P>
 113  *      <LI><P>com.sun.xml.internal.ws.handlerSOAPMessageContextImpl.getHeaders()
 114  *      uses SAAJ API to get headers.</P>
 115  *      <LI><P>SOAPMessage.writeTo() is used to write response. At present,
 116  *      it writes into byte[] and this byte[] is written to
 117  *      HttpServletResponse.</P>
 118  * </UL>
 119  * <H4>JAXB API</H4>
 120  * <P>JAX-WS RI uses the JAXB API to marshall/unmarshall user created
 121  * JAXB objects with user created {@link javax.xml.bind.JAXBContext JAXBContext}.
 122  * Handler, Dispatch in JAX-WS API provide ways for the user to specify his/her own
 123  * JAXBContext. {@link com.sun.xml.internal.ws.encoding.jaxb.JAXBTypeSerializer JAXBTypeSerializer} class uses all these methods.</P>
 124  * <UL>
 125  *      <LI><p>{@link javax.xml.bind.Marshaller#marshal(Object,XMLStreamWriter) Marshaller.marshal(Object,XMLStreamWriter)}</p>
 126  *      <LI><P>{@link javax.xml.bind.Marshaller#marshal(Object,Result) Marshaller.marshal(Object, DomResult)}</P>
 127  *      <LI><P>{@link javax.xml.bind.Unmarshaller#unmarshal(XMLStreamReader) Object Unmarshaller.unmarshal(XMLStreamReader)}</P>
 128  *      <LI><P>{@link javax.xml.bind.Unmarshaller#unmarshal(Source) Object Unmarshaller.unmarshal(Source)}</P>
 129  * </UL>
 130  * The following two JAXB classes are implemented by JAX-WS to enable/implement MTOM and XOP
 131  * <UL>
 132  *      <LI><P>{@link javax.xml.bind.attachment.AttachmentMarshaller AttachmentMarshaller}</P>
 133  *      <LI><P>{@link javax.xml.bind.attachment.AttachmentUnmarshaller AttachmentUnmarshaller}</P>
 134  * </UL>
 135  * <H4>JAXB Runtime-API (private contract)</H4>
 136  * <P>JAX-WS RI uses these private API for serialization/deserialization
 137  * purposes. This private API is used to serialize/deserialize method
 138  * parameters at the time of JAXBTypeSerializer class uses all
 139  * these methods.</P>
 140  * <UL>
 141  *      <LI><P>{@link com.sun.xml.internal.bind.api.Bridge#marshal(BridgeContext, Object, XMLStreamWriter) Bridge.marshal(BridgeContext, Object, XMLStreamWriter)}</P>
 142  *      <LI><P>{@link com.sun.xml.internal.bind.api.Bridge#marshal(BridgeContext, Object, Node) Bridge.marshal(BridgeContext, Object, Node)}</P>
 143  *      <LI><P>{@link com.sun.xml.internal.bind.api.Bridge#unmarshal(BridgeContext, XMLStreamReader) Object Bridge.unmarshal(BridgeContext, XMLStreamReader)}</P>
 144  * </UL>
 145  *
 146  **/
 147 package com.sun.xml.internal.ws.client;
 148 
 149 import com.sun.xml.internal.bind.api.BridgeContext;
 150 
 151 import javax.xml.transform.Result;
 152 import javax.xml.transform.Source;
 153 import javax.xml.stream.XMLStreamReader;
 154 import javax.xml.stream.XMLStreamWriter;
 155 
 156 import org.w3c.dom.Node;