Jax-ws:Java SOAP异常:MustUnderstand标题:[{http://www.w3.org/2005/08/addressing}动作

时间:2012-01-29 17:47:15

标签: java web-services soap jax-ws soap-client

我正在使用Jax-ws为Onvif IP摄像头实现客户端应用程序,我正在向摄像头发送请求以创建PullPointSubscription,看来摄像头理解请求并处理请求并发送正确的响应,但是客户端jax -ws代码抛出异常

MustUnderstand headers:[{http://www.w3.org/2005/08/addressing}Action] are not understood

我不明白究竟是什么问题?任何人都可以解释问题是什么以及如何解决它?

异常详情

an 29, 2012 11:43:48 AM com.sun.xml.ws.protocol.soap.MUTube getMisUnderstoodHeaders
INFO: Element not understood={http://www.w3.org/2005/08/addressing}Action
javax.xml.ws.soap.SOAPFaultException: MustUnderstand headers:[{http://www.w3.org/2005/08/addressing}Action] are not understood
    at com.sun.xml.ws.protocol.soap.MUTube.createMUSOAPFaultException(MUTube.java:148)
    at com.sun.xml.ws.protocol.soap.ClientMUTube.processResponse(ClientMUTube.java:109)
    at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:651)
    at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:600)
    at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:585)
    at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:482)
    at com.sun.xml.ws.client.Stub.process(Stub.java:323)
    at com.sun.xml.ws.client.sei.SEIStub.doProcess(SEIStub.java:161)
    at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:113)
    at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:93)
    at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:144)
    at $Proxy46.createPullPointSubscription(Unknown Source)
    at Test.SubInEventLast(Test.java:173)
    at Test.main(Test.java:139)

请求soap消息是

<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope">
    <S:Body>
    <ns6:CreatePullPointSubscription xmlns:ns2="http://www.w3.org/2005/08/addressing" 
        xmlns:ns3="http://docs.oasis-open.org/wsn/b-2" 
        xmlns:ns4="http://docs.oasis-open.org/wsrf/bf-2" 
        xmlns:ns5="http://docs.oasis-open.org/wsn/t-1" 
        xmlns:ns6="http://www.onvif.org/ver10/events/wsdl" 
        xmlns:ns7="http://www.onvif.org/ver10/schema" 
        xmlns:xmime="http://www.w3.org/2005/05/xmlmime" 
        xmlns:ns9="http://www.w3.org/2004/08/xop/include" 
        xmlns:ns10="http://docs.oasis-open.org/wsrf/r-2">
        <ns6:Filter>
            <ns3:TopicExpression xmlns="http://docs.oasis-open.org/wsn/b-2" 
                xmlns:tns1="http://www.onvif.org/ver10/topics" 
                Dialect="http://www.onvif.org/ver10/tev/topicExpression/ConcreteSet">
                tns1:Device
            </ns3:TopicExpression>
        </ns6:Filter>
        <ns3:InitialTerminationTime>PT1M</ns3:InitialTerminationTime>
    </ns6:CreatePullPointSubscription>
    </S:Body>
</S:Envelope>

这是肥皂回应

              <?xml version="1.0" encoding="UTF-8"?>
                <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" 
                    xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" 
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                    xmlns:c14n="http://www.w3.org/2001/10/xml-exc-c14n#" 
                    xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" 
                    xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" 
                    xmlns:wsa5="http://www.w3.org/2005/08/addressing" 
                    xmlns:xmime5="http://www.w3.org/2005/05/xmlmime" 
                    xmlns:wsrf-bf="http://docs.oasis-open.org/wsrf/bf-2" 
                    xmlns:wstop="http://docs.oasis-open.org/wsn/t-1" 
                    xmlns:tt="http://www.onvif.org/ver10/schema" 
                    xmlns:wsrf-r="http://docs.oasis-open.org/wsrf/r-2" 
                    xmlns:tan1="http://www.onvif.org/ver10/analytics/wsdl/RuleEngineBinding" 
                    xmlns:tan="http://www.onvif.org/ver10/analytics/wsdl" 
                    xmlns:tan2="http://www.onvif.org/ver10/analytics/wsdl/AnalyticsEngineBinding" 
                    xmlns:tds="http://www.onvif.org/ver10/device/wsdl" 
                    xmlns:tev1="http://www.onvif.org/ver10/events/wsdl/NotificationProducerBinding" 
                    xmlns:tev2="http://www.onvif.org/ver10/events/wsdl/EventBinding" 
                    xmlns:tev3="http://www.onvif.org/ver10/events/wsdl/SubscriptionManagerBinding" 
                    xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" 
                    xmlns:tev4="http://www.onvif.org/ver10/events/wsdl/PullPointSubscriptionBinding" 
                    xmlns:tev="http://www.onvif.org/ver10/events/wsdl" 
                    xmlns:timg="http://www.onvif.org/ver10/imaging/wsdl" 
                    xmlns:tptz="http://www.onvif.org/ver10/ptz/wsdl" 
                    xmlns:trt="http://www.onvif.org/ver10/media/wsdl"
                     xmlns:ter="http://www.onvif.org/ver10/error" 
                     xmlns:tns1="http://www.onvif.org/ver10/topics" 
                     xmlns:tnsaxis="http://www.axis.com/2009/event/topics">
                    <SOAP-ENV:Header>
                        <wsa5:Action SOAP-ENV:mustUnderstand="true">http://docs.oasis-open.org/wsn/bw-2/SubscriptionManager/CreatePullPointSubscriptionResponse</wsa5:Action>
                    </SOAP-ENV:Header>
                    <SOAP-ENV:Body>
                         <tev:CreatePullPointSubscriptionResponse>
                            <tev:SubscriptionReference>
                            <wsa5:Address>http://192.168.0.151/onvif/services</wsa5:Address>
                            <wsa5:ReferenceParameters><dom0:SubscriptionId xmlns:dom0="http://www.axis.com/2009/event">3</dom0:SubscriptionId>
                            </wsa5:ReferenceParameters>
                        </tev:SubscriptionReference>
                        <wsnt:CurrentTime>2010-10-27T09:11:42Z</wsnt:CurrentTime>
                        <wsnt:TerminationTime>2010-11-24T09:11:42Z</wsnt:TerminationTime></tev:CreatePullPointSubscriptionResponse>
                     </SOAP-ENV:Body>
                 </SOAP-ENV:Envelope>

6 个答案:

答案 0 :(得分:6)

我在某个特定设备上遇到了同样的问题,我花了几天的时间进行搜索和试错,得出了一个解决方案(几乎完全是偶然的)。我能够通过向端口添加自定义处理程序来解决此问题。处理程序只需要为WS-Addressing Action标头提供QName(调用handleMessage时不需要执行任何操作)。

这对我有用:

public class ActionHandler implements SOAPHandler<SOAPMessageContext> 
{   
    @Override
    public boolean handleMessage(SOAPMessageContext context) 
    {
        // Auto-generated method stub
        return true;
    }

    @Override
    public boolean handleFault(SOAPMessageContext context) 
    {
        // Auto-generated method stub
        return false;
    }

    @Override
    public void close(MessageContext context) 
    {
        // Auto-generated method stub
    }

    @Override
    public Set<QName> getHeaders() 
    {
        Set<QName> set = new HashSet<QName>();
        // Make sure the '[{http://www.w3.org/2005/08/addressing}]Action' header 
        // is handled in case the device set the 'MustUnderstand' attribute to '1'
        set.add(new QName("http://www.w3.org/2005/08/addressing", "Action"));
        return set;
    }   
}

然后将Handler添加到绑定的处理程序链:

BindingProvider bindingProvider = (BindingProvider) eventPortType;      
final Binding binding = bindingProvider.getBinding();

List<Handler> handlerList = binding.getHandlerChain();
if (handlerList == null)
    handlerList = new ArrayList<Handler>();

handlerList.add(new ActionHandler());

binding.setHandlerChain(handlerList);

答案 1 :(得分:4)

就我而言,这有助于:

getPort(QName portName,
            Class<T> serviceEndpointInterface, WebServiceFeature... features)

new javax.xml.ws.soap.AddressingFeature()传递为WebServiceFeature

答案 2 :(得分:4)

FIX的解决方案

  • &#34; MustUnderstand标题:[{http://www.w3.org/2005/08/addressing}行动]未被理解&#34;

  • &#34; 服务器发送HTTP状态码415:无法处理消息,因为内容类型&#39; application / soap + xml; charset =&#34; utf-8&#34 ;;&#34;

使用NetBeans 7.1或更高版本生成Web服务客户端。

(NetBeans将使用 javax.xml.ws.Service

所以 修复代码中的一些内容:

当您实例化您的客户服务时,您需要传递&#34;功能&#34; PARAM。

com.sun.xml.internal.ws.developer.BindingTypeFeature featureB = new BindingTypeFeature(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING);
javax.xml.ws.soap.AddressingFeature featureA = new AddressingFeature();

IGeneratedServiceEV servico = new GeneratedService()
.getBasicHttpBindingGeneratedServiceEV(featureA,featureB);

最重要的是你必须使用&#34;功能&#34;来创建服务: &#34; javax.xml.ws.Service.getPort( wsdlLocation,featureA,FeatureB )&#34;

您可以将代码迁移到另一个IDE,例如&#34; Eclipse&#34;。

答案 3 :(得分:0)

解决此问题的另一种方法是在wsimport命令中添加“-XadditionalHeaders”参数。这会将请求/响应头参数添加到服务方法。

wsimport HelloWorld.wsdl -keep -d ./src/main/java -p com.trial.helloworld -XadditionalHeaders

答案 4 :(得分:0)

是的,我解决了

WSService service  = new WSService();
IWSService wcf = service.getWSHttpBindingIWSService(new AddressingFeature(true));

答案 5 :(得分:0)

如果您使用的是 @WebService 注释之一,@WebServiceProvider 或者@WebServiceRef,那么也可以通过在javax.xml.ws.soap中添加@Addressing注解来解决。