Is it possible to access the raw SOA/XML message in a JAX-RPC java client?

余生颓废 提交于 2019-12-11 07:06:47

问题


I am trying to access the XML response via a JAX-RPC java client.

I have been looking into Axis custom handlers, but it looks like they are useful only in the service side.


回答1:


Here's some code that will give you the XML response payload back. You can either get it directly from AXIS Stub class, or from a handler that wrote it to the MessageContext. Here's the one that reads it directly:

private String getSOAPResponseXML(Object clientstub) {
    String returnValue = null;
    org.apache.axis.client.Stub stub = (org.apache.axis.client.Stub)clientstub;
    Call call = stub._getCall();
    if (call != null) {
        MessageContext ctx = call.getMessageContext();
        // If I registered a handler
        // returnValue = (String) ctx.getProperty( ClientHandler.SOAP_RESPONSE );

        // or use:
        try {
            Message msg = call.getResponseMessage();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            // NOTE: If we never get a response (a request handler throws an uncaught error
            // this can cause a java.lang.NullPointerException
            msg.writeTo(baos);
            returnValue = baos.toString();
        } catch (java.io.IOException ex) {
            log.debug("Error in getSOAPResponseXML", ex);
        } catch (javax.xml.soap.SOAPException ex) {
            log.debug("Error in getSOAPResponseXML", ex);
        }
    }
    return returnValue;
} // getSOAPResponseXML

If you need the handler, just let me know.



来源:https://stackoverflow.com/questions/3842900/is-it-possible-to-access-the-raw-soa-xml-message-in-a-jax-rpc-java-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!