简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM