boolean isSOAP)
throws OMException, XMLStreamException, FactoryConfigurationError {
StAXBuilder builder = null;
XMLStreamReader streamReader;
Attachments attachments = createAttachmentsMap(msgContext, inStream, contentTypeString);
String charSetEncoding = getCharSetEncoding(attachments.getSOAPPartContentType());
if ((charSetEncoding == null)
|| "null".equalsIgnoreCase(charSetEncoding)) {
charSetEncoding = MessageContext.UTF_8;
}
msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING,
charSetEncoding);
try {
PushbackInputStream pis = getPushbackInputStream(attachments.getSOAPPartInputStream());
String actualCharSetEncoding = getCharSetEncoding(pis, charSetEncoding);
streamReader = StAXUtils.createXMLStreamReader(pis, actualCharSetEncoding);
} catch (IOException e) {
throw new XMLStreamException(e);
}
// Put a reference to Attachments Map in to the message context For
// backword compatibility with Axis2 1.0
msgContext.setProperty(MTOMConstants.ATTACHMENTS, attachments);
// Setting the Attachments map to new SwA API
msgContext.setAttachmentMap(attachments);
String soapEnvelopeNamespaceURI = getEnvelopeNamespace(contentTypeString);
if (isSOAP) {
if (attachments.getAttachmentSpecType().equals(
MTOMConstants.MTOM_TYPE)) {
//Creates the MTOM specific MTOMStAXSOAPModelBuilder
builder = new MTOMStAXSOAPModelBuilder(streamReader,
attachments, soapEnvelopeNamespaceURI);
msgContext.setDoingMTOM(true);
} else if (attachments.getAttachmentSpecType().equals(
MTOMConstants.SWA_TYPE)) {
builder = new StAXSOAPModelBuilder(streamReader,
soapEnvelopeNamespaceURI);
} else if (attachments.getAttachmentSpecType().equals(
MTOMConstants.SWA_TYPE_12)) {
builder = new StAXSOAPModelBuilder(streamReader,
soapEnvelopeNamespaceURI);
}
}
// To handle REST XOP case
else {
if (attachments.getAttachmentSpecType().equals(
MTOMConstants.MTOM_TYPE)) {
XOPAwareStAXOMBuilder stAXOMBuilder = new XOPAwareStAXOMBuilder(
streamReader, attachments);
builder = stAXOMBuilder;
} else if (attachments.getAttachmentSpecType().equals(
MTOMConstants.SWA_TYPE)) {
builder = new StAXOMBuilder(streamReader);
} else if (attachments.getAttachmentSpecType().equals(
MTOMConstants.SWA_TYPE_12)) {
builder = new StAXOMBuilder(streamReader);
}
}