/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* SOAP binding {@link Codec} that can handle MTOM, SwA, and SOAP messages
* encoded using XML or Fast Infoset.
*
* <p>
* This is used when we need to determine the encoding from what we received (for decoding)
* and from configuration and {@link Message} contents (for encoding)
*
* <p>
* TODO: Split this Codec into two, one that supports FI and one that does not.
* Then further split the FI Codec into two, one for client and one for
* server. This will simplify the logic and make it easier to understand/maintain.
*
* @author Vivek Pandey
* @author Kohsuke Kawaguchi
*/
public class SOAPBindingCodec extends MimeCodec implements com.sun.xml.internal.ws.api.pipe.SOAPBindingCodec {
/**
* Based on request's Accept header this is set.
* Currently only set if MTOMFeature is enabled.
*
* Should be used on server-side, for encoding the response.
*/
private boolean acceptMtomMessages;
/**
* If the request's Content-Type is multipart/related; type=application/xop+xml, then this set to to true
*
* Used on server-side, for encoding the repsonse.
*/
private boolean isRequestMtomMessage;
/**
* This captures is decode is called before encode,
* if true, infers that this is being used on Server-side
*/
/**
* True if Fast Infoset functionality has been
* configured to be disabled, or the Fast Infoset
* runtime is not available.
*/
private boolean isFastInfosetDisabled;
/**
* True if the Fast Infoset codec should be used for encoding.
*/
private boolean useFastInfosetForEncoding;
/**
* True if the content negotiation property should
* be ignored by the client. This will be used in
* the case of Fast Infoset being configured to be
* disabled or automatically selected.
*/
private boolean ignoreContentNegotiationProperty;
// The XML SOAP codec
// The Fast Infoset SOAP codec
// The XML MTOM codec
// The XML SWA codec
// The Fast Infoset SWA codec
/**
* The XML SOAP MIME type
*/
/**
* The Fast Infoset SOAP MIME type
*/
/**
* The Accept header for XML encodings
*/
/**
* The Accept header for Fast Infoset and XML encodings
*/
return xmlSoapCodec;
}
} else {
}
_c = c;
return this;
}
return _c.getContentType();
}
return _c.getSOAPActionHeader();
}
return _accept;
}
}
}
this.xmlSoapCodec = xmlSoapCodec;
xmlMtomCodec = new MtomCodec(version, xmlSoapCodec, binding, binding.getFeature(MTOMFeature.class));
if (!isFastInfosetDisabled) {
if (fiSoapCodec != null) {
/**
* This feature will only be present on the client side.
*
* Fast Infoset is enabled on the client if the service
* explicitly supports Fast Infoset.
*/
ignoreContentNegotiationProperty = true;
// If the client's FI encoding feature is enabled, and server's is not disabled
useFastInfosetForEncoding = true;
}
} else { // If client FI feature is disabled
isFastInfosetDisabled = true;
}
}
} else {
// Fast Infoset could not be loaded by the runtime
isFastInfosetDisabled = true;
fiSwaCodec = null;
fiMimeType = "";
ignoreContentNegotiationProperty = true;
}
} else {
// Fast Infoset is explicitly not supported by the service
fiMimeType = "";
ignoreContentNegotiationProperty = true;
}
if(!(binding instanceof SOAPBindingImpl))
}
return null;
}
}
postEncode();
return ct;
}
postEncode();
return ct;
}
/**
* Should be called before encode().
* Set the state so that such state is used by encode process.
*/
}
/**
* Should be called after encode()
* Reset the encoding state.
*/
private void postEncode() {
acceptMtomMessages = false;
isRequestMtomMessage = false;
}
/**
* Should be called before decode().
* Set the state so that such state is used by decode().
*/
if (p.contentNegotiation == null)
useFastInfosetForEncoding = false;
}
/**
* Should be called after decode().
* Set the state so that such state is used by encode().
*/
if (!useFastInfosetForEncoding) {
}
}
private boolean isServerSide() {
}
if (contentType == null) {
}
try {
// parse the multipart portion and then decide whether it's MTOM or SwA
else if(isFastInfoset(contentType)) {
throw noFastInfosetForDecoding();
useFastInfosetForEncoding = true;
} else
} catch(RuntimeException we) {
throw we;
} else {
}
}
}
if (contentType == null) {
throw new UnsupportedMediaException();
}
try {
else if(isFastInfoset(contentType)) {
throw noFastInfosetForDecoding();
useFastInfosetForEncoding = true;
} else
} catch(RuntimeException we) {
throw we;
} else {
}
}
}
}
// is this SwA or XOP?
isRequestMtomMessage = true;
} else if (isFastInfoset(rootContentType)) {
throw noFastInfosetForDecoding();
useFastInfosetForEncoding = true;
} else if (isXml(rootContentType))
else {
// TODO localize exception
throw new IOException("");
}
// checkDuplicateKnownHeaders(packet);
}
}
}
}
if (isFastInfosetDisabled) return false;
}
a.substring(0,
b.length()));
}
while (st.hasMoreTokens()) {
return true;
}
}
return false;
}
/*
* Just check if the Accept header contains application/xop+xml,
* no need to worry about q values.
*/
while (st.hasMoreTokens()) {
return true;
}
}
return false;
}
/**
* Determines the encoding codec.
*/
/**
* The following logic is only for outbound packets
* to be encoded by a client.
* For a server the p.contentNegotiation == null.
*/
if (!ignoreContentNegotiationProperty) {
// The client may have changed the negotiation property from
// pessismistic to none between invocations
useFastInfosetForEncoding = false;
// Always encode using Fast Infoset if in optimisitic mode
useFastInfosetForEncoding = true;
}
}
// Override the MTOM binding for now
// Note: Using FI with MTOM does not make sense
if (useFastInfosetForEncoding) {
final Message m = p.getMessage();
return fiSoapCodec;
else
return fiSwaCodec;
}
//On client, always use XOP encoding if MTOM is enabled
// On Server, use XOP encoding if either request is XOP encoded or client accepts XOP encoding
return xmlMtomCodec;
}
Message m = p.getMessage();
return xmlSoapCodec;
else
return xmlSwaCodec;
}
}
/**
* Obtain an FI SOAP codec instance using reflection.
*/
try {
} catch (Exception e) {
// TODO Log that FI cannot be loaded
return null;
}
}
}