有没有一种保证的方法来获取自定义肥皂处理程序中的操作名称? [英] Is there a guaranteed way to get operation name in a custom soap handler?

查看:52
本文介绍了有没有一种保证的方法来获取自定义肥皂处理程序中的操作名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于传入消息的自定义SOAP消息处理程序,该消息处理程序将根据调用的操作来运行不同的代码.我第一次尝试获取操作名称看起来像这样:

I have a custom SOAP message handler for incoming messages that will run different code based on which operation is being called. My first try to get the operation name looked something liket this:

public boolean handleMessage(SOAPMessageContext context)
{
    String op = context.get(MessageContext.WSDL_OPERATION);
    ...

此操作失败,因为似乎从未设置过属性MessageContext.WSDL_OPERATION.然后,我尝试使用此方法:

This failed because the property MessageContext.WSDL_OPERATION appears to never be set. I then tried using this:

public boolean handleMessage(SOAPMessageContext context)
{
    Map<?, ?> headers = (Map<?, ?>)context.get(MessageContext.HTTP_REQUEST_HEADERS);    
    ArrayList<String> SOAPAction = ((ArrayList<String>) headers.get("SOAPAction"));
    String opName = SOAPAction.get(0);
    //opName will be formatted like "urn#myOperation", so the prefix must be removed
    opName = ((opName.replace("\"","").split("#"))[1]);

这可行,但是我担心可能会出现未设置标头属性"SOAPAction"(甚至不存在),或者没有期望的值的情况.我也有点担心,因为我不知道这是否是获取操作名称的官方"方式-我通过查看调试器中context的内容来弄清楚了.

This works, but I'm concerned there could be situations where the header property "SOAPAction" isn't set (or doesn't even exist), or does not have the value that I'm expecting it to. I'm also a little concerned because I don't know if this is an "official" way to get the operation name - I figured it out by looking at the contents of context in the debugger.

在处理传入的SOAP消息时,是否还有更好的方法来获取操作名称?

Is there any better way to get the operation name when handling incoming SOAP messages?

推荐答案

您可以调用body.getElementName().getLocalName()来检索消息有效负载的SOAP主体元素的名称.有点冗长和手动,但是可以用.您可以在处理程序中添加以下内容

You could call body.getElementName().getLocalName() to retrieve the name of SOAP body element of the message payload. It's a little bit verbose and manual but it works. You could have the following in your handler

if ((boolean) context.get(MessageContext.MESSAGE_INBOUND_PROPERTY){ //for requests only
            SOAPEnvelope msg = context.getMessage().getSOAPPart().getEnvelope(); //get the SOAP Message envelope
                SOAPBody body = msg.getBody();
            String operationName = body.getChildNodes().item(1).getLocalName();
}

上述代码的结果保证可以带有WSDL中指定的操作名称

The result of the above code is guaranteed to carry the name of the operation as specified in your WSDL

此解决方案仅基于Web服务以文档/文字包装或RPC/文字实现的条件

This solution is based solely on the condition that the web service is implemented as document/literal-wrapped or RPC/literal

这篇关于有没有一种保证的方法来获取自定义肥皂处理程序中的操作名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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