我正在使用Axis2-1.6.3,并且已经能够成功发送SOAP请求。这是请求的示例:(我正在呼叫会话Sabre的创建服务)
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<ns4:MessageHeader
xmlns:ns4="http://www.ebxml.org/namespaces/messageHeader" soapenv:mustUnderstand="0">
<ns4:From>
<ns4:PartyId>client.webconnect@sabre.com</ns4:PartyId>
</ns4:From>
<ns4:To>
<ns4:PartyId>sabre.webconnect@sabre.com</ns4:PartyId>
</ns4:To>
<ns4:CPAId>QI6D</ns4:CPAId>
<ns4:ConversationId>sabre@12345.com</ns4:ConversationId>
<ns4:Service>SessionCreateRQ</ns4:Service>
<ns4:Action>SessionCreateRQ</ns4:Action>
<ns4:MessageData>
<ns4:MessageId>mid:20001209-133003-2333@resourcecentre.abacus.com.sg</ns4:MessageId>
<ns4:Timestamp>2007-08-28T11:15:12Z</ns4:Timestamp>
</ns4:MessageData>
</ns4:MessageHeader>
<ns6:Security
xmlns:ns6="http://schemas.xmlsoap.org/ws/2002/12/secext" soapenv:mustUnderstand="0">
<ns6:UsernameToken>
<ns6:Username>9102</ns6:Username>
<ns6:Password>focus75</ns6:Password>
<Organization>QI6D</Organization>
<Domain>DEFAULT</Domain>
</ns6:UsernameToken>
</ns6:Security>
</soapenv:Header>
<soapenv:Body>
<ns1:SessionCreateRQ
xmlns:ns1="http://www.opentravel.org/OTA/2002/11" returnContextID="false">
<ns1:POS>
<ns1:Source PseudoCityCode="QI6D"/>
</ns1:POS>
</ns1:SessionCreateRQ>
</soapenv:Body>
</soapenv:Envelope>
在收到响应后,将引发此异常:
org.apache.axis2.AxisFault: Must Understand check failed for header http://www.ebxml.org/namespaces/messageHeader : MessageHeader
at org.apache.axis2.engine.AxisEngine.checkMustUnderstand(AxisEngine.java:105) ~[axis2-1.6.3.jar:na]
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:171) ~[axis2-1.6.3.jar:na]
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:364) [axis2-1.6.3.jar:na]
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421) [axis2-1.6.3.jar:na]
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229) [axis2-1.6.3.jar:na]
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165) [axis2-1.6.3.jar:na]
at com.sabre.webservices.websvc.SessionCreateRQServiceStub.sessionCreateRQ(SessionCreateRQServiceStub.java:212) [classes/:na]
at com.wipro.w2g.partner.airline.calendarShopping.sabre.SessionCreateServiceImpl.createSabreSession(SessionCreateServiceImpl.java:175) [classes/:na]
at com.wipro.w2g.partner.airline.calendarShopping.manager.CalendarShoppingSessionManager.createSabreSession(CalendarShoppingSessionManager.java:279) [classes/:na]
at com.wipro.w2g.partner.airline.calendarShopping.services.flow.CalendarShoppingServiceFlow.getCalendarShoppingFlightSearch(CalendarShoppingServiceFlow.java:221) [classes/:na]
at com.wipro.w2g.partner.airline.calendarShopping.manager.CalendarShoppingSegmentHandlerImpl.searchSegmentHandlerImpl(CalendarShoppingSegmentHandlerImpl.java:51) [classes/:na]
at com.wipro.w2g.partner.airline.calendarShopping.spring.appcontainer.AsyncAppPartnerHandler.asyncCallForAllPartners(AsyncAppPartnerHandler.java:37) [classes/:na]
at com.wipro.w2g.partner.airline.calendarShopping.manager.CalendarShoppingServiceAction.asyncCallToAllPartners(CalendarShoppingServiceAction.java:213) [classes/:na]
at com.wipro.w2g.partner.airline.calendarShopping.manager.CalendarShoppingServiceAction.manageCalendarShoppingServiceCall(CalendarShoppingServiceAction.java:107) [classes/:na]
at com.wipro.w2g.partner.airline.calendarShopping.manager.CalendarShoppingManager.invokeCalendarShoppingServiceAsyncronously(CalendarShoppingManager.java:87) [classes/:na]
at com.wipro.w2g.partner.airline.calendarShopping.manager.CalendarShoppingManager$$FastClassBySpringCGLIB$$c61f4c16.invoke(<generated>) [classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) [spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738) [spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) [spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.aop.interceptor.AsyncExecutionInterceptor$1.call(AsyncExecutionInterceptor.java:115) [spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at java.util.concurrent.FutureTask.run(Unknown Source) [na:1.8.0_101]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_101]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_101]
at java.lang.Thread.run(Unknown Source) [na:1.8.0_101]
这是响应xml
<?xml version='1.0' encoding='utf-8'?>
<soap-env:Envelope
xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Header>
<eb:MessageHeader
xmlns:eb="http://www.ebxml.org/namespaces/messageHeader" eb:version="1.0" soap-env:mustUnderstand="1">
<eb:From>
<eb:PartyId eb:type="URI">sabre.webconnect@sabre.com</eb:PartyId>
</eb:From>
<eb:To>
<eb:PartyId eb:type="URI">client.webconnect@sabre.com</eb:PartyId>
</eb:To>
<eb:CPAId>QI6D</eb:CPAId>
<eb:ConversationId>sabre@12345.com</eb:ConversationId>
<eb:Service>SessionCreateRQ</eb:Service>
<eb:Action>ErrorRS</eb:Action>
<eb:MessageData>
<eb:MessageId>1961156184619800211</eb:MessageId>
<eb:Timestamp>2018-09-25T05:07:42</eb:Timestamp>
<eb:RefToMessageId>mid:20001209-133003-2333@resourcecentre.abacus.com.sg</eb:RefToMessageId>
</eb:MessageData>
</eb:MessageHeader>
<wsse:Security
xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext"/>
</soap-env:Header>
<soap-env:Body>
<soap-env:Fault>
<faultcode>soap-env:Client.AuthenticationFailed</faultcode>
<faultstring>Authentication failed</faultstring>
<detail>
<StackTrace>com.sabre.universalservices.base.security.AuthenticationException: errors.authentication.USG_AUTHENTICATION_FAILED</StackTrace>
</detail>
</soap-env:Fault>
</soap-env:Body>
</soap-env:Envelope>
我找到了一种解决方案,将响应中的mustUnderstand实例设置为false,但我可以将请求的mustUnderstand实例更改为false,但我无法为响应将其更改
答案 0 :(得分:0)
您应该在getHeaders()响应中添加一个返回QName(“ http://www.ebxml.org/namespaces/messageHeader”,“ MessageHeader”)的SOAPHandler。
一个例子是...
public class MessageHeaderHandler implements SOAPHandler<SOAPMessageContext>, Serializable {
private static final long serialVersionUID = 1L;
QName messageHeaderQName = new QName("http://www.ebxml.org/namespaces/messageHeader", "MessageHeader");
Set<QName> headers = new HashSet<QName>();
public MessageHeaderHandler() {
headers.add(messageHeaderQName);
}
@Override
public Set<QName> getHeaders() {
return headers;
}
@Override
public boolean handleMessage(SOAPMessageContext context) {
return true;
}
@Override
public boolean handleFault(SOAPMessageContext context) {
return true;
}
@Override
public void close(MessageContext context) {
}
}
然后将其添加到处理程序链中...
List<Handler> handlerChain = new ArrayList<Handler>();
handlerChain.add(new MessageHeaderHandler());
BindingProvider bindingProvider = // get the binding provider depending on your client;
bindingProvider.getBinding().setHandlerChain(this.handlerChain);
答案 1 :(得分:0)
下面的链接中的解决方案在进行较小的更改后即可使用。 Axis2 Client Throws AxisFault: Must Understand check failed for header Security
我添加了: headerBlock.setProcessed(); 后 headerBlock.setMustUnderstand(false);