1

我正在尝试通过 JAX-RPC java 客户端访问 XML 响应。

我一直在研究 Axis 自定义处理程序,但看起来它们仅在服务端有用。

4

1 回答 1

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.

于 2013-05-15T18:20:45.553 回答