//TODO we assume for the time being that there is only one attachement and this attachement contains the soap evelope
try {
Multipart mp = (Multipart) msg.getContent();
if (mp != null) {
for (int i = 0, n = mp.getCount(); i < n; i++) {
Part part = mp.getBodyPart(i);
String disposition = part.getDisposition();
if (disposition != null && disposition.equalsIgnoreCase(Part.ATTACHMENT)) {
String soapAction;
/* Set the Charactorset Encoding */
String contentType = part.getContentType();
String charSetEncoding = BuilderUtil.getCharSetEncoding(contentType);
if (charSetEncoding != null) {
msgContext.setProperty(
org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING,
charSetEncoding);
} else {
msgContext.setProperty(
org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING,
MessageContext.DEFAULT_CHAR_SET_ENCODING);
}
/* SOAP Action */
soapAction = getMailHeaderFromPart(part,
org.apache.axis2.transport.mail.Constants.HEADER_SOAP_ACTION);
msgContext.setSoapAction(soapAction);
String contentDescription =
getMailHeaderFromPart(part, "Content-Description");
/* As an input stream - using the getInputStream() method.
Any mail-specific encodings are decoded before this stream is returned.*/
if (contentDescription != null) {
msgContext.setTo(new EndpointReference(contentDescription));
}
if (contentType.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) > -1) {
TransportUtils
.processContentTypeForAction(contentType, msgContext);
} else {
// According to the mail sepec, mail transport should support only
// application/soap+xml;
String message = "According to the mail sepec, mail transport " +
"should support only application/soap+xml";
log.error(message);
throw new AxisFault(message);
}
String cte = getMailHeaderFromPart(part, "Content-Transfer-Encoding");
if (!(cte != null && cte.equalsIgnoreCase("base64"))) {
String message = "Processing of Content-Transfer-Encoding faild.";
log.error(message);
throw new AxisFault(message);
}
InputStream inputStream = part.getInputStream();
SOAPEnvelope envelope = TransportUtils
.createSOAPMessage(msgContext, inputStream, contentType);
msgContext.setEnvelope(envelope);
}
}