Java Reference
In-Depth Information
//if the version is 1.0, give user instructions
//for upgrading to coming version.
if ("1.0".equals(version)) {
try {
SOAPMessage msg = ctx.getMessage();
SOAPBody body = msg.getSOAPBody();
SOAPElement content =
(SOAPElement)body.getFirstChild();
String value = content.getTextContent();
LOGGER.debug("Print value: " + value);
//because version is old, attach instructions
//for migrating to new version
//Create SOAP attachment
AttachmentPart ap = msg.createAttachmentPart();
String s = "Client will support JMS in " +
"version 1.5.";
ap.setContent(s, "text/plain");
ap.setContentId("Version-1.5-Notice");
msg.addAttachmentPart(ap);
LOGGER.debug("Attachment added.");
} catch (Exception ex) {
LOGGER.error("Problem.", ex);
}
}
}
return true;
}
//...
The attachment mechanism itself is not important at this point. What you want to focus on
here is the idea that you can pass data between handlers using the context, and then take some
action based on it. It is perhaps unusual to have a client sending the service some sort of notice
in this way, but the demonstration is useful for our purposes here.
The handler chain is complete, and the message is dispatched. But because you modified it on
the way out, it results in a multipart SOAP request. Along with the data in the SOAP body, it
sends the attachment as well. The final SOAP message looks like Example 6-15 .
Example6-15.Passing binary data to a web service
Search WWH ::




Custom Search