author | mkos |
Fri, 23 Aug 2013 09:57:21 +0100 | |
changeset 19645 | 36f707905f2b |
parent 16791 | fe5141eabb0e |
child 23782 | 953bfc3fbe31 |
permissions | -rw-r--r-- |
12009 | 1 |
/* |
16791 | 2 |
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
12009 | 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 |
package com.sun.xml.internal.ws.message.jaxb; |
|
27 |
||
28 |
import com.sun.istack.internal.FragmentContentHandler; |
|
29 |
import com.sun.xml.internal.stream.buffer.MutableXMLStreamBuffer; |
|
30 |
import com.sun.xml.internal.stream.buffer.XMLStreamBuffer; |
|
31 |
import com.sun.xml.internal.stream.buffer.XMLStreamBufferResult; |
|
32 |
import com.sun.xml.internal.ws.api.SOAPVersion; |
|
33 |
import com.sun.xml.internal.ws.api.message.AttachmentSet; |
|
19645
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
34 |
import com.sun.xml.internal.ws.api.message.Header; |
12009 | 35 |
import com.sun.xml.internal.ws.api.message.HeaderList; |
36 |
import com.sun.xml.internal.ws.api.message.Message; |
|
16791 | 37 |
import com.sun.xml.internal.ws.api.message.MessageHeaders; |
19645
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
38 |
import com.sun.xml.internal.ws.api.message.StreamingSOAP; |
12009 | 39 |
import com.sun.xml.internal.ws.encoding.SOAPBindingCodec; |
40 |
import com.sun.xml.internal.ws.message.AbstractMessageImpl; |
|
41 |
import com.sun.xml.internal.ws.message.AttachmentSetImpl; |
|
42 |
import com.sun.xml.internal.ws.message.RootElementSniffer; |
|
43 |
import com.sun.xml.internal.ws.message.stream.StreamMessage; |
|
44 |
import com.sun.xml.internal.ws.spi.db.BindingContext; |
|
45 |
import com.sun.xml.internal.ws.spi.db.BindingContextFactory; |
|
46 |
import com.sun.xml.internal.ws.spi.db.XMLBridge; |
|
47 |
import com.sun.xml.internal.ws.streaming.XMLStreamWriterUtil; |
|
48 |
import com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil; |
|
49 |
import com.sun.xml.internal.ws.streaming.MtomStreamWriter; |
|
19645
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
50 |
import com.sun.xml.internal.ws.util.xml.XMLReaderComposite; |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
51 |
import com.sun.xml.internal.ws.util.xml.XMLReaderComposite.ElemInfo; |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
52 |
|
12009 | 53 |
import org.xml.sax.ContentHandler; |
54 |
import org.xml.sax.ErrorHandler; |
|
55 |
import org.xml.sax.SAXException; |
|
56 |
||
57 |
import javax.xml.bind.JAXBContext; |
|
58 |
import javax.xml.bind.JAXBElement; |
|
59 |
import javax.xml.bind.JAXBException; |
|
60 |
import javax.xml.bind.Marshaller; |
|
61 |
import javax.xml.bind.Unmarshaller; |
|
62 |
import javax.xml.bind.attachment.AttachmentMarshaller; |
|
63 |
import javax.xml.bind.annotation.XmlRootElement; |
|
64 |
import javax.xml.bind.util.JAXBResult; |
|
65 |
import javax.xml.namespace.QName; |
|
66 |
import javax.xml.stream.XMLStreamException; |
|
67 |
import javax.xml.stream.XMLStreamReader; |
|
68 |
import javax.xml.stream.XMLStreamWriter; |
|
69 |
import static javax.xml.stream.XMLStreamConstants.START_DOCUMENT; |
|
70 |
import javax.xml.transform.Source; |
|
71 |
import javax.xml.ws.WebServiceException; |
|
72 |
import java.io.OutputStream; |
|
19645
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
73 |
import java.util.List; |
12009 | 74 |
|
75 |
/** |
|
76 |
* {@link Message} backed by a JAXB bean. |
|
77 |
* |
|
78 |
* @author Kohsuke Kawaguchi |
|
79 |
*/ |
|
19645
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
80 |
public final class JAXBMessage extends AbstractMessageImpl implements StreamingSOAP { |
16791 | 81 |
private MessageHeaders headers; |
12009 | 82 |
|
83 |
/** |
|
84 |
* The JAXB object that represents the payload. |
|
85 |
*/ |
|
86 |
private final Object jaxbObject; |
|
87 |
||
88 |
private final XMLBridge bridge; |
|
89 |
||
90 |
/** |
|
91 |
* For the use case of a user-supplied JAXB context that is not |
|
92 |
* a known JAXB type, as when creating a Disaptch object with a |
|
93 |
* JAXB object parameter, we will marshal and unmarshal directly with |
|
94 |
* the context object, as there is no Bond available. In this case, |
|
95 |
* swaRef is not supported. |
|
96 |
*/ |
|
97 |
private final JAXBContext rawContext; |
|
98 |
||
99 |
/** |
|
100 |
* Lazily sniffed payload element name |
|
101 |
*/ |
|
102 |
private String nsUri,localName; |
|
103 |
||
104 |
/** |
|
105 |
* If we have the infoset representation for the payload, this field is non-null. |
|
106 |
*/ |
|
107 |
private XMLStreamBuffer infoset; |
|
108 |
||
16791 | 109 |
public static Message create(BindingContext context, Object jaxbObject, SOAPVersion soapVersion, MessageHeaders headers, AttachmentSet attachments) { |
12009 | 110 |
if(!context.hasSwaRef()) { |
111 |
return new JAXBMessage(context,jaxbObject,soapVersion,headers,attachments); |
|
112 |
} |
|
113 |
||
114 |
// If we have swaRef, then that means we might have attachments. |
|
115 |
// to comply with the packet API, we need to eagerly turn the JAXB object into infoset |
|
116 |
// to correctly find out about attachments. |
|
117 |
||
118 |
try { |
|
119 |
MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer(); |
|
120 |
||
121 |
Marshaller m = context.createMarshaller(); |
|
122 |
AttachmentMarshallerImpl am = new AttachmentMarshallerImpl(attachments); |
|
123 |
m.setAttachmentMarshaller(am); |
|
124 |
am.cleanup(); |
|
125 |
m.marshal(jaxbObject,xsb.createFromXMLStreamWriter()); |
|
126 |
||
127 |
// any way to reuse this XMLStreamBuffer in StreamMessage? |
|
128 |
return new StreamMessage(headers,attachments,xsb.readAsXMLStreamReader(),soapVersion); |
|
129 |
} catch (JAXBException e) { |
|
130 |
throw new WebServiceException(e); |
|
131 |
} catch (XMLStreamException e) { |
|
132 |
throw new WebServiceException(e); |
|
133 |
} |
|
134 |
} |
|
135 |
/** |
|
136 |
* Creates a {@link Message} backed by a JAXB bean. |
|
137 |
* |
|
138 |
* @param context |
|
139 |
* The JAXBContext to be used for marshalling. |
|
140 |
* @param jaxbObject |
|
141 |
* The JAXB object that represents the payload. must not be null. This object |
|
142 |
* must be bound to an element (which means it either is a {@link JAXBElement} or |
|
143 |
* an instanceof a class with {@link XmlRootElement}). |
|
144 |
* @param soapVersion |
|
145 |
* The SOAP version of the message. Must not be null. |
|
146 |
*/ |
|
147 |
public static Message create(BindingContext context, Object jaxbObject, SOAPVersion soapVersion) { |
|
148 |
return create(context,jaxbObject,soapVersion,null,null); |
|
149 |
} |
|
150 |
/** @deprecated */ |
|
151 |
public static Message create(JAXBContext context, Object jaxbObject, SOAPVersion soapVersion) { |
|
152 |
return create(BindingContextFactory.create(context),jaxbObject,soapVersion,null,null); |
|
153 |
} |
|
154 |
||
155 |
/** |
|
156 |
* @deprecated |
|
157 |
* For use when creating a Dispatch object with an unknown JAXB implementation |
|
158 |
* for he JAXBContext parameter. |
|
159 |
* |
|
160 |
*/ |
|
161 |
public static Message createRaw(JAXBContext context, Object jaxbObject, SOAPVersion soapVersion) { |
|
162 |
return new JAXBMessage(context,jaxbObject,soapVersion,null,null); |
|
163 |
} |
|
164 |
||
16791 | 165 |
private JAXBMessage( BindingContext context, Object jaxbObject, SOAPVersion soapVer, MessageHeaders headers, AttachmentSet attachments ) { |
12009 | 166 |
super(soapVer); |
167 |
// this.bridge = new MarshallerBridge(context); |
|
168 |
this.bridge = context.createFragmentBridge(); |
|
169 |
this.rawContext = null; |
|
170 |
this.jaxbObject = jaxbObject; |
|
171 |
this.headers = headers; |
|
172 |
this.attachmentSet = attachments; |
|
173 |
} |
|
174 |
||
16791 | 175 |
private JAXBMessage( JAXBContext rawContext, Object jaxbObject, SOAPVersion soapVer, MessageHeaders headers, AttachmentSet attachments ) { |
12009 | 176 |
super(soapVer); |
177 |
// this.bridge = new MarshallerBridge(context); |
|
178 |
this.rawContext = rawContext; |
|
179 |
this.bridge = null; |
|
180 |
this.jaxbObject = jaxbObject; |
|
181 |
this.headers = headers; |
|
182 |
this.attachmentSet = attachments; |
|
183 |
} |
|
184 |
||
185 |
/** |
|
186 |
* Creates a {@link Message} backed by a JAXB bean. |
|
187 |
* |
|
188 |
* @param bridge |
|
189 |
* Specify the payload tag name and how <tt>jaxbObject</tt> is bound. |
|
190 |
* @param jaxbObject |
|
191 |
*/ |
|
192 |
public static Message create(XMLBridge bridge, Object jaxbObject, SOAPVersion soapVer) { |
|
193 |
if(!bridge.context().hasSwaRef()) { |
|
194 |
return new JAXBMessage(bridge,jaxbObject,soapVer); |
|
195 |
} |
|
196 |
||
197 |
// If we have swaRef, then that means we might have attachments. |
|
198 |
// to comply with the packet API, we need to eagerly turn the JAXB object into infoset |
|
199 |
// to correctly find out about attachments. |
|
200 |
||
201 |
try { |
|
202 |
MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer(); |
|
203 |
||
204 |
AttachmentSetImpl attachments = new AttachmentSetImpl(); |
|
205 |
AttachmentMarshallerImpl am = new AttachmentMarshallerImpl(attachments); |
|
206 |
bridge.marshal(jaxbObject,xsb.createFromXMLStreamWriter(), am); |
|
207 |
am.cleanup(); |
|
208 |
||
209 |
// any way to reuse this XMLStreamBuffer in StreamMessage? |
|
210 |
return new StreamMessage(null,attachments,xsb.readAsXMLStreamReader(),soapVer); |
|
211 |
} catch (JAXBException e) { |
|
212 |
throw new WebServiceException(e); |
|
213 |
} catch (XMLStreamException e) { |
|
214 |
throw new WebServiceException(e); |
|
215 |
} |
|
216 |
} |
|
217 |
||
218 |
private JAXBMessage(XMLBridge bridge, Object jaxbObject, SOAPVersion soapVer) { |
|
219 |
super(soapVer); |
|
220 |
// TODO: think about a better way to handle BridgeContext |
|
221 |
this.bridge = bridge; |
|
222 |
this.rawContext = null; |
|
223 |
this.jaxbObject = jaxbObject; |
|
224 |
QName tagName = bridge.getTypeInfo().tagName; |
|
225 |
this.nsUri = tagName.getNamespaceURI(); |
|
226 |
this.localName = tagName.getLocalPart(); |
|
227 |
this.attachmentSet = new AttachmentSetImpl(); |
|
228 |
} |
|
229 |
||
230 |
/** |
|
231 |
* Copy constructor. |
|
232 |
*/ |
|
233 |
public JAXBMessage(JAXBMessage that) { |
|
234 |
super(that); |
|
235 |
this.headers = that.headers; |
|
236 |
if(this.headers!=null) |
|
237 |
this.headers = new HeaderList(this.headers); |
|
238 |
this.attachmentSet = that.attachmentSet; |
|
239 |
||
240 |
this.jaxbObject = that.jaxbObject; |
|
241 |
this.bridge = that.bridge; |
|
242 |
this.rawContext = that.rawContext; |
|
243 |
} |
|
244 |
||
16791 | 245 |
@Override |
12009 | 246 |
public boolean hasHeaders() { |
16791 | 247 |
return headers!=null && headers.hasHeaders(); |
12009 | 248 |
} |
249 |
||
16791 | 250 |
@Override |
251 |
public MessageHeaders getHeaders() { |
|
12009 | 252 |
if(headers==null) |
16791 | 253 |
headers = new HeaderList(getSOAPVersion()); |
12009 | 254 |
return headers; |
255 |
} |
|
256 |
||
16791 | 257 |
@Override |
12009 | 258 |
public String getPayloadLocalPart() { |
259 |
if(localName==null) |
|
260 |
sniff(); |
|
261 |
return localName; |
|
262 |
} |
|
263 |
||
16791 | 264 |
@Override |
12009 | 265 |
public String getPayloadNamespaceURI() { |
266 |
if(nsUri==null) |
|
267 |
sniff(); |
|
268 |
return nsUri; |
|
269 |
} |
|
270 |
||
16791 | 271 |
@Override |
12009 | 272 |
public boolean hasPayload() { |
273 |
return true; |
|
274 |
} |
|
275 |
||
276 |
/** |
|
277 |
* Obtains the tag name of the root element. |
|
278 |
*/ |
|
279 |
private void sniff() { |
|
280 |
RootElementSniffer sniffer = new RootElementSniffer(false); |
|
281 |
try { |
|
282 |
if (rawContext != null) { |
|
283 |
Marshaller m = rawContext.createMarshaller(); |
|
284 |
m.setProperty("jaxb.fragment", Boolean.TRUE); |
|
285 |
m.marshal(jaxbObject,sniffer); |
|
286 |
} else |
|
287 |
bridge.marshal(jaxbObject,sniffer,null); |
|
288 |
} catch (JAXBException e) { |
|
289 |
// if it's due to us aborting the processing after the first element, |
|
290 |
// we can safely ignore this exception. |
|
291 |
// |
|
292 |
// if it's due to error in the object, the same error will be reported |
|
293 |
// when the readHeader() method is used, so we don't have to report |
|
294 |
// an error right now. |
|
295 |
nsUri = sniffer.getNsUri(); |
|
296 |
localName = sniffer.getLocalName(); |
|
297 |
} |
|
298 |
} |
|
299 |
||
16791 | 300 |
@Override |
12009 | 301 |
public Source readPayloadAsSource() { |
302 |
return new JAXBBridgeSource(bridge,jaxbObject); |
|
303 |
} |
|
304 |
||
16791 | 305 |
@Override |
12009 | 306 |
public <T> T readPayloadAsJAXB(Unmarshaller unmarshaller) throws JAXBException { |
307 |
JAXBResult out = new JAXBResult(unmarshaller); |
|
308 |
// since the bridge only produces fragments, we need to fire start/end document. |
|
309 |
try { |
|
310 |
out.getHandler().startDocument(); |
|
311 |
if (rawContext != null) { |
|
312 |
Marshaller m = rawContext.createMarshaller(); |
|
313 |
m.setProperty("jaxb.fragment", Boolean.TRUE); |
|
314 |
m.marshal(jaxbObject,out); |
|
315 |
} else |
|
316 |
bridge.marshal(jaxbObject,out); |
|
317 |
out.getHandler().endDocument(); |
|
318 |
} catch (SAXException e) { |
|
319 |
throw new JAXBException(e); |
|
320 |
} |
|
321 |
return (T)out.getResult(); |
|
322 |
} |
|
323 |
||
16791 | 324 |
@Override |
12009 | 325 |
public XMLStreamReader readPayload() throws XMLStreamException { |
326 |
try { |
|
327 |
if(infoset==null) { |
|
328 |
if (rawContext != null) { |
|
19645
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
329 |
XMLStreamBufferResult sbr = new XMLStreamBufferResult(); |
12009 | 330 |
Marshaller m = rawContext.createMarshaller(); |
331 |
m.setProperty("jaxb.fragment", Boolean.TRUE); |
|
332 |
m.marshal(jaxbObject, sbr); |
|
19645
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
333 |
infoset = sbr.getXMLStreamBuffer(); |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
334 |
} else { |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
335 |
MutableXMLStreamBuffer buffer = new MutableXMLStreamBuffer(); |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
336 |
writePayloadTo(buffer.createFromXMLStreamWriter()); |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
337 |
infoset = buffer; |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
338 |
} |
12009 | 339 |
} |
340 |
XMLStreamReader reader = infoset.readAsXMLStreamReader(); |
|
341 |
if(reader.getEventType()== START_DOCUMENT) |
|
342 |
XMLStreamReaderUtil.nextElementContent(reader); |
|
343 |
return reader; |
|
344 |
} catch (JAXBException e) { |
|
345 |
// bug 6449684, spec 4.3.4 |
|
346 |
throw new WebServiceException(e); |
|
347 |
} |
|
348 |
} |
|
349 |
||
350 |
/** |
|
351 |
* Writes the payload as SAX events. |
|
352 |
*/ |
|
16791 | 353 |
@Override |
12009 | 354 |
protected void writePayloadTo(ContentHandler contentHandler, ErrorHandler errorHandler, boolean fragment) throws SAXException { |
355 |
try { |
|
356 |
if(fragment) |
|
357 |
contentHandler = new FragmentContentHandler(contentHandler); |
|
358 |
AttachmentMarshallerImpl am = new AttachmentMarshallerImpl(attachmentSet); |
|
359 |
if (rawContext != null) { |
|
360 |
Marshaller m = rawContext.createMarshaller(); |
|
361 |
m.setProperty("jaxb.fragment", Boolean.TRUE); |
|
362 |
m.setAttachmentMarshaller(am); |
|
363 |
m.marshal(jaxbObject,contentHandler); |
|
364 |
} else |
|
365 |
bridge.marshal(jaxbObject,contentHandler, am); |
|
366 |
am.cleanup(); |
|
367 |
} catch (JAXBException e) { |
|
368 |
// this is really more helpful but spec compliance |
|
369 |
// errorHandler.fatalError(new SAXParseException(e.getMessage(),NULL_LOCATOR,e)); |
|
370 |
// bug 6449684, spec 4.3.4 |
|
371 |
throw new WebServiceException(e.getMessage(),e); |
|
372 |
} |
|
373 |
} |
|
374 |
||
16791 | 375 |
@Override |
12009 | 376 |
public void writePayloadTo(XMLStreamWriter sw) throws XMLStreamException { |
377 |
try { |
|
378 |
// MtomCodec sets its own AttachmentMarshaller |
|
379 |
AttachmentMarshaller am = (sw instanceof MtomStreamWriter) |
|
380 |
? ((MtomStreamWriter)sw).getAttachmentMarshaller() |
|
381 |
: new AttachmentMarshallerImpl(attachmentSet); |
|
382 |
||
383 |
// Get the encoding of the writer |
|
384 |
String encoding = XMLStreamWriterUtil.getEncoding(sw); |
|
385 |
||
386 |
// Get output stream and use JAXB UTF-8 writer |
|
16791 | 387 |
OutputStream os = bridge.supportOutputStream() ? XMLStreamWriterUtil.getOutputStream(sw) : null; |
19645
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
388 |
if (rawContext != null) { |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
389 |
Marshaller m = rawContext.createMarshaller(); |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
390 |
m.setProperty("jaxb.fragment", Boolean.TRUE); |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
391 |
m.setAttachmentMarshaller(am); |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
392 |
if (os != null) { |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
393 |
m.marshal(jaxbObject, os); |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
394 |
} else { |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
395 |
m.marshal(jaxbObject, sw); |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
396 |
} |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
397 |
} else { |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
398 |
if (os != null && encoding != null && encoding.equalsIgnoreCase(SOAPBindingCodec.UTF8_ENCODING)) { |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
399 |
bridge.marshal(jaxbObject, os, sw.getNamespaceContext(), am); |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
400 |
} else { |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
401 |
bridge.marshal(jaxbObject, sw, am); |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
402 |
} |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
403 |
} |
12009 | 404 |
//cleanup() is not needed since JAXB doesn't keep ref to AttachmentMarshaller |
405 |
//am.cleanup(); |
|
406 |
} catch (JAXBException e) { |
|
407 |
// bug 6449684, spec 4.3.4 |
|
408 |
throw new WebServiceException(e); |
|
409 |
} |
|
410 |
} |
|
411 |
||
16791 | 412 |
@Override |
12009 | 413 |
public Message copy() { |
414 |
return new JAXBMessage(this); |
|
415 |
} |
|
416 |
||
19645
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
417 |
public XMLStreamReader readEnvelope() { |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
418 |
int base = soapVersion.ordinal()*3; |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
419 |
this.envelopeTag = DEFAULT_TAGS.get(base); |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
420 |
this.bodyTag = DEFAULT_TAGS.get(base+2); |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
421 |
List<XMLStreamReader> hReaders = new java.util.ArrayList<XMLStreamReader>(); |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
422 |
ElemInfo envElem = new ElemInfo(envelopeTag, null); |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
423 |
ElemInfo bdyElem = new ElemInfo(bodyTag, envElem); |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
424 |
for (Header h : getHeaders().asList()) { |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
425 |
try { |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
426 |
hReaders.add(h.readHeader()); |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
427 |
} catch (XMLStreamException e) { |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
428 |
throw new RuntimeException(e); |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
429 |
} |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
430 |
} |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
431 |
XMLStreamReader soapHeader = null; |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
432 |
if(hReaders.size()>0) { |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
433 |
headerTag = DEFAULT_TAGS.get(base+1); |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
434 |
ElemInfo hdrElem = new ElemInfo(headerTag, envElem); |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
435 |
soapHeader = new XMLReaderComposite(hdrElem, hReaders.toArray(new XMLStreamReader[hReaders.size()])); |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
436 |
} |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
437 |
try { |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
438 |
XMLStreamReader payload= readPayload(); |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
439 |
XMLStreamReader soapBody = new XMLReaderComposite(bdyElem, new XMLStreamReader[]{payload}); |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
440 |
XMLStreamReader[] soapContent = (soapHeader != null) ? new XMLStreamReader[]{soapHeader, soapBody} : new XMLStreamReader[]{soapBody}; |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
441 |
return new XMLReaderComposite(envElem, soapContent); |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
442 |
} catch (XMLStreamException e) { |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
443 |
throw new RuntimeException(e); |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
444 |
} |
36f707905f2b
8022885: Update JAX-WS RI integration to 2.2.9-b14140
mkos
parents:
16791
diff
changeset
|
445 |
} |
12009 | 446 |
} |