当前位置: 首页 > 知识库问答 >
问题:

Axis2客户端抛出AxisFault:必须了解头安全性检查失败

林雅畅
2023-03-14

我使用的是Axis2-1.6.1,能够成功地发送SOAP请求。以下是请求的一个示例:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
  <soapenv:Header>
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="true">
      <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <wsse:Username>***username***</wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">***pass***</wsse:Password>
        <wsse:Nonce Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">***nonce***</wsse:Nonce>
        <wsu:Created Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">***datetime***</wsu:Created>
      </wsse:UsernameToken>
    </wsse:Security>
    <wsa:Action xmlns:wsa="http://www.w3.org/2005/08/addressing">http://mysite/contract/users/v3/IUsers/EchoAuthenticated</wsa:Action>
  </soapenv:Header>
  <soapenv:Body>
    <ns6:EchoAuthenticated xmlns:ns6="http://mysite/contract/users/v3">
      <ns6:value>success</ns6:value>
    </ns6:EchoAuthenticated>
  </soapenv:Body>
</soapenv:Envelope>

收到响应后,将引发此异常:

org.apache.axis2. AxisFault:必须理解头http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd检查失败:安全性

在做了一些研究后,我的印象是,在响应中有一些Axis2不喜欢的东西。困惑的是,我复制了上面的请求,并将其粘贴到SoapUI中并启动了它。它起作用了,我收到了下面的响应。我还使用Fiddler确认,这和我在Eclipse中发送这个请求时得到的响应是一样的,只是Axis2不喜欢客户端的一些东西,也许是必须的。明白吗?

以下是回应:

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
  <s:Header>
    <a:Action s:mustUnderstand="1">http://mysite/contract/users/v3/IUsers/EchoAuthenticatedResponse</a:Action>
    <a:RelatesTo>urn:uuid:***guid***</a:RelatesTo>
    <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <u:Timestamp u:Id="_0">
        <u:Created>***datetime***</u:Created>
        <u:Expires>***datetime***</u:Expires>
      </u:Timestamp>
    </o:Security>
  </s:Header>
  <s:Body>
    <EchoAuthenticatedResponse xmlns="http://mysite/contract/users/v3">
      <EchoAuthenticatedResult>This is the Users service answering back. The value you sent was: success</EchoAuthenticatedResult>
    </EchoAuthenticatedResponse>
  </s:Body>
</s:Envelope>

由于Axis2与一个产品捆绑在一起,我的能力有限,无法升级到较新版本的Axis2,但我需要了解如何通过此错误。

共有1个答案

邢烨烨
2023-03-14

我找到了一个解决方案,就是在对false的响应中设置mustUnderstand实例

为了做到这一点,我做了以下工作:

  1. 创建一个扩展*org的处理程序类。阿帕奇。axis2。处理程序。AbstractHandler

我必须理解汉德勒。JAVA

import java.util.Iterator;

import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPHeader;
import org.apache.axiom.soap.SOAPHeaderBlock;
import org.apache.axis2.AxisFault;
import org.apache.axis2.context.MessageContext;

public class MustUnderstandHandler extends org.apache.axis2.handlers.AbstractHandler  {

  @Override
  public InvocationResponse invoke(MessageContext messageContext) throws AxisFault {
    
    try{
      
      System.out.println("RemoveMustUnderstandAll: invoke " + messageContext);
      
      SOAPEnvelope env = messageContext.getEnvelope();
      SOAPHeader header = env.getHeader();
      
      if(header != null){
        
          for(Iterator<?> itr = header.getChildElements(); itr.hasNext();){
            
              SOAPHeaderBlock headerBlock = (SOAPHeaderBlock) itr.next();
              
              if(headerBlock.getMustUnderstand()){
                
                headerBlock.setMustUnderstand(false);
                System.out.println("RemoveMustUnderstandAll (" + messageContext + "): setMustUnderstand(false) to " + headerBlock.getQName());
              }
          }
      }
    }
    catch(Exception e){

      System.out.println(e.toString());
    }
    
    return InvocationResponse.CONTINUE;
  }
}

在生成的存根(由WSDL2Java创建)中,我找到了它正在执行客户端的实例,在每一行之前,我包括以下内容:

我的浴缸。JAVA

AxisConfiguration axisConfiguration = _messageContext.getConfigurationContext().getAxisConfiguration();
ArrayList arrayList = new ArrayList();
arrayList.add(new MustUnderstandHandler());
axisConfiguration.setInPhasesUptoAndIncludingPostDispatch(arrayList);

// execute the operation client
_operationClient.execute(true);
 类似资料:
  • 我在WSO2 AS 5上部署了一个axis2服务,我使用该服务器用UT basic auth保护了该服务。我想用Axis客户机调用服务。我生成了存根并尝试了这个, 我在客户端得到这个错误, 我在这里做错了什么?在WSO2 AS中,如何为使用UT保护的服务编写axis客户机?提前谢了。

  • 我正在建立一个测试实验室来学习更多关于WSO2应用的知识。我试图重新创建这里描述的场景:http://wso2.org/library/tutorials/2012/12/providing-xacml-fine-grained-authorization-webapps 我使用的是一台Windows 2008服务器,WSO应用程序都在不同的端口上监听。WSOIS的tryit功能表明策略正在正确评

  • 我试图使用托管在Tomcat上的java应用程序调用webservice(SOAP1.2)。已经使用Axis2生成了客户端。当我调用WS方法时,我会变得低于errow。 请帮忙。

  • 我一直在进入Quarkus并试图利用叛变Vertx网络客户端。我的代码可以工作,但我不希望依赖不安全/未检查的分配,这就是我目前在HttpResponse上使用bodyAsJson方法编写代码的方式。有没有更好的方法,或者更标准的方法来解码来自Mutiny Vertx客户端的JSON?我意识到我可以调用bodyAsJsonObject并返回它,但我需要对API调用返回的数据进行处理,所以我需要将其

  • 我有一个servlet,它以XML格式响应。 客户端通过HttpSurlConnection连接到这个servlet。现在,如果客户端不调用会有问题吗? 非常感谢。

  • 问题内容: 最近,我一直在查看Pagedown.js,以在页面上使用mark-down而不是丑陋的只读textareas。 我非常谨慎,因为欺骗已转换的转换器似乎很容易。我已经看到了一些有关Angular.js及其html绑定的讨论,并且在Knockout.js 3.0发布时听到了一些关于html绑定以前不安全的信息。 似乎有人需要做的所有事情来禁用Pagedown.js中的消毒剂,例如- 他们可