I can uses Web service client classes to obtain the result but instead of the text result i want complete SOAP message in my JavaSE program. How can I do that? Any Idea?
Yes there is.
Use Dispatch<Source> to work on the SOAP message JAX-WS Dispatch.
Example DISCLAIMER: Did not even attempt to compile the code:
//xmlString has the xml message to send to the web service
StreamSource xmlMsg = new StreamSource(new StringReader(xmlString));
//Create URL of web service. Place your URL for WSDL
URL wsdlURL = new URL("http://10.5.2.10:8080/path/service?wsdl");
QName serviceName = new QName("http://example.com", "TrivialWebService");
Service s = Service.create(wsdlURL, serviceName);
QName portName = new QName("http://example.com", "TrivialWebServicePort");
//Service.Mode.MESSAGE works on SOAP msg (as opposed to Service.Mode.PAYLOAD)
Dispatch<Source> dispatch = createDispatch(portName,
Source.class,
Service.Mode.MESSAGE);
//Send request
Source reply = dispatch.invoke(xmlMsg);
DOMResult domResponse = new DOMResult();
Transformer trans = TransformerFactory.newInstance().newTransformer();
trans.transform(reply, domResponse);
//Now use DOM APIs
You can also specify if you want to work on the HTTP payload (as XML) i.e. SOAP envelope or the SOAP payload i.e. the response.
You will have write code to handle the raw XML (e.g. use DOM).
You can use this api if you use JAX-WS or CXF.
For AXIS2 it is possible to work on XML as well.Just will be some specific apis
Of course there is also SAAJ you can use.
Yes, about how do I use Dispatch code to get SOAP response on my console screen ? It would be really helpful. Thanks in advance :)
– Azfar NiazJul 03 '11 at 23:41
0
The whole SOAP message will be contained within HTTP request object (HttpServletRequest). This will give you headers, body and everything else.