I’m just starting out with Java, but my boss is pushing for this. I’ve taken the WSDL file we had, and generated a web service and a web client in Netbeans. Also, I’ve dragged the new service into my client and made sure, that the code works. But now I have a question. How do work with the result? The code in my JSP looks like this:
try {
Soap.PDFSignatureServiceService service = new Soap.PDFSignatureServiceService();
javax.xml.namespace.QName portQName = new javax.xml.namespace.QName("http://external.ltc.com/", "PDFSignatureServicePort");
String req = "<getTimestamp xmlns=\"http://external.ltc.com/\"><msisdn>ENTER VALUE</msisdn></getTimestamp>";
javax.xml.ws.Dispatch<javax.xml.transform.Source> sourceDispatch = null;
sourceDispatch = service.createDispatch(portQName, javax.xml.transform.Source.class, javax.xml.ws.Service.Mode.PAYLOAD);
javax.xml.transform.Source result = sourceDispatch.invoke(new javax.xml.transform.stream.StreamSource(new java.io.StringReader(req)));
out.print(result.toString());
} catch (Exception ex) {
out.print(ex.getMessage());
}
The code works, but what it is printing out is: com.sun.xml.ws.util.xml.StAXSource@90fe8e. What in the world do I do with this? I was expecting either a SOAP message, or an integer of some sorts. How do I get to somewhere from here?
Thanks!
What you are doing here is creating a dynamic client and actually you are working on the payload level and not on the SOAP message level.
For the SOAP level you would have to do:
The result in your case is the XML payload of the response.
You can for example convert it to String and see it:
Or convert it to XML node:
Disclaimer:Did not even attempt to compile the code