//Convert SOAPMessage to Source
if (message instanceof SoapMessage) {
SOAPMessage soapMessage = message.getContent(SOAPMessage.class);
message.removeContent(SOAPMessage.class);
setupBindingOperationInfo(message.getExchange(), soapMessage);
DataReader<Node> dataReader = new NodeDataReader();
Node n = null;
if (mode == Service.Mode.MESSAGE) {
try {
n = soapMessage.getSOAPPart();
//This seems to be a problem in SAAJ. Envelope might not be initialized properly
//without calling getEnvelope()
soapMessage.getSOAPPart().getEnvelope();
if (soapMessage.countAttachments() > 0) {
if (message.getAttachments() == null) {
message.setAttachments(new ArrayList<Attachment>(soapMessage
.countAttachments()));
}
Iterator<AttachmentPart> it = CastUtils.cast(soapMessage.getAttachments());
while (it.hasNext()) {
AttachmentPart part = it.next();
AttachmentImpl att = new AttachmentImpl(part.getContentId());
att.setDataHandler(part.getDataHandler());
Iterator<MimeHeader> it2 = CastUtils.cast(part.getAllMimeHeaders());
while (it2.hasNext()) {
MimeHeader header = it2.next();
att.setHeader(header.getName(), header.getValue());
}
message.getAttachments().add(att);
}
}
} catch (SOAPException e) {
throw new Fault(e);
}
} else if (mode == Service.Mode.PAYLOAD) {
try {
n = DOMUtils.getChild(soapMessage.getSOAPBody(), Node.ELEMENT_NODE);
} catch (SOAPException e) {
throw new Fault(e);
}
}
Class tempType = type;
if (!Source.class.isAssignableFrom(type)) {
tempType = Source.class;
}
obj = dataReader.read(null, n, tempType);
message.setContent(Source.class, obj);
}
}