envelope = SAAJUtil.toOMSOAPEnvelope(request);
options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
} else {
envelope = SAAJUtil.toOMSOAPEnvelope(request.getSOAPPart().getDocumentElement());
if (request.countAttachments() != 0) { // SOAPMessage with attachments
Attachments attachments = requestMsgCtx.getAttachmentMap();
for (Iterator it = request.getAttachments(); it.hasNext(); ) {
AttachmentPart attachment = (AttachmentPart)it.next();
String contentId = attachment.getContentId();
// Axiom currently doesn't support attachments without Content-ID
// (see WSCOMMONS-418); generate one if necessary.
if (contentId == null) {
contentId = IDGenerator.generateID();
}
DataHandler handler = attachment.getDataHandler();
// make sure that AttachmentPart content-type overrides DataHandler content-type
if (!SAAJUtil.compareContentTypes(attachment.getContentType(), handler.getContentType())) {
ConfigurableDataHandler configuredHandler = new ConfigurableDataHandler(handler.getDataSource());
configuredHandler.setContentType(attachment.getContentType());
handler = configuredHandler;
}
attachments.addDataHandler(contentId, handler);
}
options.setProperty(Constants.Configuration.ENABLE_SWA, Constants.VALUE_TRUE);
}
}
Map<String,String> httpHeaders = null;
for (Iterator it = request.getMimeHeaders().getAllHeaders(); it.hasNext(); ) {
MimeHeader header = (MimeHeader)it.next();
String name = header.getName().toLowerCase();
if (name.equals("soapaction")) {
requestMsgCtx.setSoapAction(header.getValue());
} else if (name.equals("content-type")) {
// Don't set the Content-Type explicitly since it will be computed by the
// message builder.
} else {
if (httpHeaders == null) {
httpHeaders = new HashMap<String,String>();
}
httpHeaders.put(header.getName(), header.getValue());
}
}
if (httpHeaders != null) {
requestMsgCtx.setProperty(HTTPConstants.HTTP_HEADERS, httpHeaders);
}
try {
MessageContext responseMsgCtx;
try {
requestMsgCtx.setEnvelope(envelope);
opClient.addMessageContext(requestMsgCtx);
opClient.execute(true);
responseMsgCtx =
opClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
} catch (AxisFault ex) {
throw new SOAPException(ex.getMessage(), ex);
}
SOAPMessage response = getSOAPMessage(responseMsgCtx.getEnvelope());
Attachments attachments = requestMsgCtx.getAttachmentMap();
for (String contentId : attachments.getAllContentIDs()) {
if (!contentId.equals(attachments.getSOAPPartContentID())) {
AttachmentPart ap = response.createAttachmentPart(
attachments.getDataHandler(contentId));
ap.setContentId(contentId);
response.addAttachmentPart(ap);
}
}