* @param attachments the set of attachments to be used to substitute xop:Include elements
* @throws SOAPException
*/
public SOAPPartImpl(SOAPMessageImpl parentSoapMsg, InputStream inputStream,
MimeHeaders mimeHeaders, Attachments attachments) throws SOAPException {
ContentType contentType = null;
if (mimeHeaders == null) {
//TODO : read string from constants
this.mimeHeaders = new MimeHeaders();
this.mimeHeaders.addHeader("Content-ID", IDGenerator.generateID());
this.mimeHeaders.addHeader("content-type", HTTPConstants.MEDIA_TYPE_APPLICATION_SOAP_XML);
} else {
String contentTypes[] = mimeHeaders.getHeader(HTTPConstants.HEADER_CONTENT_TYPE);
if (contentTypes != null && contentTypes.length > 0) {
try {
contentType = new ContentType(contentTypes[0]);
} catch (ParseException ex) {
throw new SOAPException("Invalid content type '" + contentTypes[0] + "'");
}
}
this.mimeHeaders = SAAJUtil.copyMimeHeaders(mimeHeaders);
}
soapMessage = parentSoapMsg;
String charset;
boolean isMTOM;
String soapEnvelopeNamespaceURI;
OMMetaFactory metaFactory = OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM);
SOAPFactory soapFactory;
if (contentType == null) {
charset = null;
isMTOM = false;
soapFactory = metaFactory.getSOAP11Factory();
soapEnvelopeNamespaceURI = null;
} else {
MediaType baseType = contentType.getMediaType();
MediaType soapContentType;
if (baseType.equals(MediaType.APPLICATION_XOP_XML)) {
isMTOM = true;
String typeParam = contentType.getParameter("type");
if (typeParam == null) {
throw new SOAPException("Missing 'type' parameter in XOP content type");
} else {
try {
soapContentType = new ContentType(typeParam).getMediaType();
} catch (ParseException ex) {
throw new SOAPException("Failed to parse the 'type' parameter", ex);
}
}
} else {
isMTOM = false;
soapContentType = baseType;
}
if (soapContentType.equals(MediaType.TEXT_XML)) {
soapEnvelopeNamespaceURI = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
soapFactory = metaFactory.getSOAP11Factory();
} else if (soapContentType.equals(MediaType.APPLICATION_SOAP_XML)) {
soapEnvelopeNamespaceURI = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI;
soapFactory = metaFactory.getSOAP12Factory();
} else {
throw new SOAPException("Unrecognized content type '" + soapContentType + "'");
}
charset = contentType.getParameter("charset");
}
XMLStreamReader streamReader;
try {
if (charset != null) {