Professional Documents
Culture Documents
Agenda
? What is SAAJ?
? SOAP message structure
? SAAJ programming APIs
SAAJ ? SAAJ and DOM
1 5
SAAJ
? Contains the API for creating, populating, and
accessing SOAP messages conforming to
SOAP 1.1 and SOAP with Attachment
specifications
Package Relationship
javax.xml.rpc javax.xml.messaging
SOAP Message
SAAJ
Structure
javax.xml.soap
8 9
Body Entry
Attachment
SOAP
Message
Object With SAAJ
Attachments Programming APIs
source: Java WSDP
12 13
? SOAPConnection SOAPElement
– For request/response SOAP message exchange Text SOAPHeader
? SOAPMessage
– Creating and populating
SOAPHeaderElement
? Constituent parts of a SOAP message SOAPBody
– SOAPPart
– AttachmentPart
SOAPBodyElement SOAPFault
14 15
03/09/2004
MimeHeader MimeHeaders
16 17
javax.xml.soap.SOAPMessage javax.xml.soap.SOAPPart
? Java technology abstraction for a SOAP ? The first part of a multi-part message
1.1 message when there are attachments
? SOAPPart + Zero or more ? Contains a SOAP 1.1 header
AttachmentPart's ? Support to create or examine the SOAP
1.1 header elements
18 19
03/09/2004
javax.xml.soap.AttachmentPart
? Can contain any data (for example:
JPEG images, XML business
documents, etc.)
– Must have a MIME header to indicate the type
of data it contains
Steps of SAAJ
? May also have additional MIME headers Programming
to identify it or to give its location, which
are optional but can be useful when
there are multiple attachments
20 21
22 23
03/09/2004
24 25
26 27
03/09/2004
28 29
Reading a response
SOAPBody soapBody = response.getSOAPBody();
java.util.Iterator iterator =
soapBody.getChildElements(bodyName);
SOAPBodyElement bodyElement =
(SOAPBodyElement)iterator.next();
String lastPrice = bodyElement.getValue(); Steps of SAAJ
System.out.print("The last price for SUNW is "); Programming
System.out.println(lastPrice);
Adding Content to
SOAPHeader
30 31
03/09/2004
Steps of SAAJ
Programming
Adding Content to
SOAPBody
34 35
03/09/2004
? attachment.setMimeHeader("Content-Type",
"application/xml");
44 45
message.addAttachmentPart(attachment);
46 47
03/09/2004
Accessing Attachments
java.util.Iterator iterator = message.getAttachments();
while (iterator.hasNext()) {
AttachmentPart attachment =
(AttachmentPart)iterator.next();
String id = attachment.getContentId();
String type = attachment.getContentType();
System.out.print("Attachment " + id +
" has content type " + type);
if (type == "text/plain") {
Steps of SAAJ
Object content = attachment.getContent();
System.out.println("Attachment " +
Programming
}
"contains:\n" + content); Adding Attributes
}
48 49
52 53
Retriveing All
Adding Actor Attribute
SOAPHeaderElement's
SOAPHeader header = message.getSOAPHeader();
Iterator allHeaders = SOAPFactory soapFactory = SOAPFactory.newInstance();
header.examineAllHeaderElements();
String nameSpace = "ns";
while (allHeaders.hasNext()) { String nameSpaceURI = "http://gizmos.com/NSURI";
SOAPHeaderElement headerElement =
(SOAPHeaderElement)allHeaders.next(); Name order = soapFactory.createName("orderDesk",
Name headerName = nameSpace, nameSpaceURI);
SOAPHeaderElement orderHeader =
headerElement.getElementName(); header.addHeaderElement(order);
System.out.println("\nHeader name is " + orderHeader.setActor("http://gizmos.com/orders");
headerName.getQualifiedName());
Name shipping =
System.out.println("Actor is " + soapFactory.createName("shippingDesk",
headerElement.getActor()); nameSpace, nameSpaceURI);
} SOAPHeaderElement shippingHeader =
header.addHeaderElement(shipping);
shippingHeader.setActor("http://gizmos.com/shipping");
54 55
03/09/2004
56 57
58 59
03/09/2004
SAAJ & DOM – The SOAPElement interface extends both the Node
interface and the org.w3c.dom.Element interface.
– The SOAPPart class implements the
org.w3c.dom.Document interface.
– The Text interface extends the org.w3c.dom.Text
interface.
60 61
62 63
03/09/2004
64 65
66 67
03/09/2004
} catch(Exception e) {
e.printStackTrace();
}
return message;
}
70 71
03/09/2004
76 77
Passion!
78