![](/img/trans.png)
[英]Java-Missing WS-Addressing header: “{http://www.w3.org/2005/08/addressing}Action”
[英]Jax-ws : Java SOAP exception :MustUnderstand headers:[{http://www.w3.org/2005/08/addressing}Action
我正在使用 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)
請求肥皂消息是
<?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>
我在某個特定設備上遇到了同樣的問題,我花了幾天的時間進行搜索和反復試驗才找到解決方案(幾乎純屬偶然)。 我能夠通過向端口添加自定義處理程序來解決這個問題。 處理程序只需要為 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);
就我而言,這有幫助:
getPort(QName portName,
Class<T> serviceEndpointInterface, WebServiceFeature... features)
將new javax.xml.ws.soap.AddressingFeature()
作為WebServiceFeature
傳遞。
FIX的解決方案
“ MustUnderstand 標頭:[{ http://www.w3.org/2005/08/addressing }Action] 無法理解”
"服務器發送 HTTP 狀態碼 415:無法處理消息,因為內容類型為 'application/soap+xml;charset="utf-8";"
使用 NetBeans 7.1 或更高版本生成 Web 服務客戶端。
( NetBeans 將使用javax.xml.ws.Service )
所以修復代碼中的一些東西:
當您實例化您的客戶端服務時,您需要傳遞“功能”參數。
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);
最重要的是,您必須使用“功能”創建服務:“javax.xml.ws.Service.getPort( wsdlLocation, featureA, FeatureB )”
在您可以將代碼遷移到另一個 IDE(如“Eclipse”)之后。
是的,我解決了
WSService service = new WSService();
IWSService wcf = service.getWSHttpBindingIWSService(new AddressingFeature(true));
解決此問題的另一種方法是向 wsimport 命令添加“-XadditionalHeaders”參數。 這會將請求/響應頭參數添加到服務方法。
wsimport HelloWorld.wsdl -keep -d ./src/main/java -p com.trial.helloworld -XadditionalHeaders
如果您使用的是@WebService 、@ WebServiceProvider或@WebServiceRef注釋之一,則還可以通過添加 javax.xml.ws.soap 中的@Addressing注釋來解決。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.