Janis Peisenieks
Janis Peisenieks

Reputation: 4998

What to do with generated SOAP calls from a WSDL file in Netbeans

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!

Upvotes: 1

Views: 2997

Answers (2)

Gaurav
Gaurav

Reputation: 1567

If you look at the Dispatch.invoke specs in javadocs, it is :

http://docs.oracle.com/javase/6/docs/api/javax/xml/ws/Dispatch.html#invoke(T).

And if you change your code to :

**javax.xml.transform.stream.StreamSource** result = sourceDispatch.invoke(new javax.xml.transform.stream.StreamSource(new java.io.StringReader(req)));

The StreamSource has methods to get the Reader and eventually some meaningful result can b obtained.

Upvotes: 0

Cratylus
Cratylus

Reputation: 54094

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:

Dispatch<SOAPMessage> dispatch

The result in your case is the XML payload of the response.
You can for example convert it to String and see it:

TransformerFactory factory = TransformerFactory.newInstance();  
Transformer transformer = factory.newTransformer();  
StringWriter writer = new StringWriter();  
Result stringOut = new StreamResult(writer);      
transformer.transform(result, stringOut);  
writer.close();  
System.out.println(writer.toString());   

Or convert it to XML node:

TransformerFactory factory = TransformerFactory.newInstance();  
Transformer transformer = factory.newTransformer();  
DOMResult domResult = new DOMResult();  
transformer.transform(result, domResult);  
rootNode = domResult.getNode();

Disclaimer:Did not even attempt to compile the code

Upvotes: 2

Related Questions