Could anybody tell me what's wrong with my code?
Code: Select all
//First create the connection
SOAPConnectionFactory soapConnFactory =
SOAPConnectionFactory.newInstance();
SOAPConnection connection =
soapConnFactory.createConnection();
//Next, create the actual message
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage message = messageFactory.createMessage();
//Create objects for the message parts
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody body = envelope.getBody();
//Populate the body
//Create the main element and namespace
SOAPElement bodyElement =
body.addChildElement(envelope.createName("CAARequestMessage" ,
"scalix-caa",
"http://www.scalix.com/caa"));
bodyElement.addChildElement(new QName("ServiceType"))
.addTextNode("scalix.res");
SOAPElement identity = bodyElement.addChildElement(new QName("Credentials"))
.addChildElement(new QName("Identity"));
identity.addAttribute(new QName("name"), "sxadmin");
identity.addAttribute(new QName("password"), "xxxxxx");
bodyElement.addChildElement(new QName("FunctionName"))
.addTextNode("GetUsersList");
SOAPElement scalixElements = bodyElement.addChildElement(new QName("ScalixServers"));
scalixElements.addChildElement(new QName("Host")).addTextNode("obiwan.itc-hk.com");
SOAPElement getUsersListParameters = bodyElement
.addChildElement("GetUsersListParameters");
getUsersListParameters.addAttribute(new QName("maxRecords"), "50")
.addChildElement("filters")
.addChildElement("usertypefiler")
.addAttribute(new QName("value"), "ALL");
getUsersListParameters.addChildElement("organizedBy")
.addAttribute(new QName("entity"), "LAST_NAME");
//Save the message
message.saveChanges();
//Check the input
System.out.println("\nREQUEST:\n");
message.writeTo(System.out);
System.out.println();
//Set the destination
String destination =
"http://obiwan.itc-hk.com:80/caa";
//Send the message
SOAPMessage reply = connection.call(message, destination);
//Check the output
System.out.println("\nRESPONSE:\n");
//Create the transformer
TransformerFactory transformerFactory =
TransformerFactory.newInstance();
Transformer transformer =
transformerFactory.newTransformer();
//Extract the content of the reply
Source sourceContent = reply.getSOAPPart().getContent();
//Set the output for the transformation
StreamResult result = new StreamResult(System.out);
transformer.transform(sourceContent, result);
System.out.println();
//Close the connection
connection.close();