The usage looks something like this:
try {
String url = "http://" + ServerIP + "/" +
AppID + "/default/call/soap";
// Create SOAP Connection
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
// Send SOAP Message to SOAP Server
SOAPMessage soapResponse = soapConnection.call(
createSOAPRequest(tdName, tdiskStatus),
url);
// Process the SOAP Response
printSOAPResponse(soapResponse);
soapConnection.close();
} catch (SOAPException ex) {
System.out.println("main: soap " + ex.getMessage());
Logger.getLogger(LogTDSClient.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnsupportedOperationException ex) {
System.out.println("main: uns" + ex.getMessage());
Logger.getLogger(LogTDSClient.class.getName()).log(Level.SEVERE, null, ex);
} catch (Exception ex) {
System.out.println("main: oops " + ex.getMessage());
Logger.getLogger(LogTDSClient.class.getName()).log(Level.SEVERE, null, ex);
}
and the interesting part:
private static SOAPMessage createSOAPRequest(String tName, String tStatus) throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
String serverURI = "http://your-url:here";
String authHack = "ZGxv-usual-base64stuff";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
// your-url:here corresponds to serverIP above
envelope.addNamespaceDeclaration("ns0", "http://your-url:here/AppID/default/call/soap");
// SOAP Body
SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement("YourSoapFunc", "ns0");
SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("YourSoapParam");
soapBodyElem1.addTextNode("YourSoapParamString");
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPACTION", "");
headers.addHeader("Authorization", "Basic " + authHack);
Iterator outHeaders = headers.getAllHeaders();
while (false & outHeaders.hasNext()) {
MimeHeader outH = (MimeHeader) outHeaders.next();
// System.out.println(outH.getName() + " -- " +outH.getValue());
}
soapMessage.saveChanges();
/* Print the request message */
if (Boolean.FALSE) {
System.out.print("Request SOAP Message = ");
soapMessage.writeTo(System.out);
System.out.println();
}
return soapMessage;
}
It's pretty simple. You might need to tweak the return value handling, because that part wasn't very important to my usage.
(Grrr -- the GG message editor gets funky when I put in a code block, at least in this browser.)
Good luck.
/dps