In this tip, author and developer Nicholas Chase shows you how to use the SOAP with Attachments API for Java (SAAJ) to simplify the process of creating and sending SOAP messages.
<!--START RESERVED FOR FUTURE USE INCLUDE FILES--><script language="JavaScript" type="text/javascript">
<!--
if (document.referrer&&document.referrer!="") {
// document.write(document.referrer);
var q = document.referrer;
var engine = q;
var isG = engine.search(/google\.com/i);
var searchTerms;
//var searchTermsForDisplay;
if (isG != -1) {
var i = q.search(/q=/);
var q2 = q.substring(i+2);
var j = q2.search(/&/);
j = (j == -1)?q2.length:j;
searchTerms = q.substring(i+2,i+2+j);
if (searchTerms.length != 0) {
searchQuery(searchTerms);
document.write("<div id=\"contents\"></div>");
}
}
}
//-->
</script><!--END RESERVED FOR FUTURE USE INCLUDE FILES-->
The foundation of Web services lies in the sending and receiving of
messages in a standard format so that all systems can understand them.
Typically, that format is SOAP. A SOAP
message can be generated and sent manually, but the SOAP with Attachments
API for Java (SAAJ) -- an offshoot of the Java API for XML Messaging (JAXM) --
automates many of the required steps, such as creating
connections or creating and sending the actual messages. This tip
chronicles the creation and sending of a synchronous SOAP message.
The process involves five steps:
- Creating a SOAP connection
- Creating a SOAP message
- Populating the message
- Sending the message
- Retrieving the reply
SAAJ is available as part of the Java Web Services Developer Pack 1.2 (see Resources). This package also includes a copy of the Tomcat Web server (so you can host your own service) and sample applications.