开发者

is there any Java API to catch request and response SOAP envelops?

I can uses Web service client classes to obtain the result but instead of th开发者_Python百科e 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.


The whole SOAP message will be contained within HTTP request object (HttpServletRequest). This will give you headers, body and everything else.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜