background image

SOAPBodyElement Class

<< SOAPConnectionFactory Class | connection.call() Method >>
<< SOAPConnectionFactory Class | connection.call() Method >>
156
SOAP
WITH
A
TTACHMENTS
API
FOR
J
AVA
The next lines of code retrieve the
SOAPHeader
and
SOAPBody
objects from the
message and remove the header.
SOAPHeader header = message.getSOAPHeader();
header.detachNode();
SOAPBody body = message.getSOAPBody();
The following lines of code create the UDDI
find_business
message. The first
line creates a
SOAPBodyElement
with a fully qualified name, including the
required namespace for a UDDI version 2 message. The next lines add two
attributes to the new element: the required attribute
generic
, with the UDDI ver-
sion number 2.0, and the optional attribute
maxRows
, with the value 100. Then
the code adds a child element that has the
QName
object
name
and adds text to the
element by using the method
addTextNode
. The added text is the business name
you will supply at the command line when you run the application.
SOAPBodyElement findBusiness =
body.addBodyElement(new QName(
"urn:uddi-org:api_v2", "find_business"));
findBusiness.addAttribute(new QName("generic"), "2.0");
findBusiness.addAttribute(new QName("maxRows"), "100");
SOAPElement businessName =
findBusiness.addChildElement(new QName("name"));
businessName.addTextNode(args[1]);
The next line of code saves the changes that have been made to the message.
This method will be called automatically when the message is sent, but it does
not hurt to call it explicitly.
message.saveChanges();
The following lines display the message that will be sent:
System.out.println("\n---- Request Message ----\n");
message.writeTo(System.out);
The next line of code creates the
java.net.URL
object that represents the desti-
nation for this message. It gets the value of the property named
URL
from the sys-
tem properties.
URL endpoint = new URL(
System.getProperties().getProperty("URL"));