39 import com.sun.xml.internal.ws.resources.StreamingMessages; |
39 import com.sun.xml.internal.ws.resources.StreamingMessages; |
40 import com.sun.xml.internal.ws.util.ByteArrayBuffer; |
40 import com.sun.xml.internal.ws.util.ByteArrayBuffer; |
41 |
41 |
42 import javax.activation.DataSource; |
42 import javax.activation.DataSource; |
43 import javax.xml.ws.WebServiceException; |
43 import javax.xml.ws.WebServiceException; |
44 import javax.xml.ws.WebServiceFeature; |
|
45 |
44 |
46 import java.io.IOException; |
45 import java.io.IOException; |
47 import java.io.InputStream; |
46 import java.io.InputStream; |
48 import java.io.OutputStream; |
47 import java.io.OutputStream; |
49 import java.lang.reflect.Method; |
48 import java.lang.reflect.Method; |
94 /** |
93 /** |
95 * The Accept header for Fast Infoset and XML encodings |
94 * The Accept header for Fast Infoset and XML encodings |
96 */ |
95 */ |
97 private static final String fiXmlAccept = APPLICATION_FAST_INFOSET_MIME_TYPE + ", " + BASE_ACCEPT_VALUE; |
96 private static final String fiXmlAccept = APPLICATION_FAST_INFOSET_MIME_TYPE + ", " + BASE_ACCEPT_VALUE; |
98 |
97 |
99 private class AcceptContentType implements ContentType { |
98 private ContentTypeImpl setAcceptHeader(Packet p, ContentType c) { |
100 private ContentType _c; |
99 ContentTypeImpl ctImpl = (ContentTypeImpl)c; |
101 private String _accept; |
100 if (p.contentNegotiation == ContentNegotiation.optimistic |
102 |
101 || p.contentNegotiation == ContentNegotiation.pessimistic) { |
103 public AcceptContentType set(Packet p, ContentType c) { |
102 ctImpl.setAcceptHeader(fiXmlAccept); |
104 // TODO: need to compose based on underlying codecs |
103 } else { |
105 if (p.contentNegotiation == ContentNegotiation.optimistic |
104 ctImpl.setAcceptHeader(xmlAccept); |
106 || p.contentNegotiation == ContentNegotiation.pessimistic) { |
105 } |
107 _accept = fiXmlAccept; |
106 p.setContentType(ctImpl); |
108 } else { |
107 return ctImpl; |
109 _accept = xmlAccept; |
108 } |
110 } |
|
111 _c = c; |
|
112 return this; |
|
113 } |
|
114 |
|
115 public String getContentType() { |
|
116 return _c.getContentType(); |
|
117 } |
|
118 |
|
119 public String getSOAPActionHeader() { |
|
120 return _c.getSOAPActionHeader(); |
|
121 } |
|
122 |
|
123 public String getAcceptHeader() { |
|
124 return _accept; |
|
125 } |
|
126 } |
|
127 |
|
128 private AcceptContentType _adaptingContentType = new AcceptContentType(); |
|
129 |
109 |
130 public XMLHTTPBindingCodec(WSFeatureList f) { |
110 public XMLHTTPBindingCodec(WSFeatureList f) { |
131 super(SOAPVersion.SOAP_11, f); |
111 super(SOAPVersion.SOAP_11, f); |
132 |
112 |
133 xmlCodec = new XMLCodec(f); |
113 xmlCodec = new XMLCodec(f); |
134 |
114 |
135 fiCodec = getFICodec(); |
115 fiCodec = getFICodec(); |
136 } |
116 } |
137 |
117 |
|
118 @Override |
138 public String getMimeType() { |
119 public String getMimeType() { |
139 return null; |
120 return null; |
140 } |
121 } |
141 |
122 |
142 @Override |
123 @Override |
143 public ContentType getStaticContentType(Packet packet) { |
124 public ContentType getStaticContentType(Packet packet) { |
144 setRootCodec(packet); |
125 ContentType ct; |
145 |
126 if (packet.getInternalMessage() instanceof MessageDataSource) { |
146 ContentType ct = null; |
127 final MessageDataSource mds = (MessageDataSource)packet.getInternalMessage(); |
147 if (packet.getMessage() instanceof MessageDataSource) { |
|
148 final MessageDataSource mds = (MessageDataSource)packet.getMessage(); |
|
149 if (mds.hasUnconsumedDataSource()) { |
128 if (mds.hasUnconsumedDataSource()) { |
150 ct = getStaticContentType(mds); |
129 ct = getStaticContentType(mds); |
151 return (ct != null) |
130 return (ct != null) |
152 ? _adaptingContentType.set(packet, ct) |
131 ? setAcceptHeader(packet, ct) //_adaptingContentType.set(packet, ct) |
153 : null; |
132 : null; |
154 } |
133 } |
155 } |
134 } |
156 |
135 |
157 ct = super.getStaticContentType(packet); |
136 ct = super.getStaticContentType(packet); |
158 return (ct != null) |
137 return (ct != null) |
159 ? _adaptingContentType.set(packet, ct) |
138 ? setAcceptHeader(packet, ct) //_adaptingContentType.set(packet, ct) |
160 : null; |
139 : null; |
161 } |
140 } |
162 |
141 |
163 @Override |
142 @Override |
164 public ContentType encode(Packet packet, OutputStream out) throws IOException { |
143 public ContentType encode(Packet packet, OutputStream out) throws IOException { |
165 setRootCodec(packet); |
144 if (packet.getInternalMessage() instanceof MessageDataSource) { |
166 |
145 final MessageDataSource mds = (MessageDataSource)packet.getInternalMessage(); |
167 if (packet.getMessage() instanceof MessageDataSource) { |
|
168 final MessageDataSource mds = (MessageDataSource)packet.getMessage(); |
|
169 if (mds.hasUnconsumedDataSource()) |
146 if (mds.hasUnconsumedDataSource()) |
170 return _adaptingContentType.set(packet, encode(mds, out)); |
147 return setAcceptHeader(packet, encode(mds, out)); |
171 } |
148 } |
172 |
149 |
173 return _adaptingContentType.set(packet, super.encode(packet, out)); |
150 return setAcceptHeader(packet, super.encode(packet, out)); |
174 } |
151 } |
175 |
152 |
|
153 @Override |
176 public ContentType encode(Packet packet, WritableByteChannel buffer) { |
154 public ContentType encode(Packet packet, WritableByteChannel buffer) { |
177 throw new UnsupportedOperationException(); |
155 throw new UnsupportedOperationException(); |
178 } |
156 } |
179 |
157 |
180 @Override |
158 @Override |
206 if (!useFastInfosetForEncoding) { |
184 if (!useFastInfosetForEncoding) { |
207 useFastInfosetForEncoding = isFastInfosetAcceptable(packet.acceptableMimeTypes); |
185 useFastInfosetForEncoding = isFastInfosetAcceptable(packet.acceptableMimeTypes); |
208 } |
186 } |
209 } |
187 } |
210 |
188 |
|
189 @Override |
211 protected void decode(MimeMultipartParser mpp, Packet packet) throws IOException { |
190 protected void decode(MimeMultipartParser mpp, Packet packet) throws IOException { |
212 // This method will never be invoked |
191 // This method will never be invoked |
213 } |
192 } |
214 |
193 |
|
194 @Override |
215 public MimeCodec copy() { |
195 public MimeCodec copy() { |
216 return new XMLHTTPBindingCodec(features); |
196 return new XMLHTTPBindingCodec(features); |
217 } |
197 } |
218 |
198 |
219 private boolean isMultipartRelated(String contentType) { |
199 private boolean isMultipartRelated(String contentType) { |
220 return compareStrings(contentType, MimeCodec.MULTIPART_RELATED_MIME_TYPE); |
200 return compareStrings(contentType, MimeCodec.MULTIPART_RELATED_MIME_TYPE); |
221 } |
|
222 |
|
223 private boolean isApplicationXopXml(String contentType) { |
|
224 return compareStrings(contentType, MtomCodec.XOP_XML_MIME_TYPE); |
|
225 } |
201 } |
226 |
202 |
227 private boolean isXml(String contentType) { |
203 private boolean isXml(String contentType) { |
228 return compareStrings(contentType, XMLCodec.XML_APPLICATION_MIME_TYPE) |
204 return compareStrings(contentType, XMLCodec.XML_APPLICATION_MIME_TYPE) |
229 || compareStrings(contentType, XMLCodec.XML_TEXT_MIME_TYPE) |
205 || compareStrings(contentType, XMLCodec.XML_TEXT_MIME_TYPE) |
298 } else if (p.contentNegotiation == ContentNegotiation.optimistic) { |
275 } else if (p.contentNegotiation == ContentNegotiation.optimistic) { |
299 // Always encode using Fast Infoset if in optimisitic mode |
276 // Always encode using Fast Infoset if in optimisitic mode |
300 useFastInfosetForEncoding = true; |
277 useFastInfosetForEncoding = true; |
301 } |
278 } |
302 |
279 |
303 rootCodec = (useFastInfosetForEncoding && fiCodec != null) |
280 return (useFastInfosetForEncoding && fiCodec != null)? fiCodec : xmlCodec; |
304 ? fiCodec : xmlCodec; |
|
305 } |
281 } |
306 |
282 |
307 public static boolean requiresTransformationOfDataSource( |
283 public static boolean requiresTransformationOfDataSource( |
308 boolean isFastInfoset, boolean useFastInfoset) { |
284 boolean isFastInfoset, boolean useFastInfoset) { |
309 return (isFastInfoset && !useFastInfoset) || (!isFastInfoset && useFastInfoset); |
285 return (isFastInfoset && !useFastInfoset) || (!isFastInfoset && useFastInfoset); |