是否可以在JAX-RPC Java客户端中访问原始SOA/XML消息? [英] Is it possible to access the raw SOA/XML message in a JAX-RPC java client?

查看:92
本文介绍了是否可以在JAX-RPC Java客户端中访问原始SOA/XML消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

推荐答案

这里有一些代码可以为您提供XML响应有效负载.您可以直接从AXIS Stub类获取它,也可以从将其写入MessageContext的处理程序中获取它.这是直接读取的内容:

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.

这篇关于是否可以在JAX-RPC Java客户端中访问原始SOA/XML消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆