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

1

1

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.

Keishakeisling answered 1/10, 2010 at 20:39 Comment(0)
C
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.

Churn answered 15/5, 2013 at 18:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.