如何将其他字段与soapMessage一起发送到soap处理程序? [英] How to send additional fields to soap handler along with soapMessage?

查看:43
本文介绍了如何将其他字段与soapMessage一起发送到soap处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SoapHandler如下记录Web服务客户端的RequestXML

I am logging RequestXML for a webservice client using SoapHandler as follows

public boolean handleMessage(SOAPMessageContext smc) {
    logToSystemOut(smc);
    return true;
}


private void logToSystemOut(SOAPMessageContext smc) {
     Boolean outboundProperty = (Boolean)
     smc.get (MessageContext.MESSAGE_OUTBOUND_PROPERTY);

    if (outboundProperty.booleanValue()) {
        out.println("\nOutbound message:");
    } else {
        out.println("\nInbound message:");
    }

    SOAPMessage message = smc.getMessage();
    try {
        message.writeTo(out);
        out.println("");   
        } catch (Exception e) {
        out.println("Exception in handler: " + e);
    }
} 

提出了一个新要求,将这个xml和一些额外的值(在xml中不存在)一起添加到DB中.有什么办法可以将一些其他字段传递给上面的肥皂处理程序(在handleMessage方法中)?

Got a new requirenment to add this xml to DB along with some extra values(which are not present in the xml). Is there any way I can pass few additional fields to above soap handler (in handleMessage method)?

请注意,更改xml/WSDL或将其添加到SOAP消息头中不是我的选择,因为它由其他接口拥有.还有其他解决方案吗?

Please note that changing the xml/WSDL or adding this to SOAP message header is not an option for me as it is owned by other interface. Any other solution?

谢谢!

推荐答案

您可以将服务类转换为"BindingProvider"类型的类.在这种形式下,您可以使用它来分配对象,以便以后可以从SOAPHandler访问这些对象.另一个有用的用法是,您还可以通过这种方式更改endPoint URL.

You can cast your service class to a class of type "BindingProvider". In this form you can use it to assign it objects which you can access later from your SOAPHandler. Another useful usage is that you also can change the endPoint URL this way.

在致电服务之前,您需要执行以下操作:

Before calling the service you do:

    MySoapServicePortType service = new MySoapService().getMySoapServicePort();
    BindingProvider bp = (BindingProvider)service;
    MyTransferObject t = new MyTransferObject();
    bp.getRequestContext().put("myTransferObject", t);
    TypeResponse response = service.doRequest();
    SOAPMessage message = t.getRequestMessage(message);

通过您的日志记录功能,您可以执行以下操作:

From your logging function you do:

private void logToSystemOut(SOAPMessageContext smc) {
    ...
    MyTransferObject t = (MyTransferObject) messageContext.get("myTransferObject");
    if (outboundProperty.booleanValue())
        t.setRequestMessage(message);
    else
        t.setResponseMessage(message);
    ...
}

这篇关于如何将其他字段与soapMessage一起发送到soap处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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