【问题标题】:Is it possible to access the raw SOA/XML message in a JAX-RPC java client?是否可以在 JAX-RPC java 客户端中访问原始 SOA/XML 消息?
【发布时间】:2010-10-01 20:39:42
【问题描述】:

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

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

【问题讨论】:

    标签: java web-services jax-rpc


    【解决方案1】:

    这里有一些代码可以返回 XML 响应负载。您可以直接从 AXIS Stub 类或从将其写入 MessageContext 的处理程序中获取它。这是直接读取的:

    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
    

    如果您需要处理程序,请告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-15
      • 2017-09-15
      相关资源
      最近更新 更多