1 /*
2 * Copyright (c) 1997, 2013, 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
95 this.codec = codec;
96 sf = features.get(SerializationFeature.class);
97 MTOMFeature mtom = features.get(MTOMFeature.class);
98 if(mtom == null)
99 this.mtomFeature = new MTOMFeature();
100 else
101 this.mtomFeature = mtom;
102 }
103
104 /**
105 * Return the soap 1.1 and soap 1.2 specific XOP packaged ContentType
106 *
107 * @return A non-null content type for soap11 or soap 1.2 content type
108 */
109 @Override
110 public ContentType getStaticContentType(Packet packet) {
111 return getStaticContentTypeStatic(packet, version);
112 }
113
114 public static ContentType getStaticContentTypeStatic(Packet packet, SOAPVersion version) {
115 ContentType ct = (ContentType) packet.getInternalContentType();
116 if ( ct != null ) return ct;
117
118 String uuid = UUID.randomUUID().toString();
119 String boundary = "uuid:" + uuid;
120 String rootId = "<rootpart*"+uuid+"@example.jaxws.sun.com>";
121 String soapActionParameter = SOAPVersion.SOAP_11.equals(version) ? null : createActionParameter(packet);
122
123 String boundaryParameter = "boundary=\"" + boundary +"\"";
124 String messageContentType = MULTIPART_RELATED_MIME_TYPE +
125 ";start=\""+rootId +"\"" +
126 ";type=\"" + XOP_XML_MIME_TYPE + "\";" +
127 boundaryParameter +
128 ";start-info=\"" + version.contentType +
129 (soapActionParameter == null? "" : soapActionParameter) +
130 "\"";
131
132 ContentTypeImpl ctImpl = SOAPVersion.SOAP_11.equals(version) ?
133 new ContentTypeImpl(messageContentType, (packet.soapAction == null)?"":packet.soapAction, null) :
134 new ContentTypeImpl(messageContentType, null, null);
135 ctImpl.setBoundary(boundary);
136 ctImpl.setRootId(rootId);
137 packet.setContentType(ctImpl);
310 // If SerializationFeature is set, just use that encoding
311 if (sf != null && sf.getEncoding() != null) {
312 return sf.getEncoding().equals("") ? SOAPBindingCodec.DEFAULT_ENCODING : sf.getEncoding();
313 }
314 return determinePacketEncoding(packet);
315 }
316
317 public static String determinePacketEncoding(Packet packet) {
318 if (packet != null && packet.endpoint != null) {
319 // Use request message's encoding for Server-side response messages
320 String charset = (String)packet.invocationProperties.get(DECODED_MESSAGE_CHARSET);
321 return charset == null
322 ? SOAPBindingCodec.DEFAULT_ENCODING : charset;
323 }
324
325 // Use default encoding for client-side request messages
326 return SOAPBindingCodec.DEFAULT_ENCODING;
327 }
328
329 public static class MtomStreamWriterImpl extends XMLStreamWriterFilter implements XMLStreamWriterEx,
330 MtomStreamWriter, HasEncoding {
331 private final List<ByteArrayBuffer> mtomAttachments;
332 private final String boundary;
333 private final MTOMFeature myMtomFeature;
334 public MtomStreamWriterImpl(XMLStreamWriter w, List<ByteArrayBuffer> mtomAttachments, String b, MTOMFeature myMtomFeature) {
335 super(w);
336 this.mtomAttachments = mtomAttachments;
337 this.boundary = b;
338 this.myMtomFeature = myMtomFeature;
339 }
340
341 @Override
342 public void writeBinary(byte[] data, int start, int len, String contentType) throws XMLStreamException {
343 //check threshold and if less write as base64encoded value
344 if(myMtomFeature.getThreshold() > len){
345 writeCharacters(DatatypeConverterImpl._printBase64Binary(data, start, len));
346 return;
347 }
348 ByteArrayBuffer bab = new ByteArrayBuffer(new DataHandler(new ByteArrayDataSource(data, start, len, contentType)), boundary);
349 writeBinary(bab);
350 }
|
1 /*
2 * Copyright (c) 1997, 2014, 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
95 this.codec = codec;
96 sf = features.get(SerializationFeature.class);
97 MTOMFeature mtom = features.get(MTOMFeature.class);
98 if(mtom == null)
99 this.mtomFeature = new MTOMFeature();
100 else
101 this.mtomFeature = mtom;
102 }
103
104 /**
105 * Return the soap 1.1 and soap 1.2 specific XOP packaged ContentType
106 *
107 * @return A non-null content type for soap11 or soap 1.2 content type
108 */
109 @Override
110 public ContentType getStaticContentType(Packet packet) {
111 return getStaticContentTypeStatic(packet, version);
112 }
113
114 public static ContentType getStaticContentTypeStatic(Packet packet, SOAPVersion version) {
115 ContentTypeImpl ct = (ContentTypeImpl) packet.getInternalContentType();
116 if ( ct != null ) {
117 //Note - this case of boundary = null or root content ID = null should never happen
118 //after a recent bug fix in Packet.shouldUseMtom logic, but just in
119 //case we get here with a Packet that has a non-null content type with
120 //a null boundary, the content type of the Packet will be reset
121 if (ct.getBoundary() != null && ct.getRootId() != null)
122 return ct;
123 }
124 String uuid = UUID.randomUUID().toString();
125 String boundary = "uuid:" + uuid;
126 String rootId = "<rootpart*"+uuid+"@example.jaxws.sun.com>";
127 String soapActionParameter = SOAPVersion.SOAP_11.equals(version) ? null : createActionParameter(packet);
128
129 String boundaryParameter = "boundary=\"" + boundary +"\"";
130 String messageContentType = MULTIPART_RELATED_MIME_TYPE +
131 ";start=\""+rootId +"\"" +
132 ";type=\"" + XOP_XML_MIME_TYPE + "\";" +
133 boundaryParameter +
134 ";start-info=\"" + version.contentType +
135 (soapActionParameter == null? "" : soapActionParameter) +
136 "\"";
137
138 ContentTypeImpl ctImpl = SOAPVersion.SOAP_11.equals(version) ?
139 new ContentTypeImpl(messageContentType, (packet.soapAction == null)?"":packet.soapAction, null) :
140 new ContentTypeImpl(messageContentType, null, null);
141 ctImpl.setBoundary(boundary);
142 ctImpl.setRootId(rootId);
143 packet.setContentType(ctImpl);
316 // If SerializationFeature is set, just use that encoding
317 if (sf != null && sf.getEncoding() != null) {
318 return sf.getEncoding().equals("") ? SOAPBindingCodec.DEFAULT_ENCODING : sf.getEncoding();
319 }
320 return determinePacketEncoding(packet);
321 }
322
323 public static String determinePacketEncoding(Packet packet) {
324 if (packet != null && packet.endpoint != null) {
325 // Use request message's encoding for Server-side response messages
326 String charset = (String)packet.invocationProperties.get(DECODED_MESSAGE_CHARSET);
327 return charset == null
328 ? SOAPBindingCodec.DEFAULT_ENCODING : charset;
329 }
330
331 // Use default encoding for client-side request messages
332 return SOAPBindingCodec.DEFAULT_ENCODING;
333 }
334
335 public static class MtomStreamWriterImpl extends XMLStreamWriterFilter implements XMLStreamWriterEx,
336 com.sun.xml.internal.org.jvnet.staxex.util.MtomStreamWriter, HasEncoding {
337 private final List<ByteArrayBuffer> mtomAttachments;
338 private final String boundary;
339 private final MTOMFeature myMtomFeature;
340 public MtomStreamWriterImpl(XMLStreamWriter w, List<ByteArrayBuffer> mtomAttachments, String b, MTOMFeature myMtomFeature) {
341 super(w);
342 this.mtomAttachments = mtomAttachments;
343 this.boundary = b;
344 this.myMtomFeature = myMtomFeature;
345 }
346
347 @Override
348 public void writeBinary(byte[] data, int start, int len, String contentType) throws XMLStreamException {
349 //check threshold and if less write as base64encoded value
350 if(myMtomFeature.getThreshold() > len){
351 writeCharacters(DatatypeConverterImpl._printBase64Binary(data, start, len));
352 return;
353 }
354 ByteArrayBuffer bab = new ByteArrayBuffer(new DataHandler(new ByteArrayDataSource(data, start, len, contentType)), boundary);
355 writeBinary(bab);
356 }
|