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