代码之家  ›  专栏  ›  技术社区  ›  elduff

如何在Axis2客户机中正确使用WS-Addressing?

  •  7
  • elduff  · 技术社区  · 16 年前

    所有的, 我正试图编写一个JUnit测试,它在Axis2.1.5中调用一个Web服务客户机,我对如何准确地将其设置为使用WS-Addressing感到困惑。

    我使用wsdl2java生成了一个客户机存根,我使用的是来自axis2二进制发行版的axis2.xml和modules存储库。

    我知道我需要使用WS-Addressing的成员提交版本,并且 认为 我已经正确设置了这个(使用选项),但似乎没有正确生成标题。(我之所以说“似乎”,是因为我也不知道如何使用soapmonitor模块-我也欢迎任何有关这方面的提示!).

    不过,我的主要困惑是,要“启用”寻址模块到底需要什么。是否足够用一个引用寻址模块的axis2.xml文件来设置configurationcontext?这样地?:

    //standard out of the box axis2 configs
     ConfigurationContext myConfigContext = ConfigurationContextFactory
       .createConfigurationContextFromFileSystem("C:/devapps/axis2-1.5.1/repository","C:/devapps/axis2-1.5.1/conf/axis2.xml");
    
      Options options = new Options();
      EndpointReference targetEPR = new EndpointReference(
        "https://host:port/service.asmx");
    
      options.setTo(targetEPR);
    
                    //I believe this is what I'm supposed to do to specify the 
      //MemberSubmission version of WS-Addressing
      options.setProperty(AddressingConstants.WS_ADDRESSING_VERSION,
        AddressingConstants.Submission.WSA_NAMESPACE);
      //No idea of this is needed or not.
      options.setProperty(AddressingConstants.INCLUDE_OPTIONAL_HEADERS,
        Boolean.TRUE);
      options.activate(myConfigContext);
      options.setAction("someAction");
    
      CaseDetailsServiceStub stub = new CaseDetailsServiceStub(
        "https://host:port/service.asmx");
      stub._getServiceClient().setOptions(options);
    
      //I'm calling this from a Junit test
      assertNotNull(stub.someAction(someParam));
    

    在上面设置了我的选项后,可以在日志文件中看到模块是从axis2.xml加载的:

    [INFO] Deploying module: addressing-1.5.1 - file:/C:/devapps/axis2-1.5.1/repository/modules/addressing-1.5.1.mar
    

    但我想我没有收到任何地址头。此时从服务器返回的错误是:

    页眉 http://schemas.xmlsoap.org/ws/2004/08/addressing:Action 对于最终收件人是必需的,但 消息中不存在。

    所以,我也看到了一些参考“参与”模块的文档。当我尝试将此行添加到代码中,并将addressing-1.5.1.mar添加到类路径中时,尽管:

    stub._getServiceClient().engageModule("addressing");
    

    我得到一个错误,说:

    无法启用模块:寻址 org.apache.axis2.axisfault:无法启用模块:soapmonitor 在Org.Apache .AxIS2.Client .Service Eclilient .EngEnMeMod(Service Client .java:358)

    但是,在日志中没有其他信息或堆栈跟踪,所以我很困惑。

    对我做错了什么有什么看法吗?

    2 回复  |  直到 11 年前
        1
  •  7
  •   deepak    16 年前

    将addressign.mar和sopamoniter.mar放入项目的lib或classpath中。 对我有用 从axis2工具包中查找mar

        2
  •  2
  •   Ben Hutchison    11 年前

    在我的Maven项目中,我必须声明对 org.apache.axis2:addressing 工件:

    <dependency>
        <groupId>org.apache.axis2</groupId>
        <artifactId>addressing</artifactId>
        <version>1.6.2</version>
        <classifier>classpath-module</classifier>
    </dependency>
    
    MyServiceStub stub = new MyServiceStub(targetEndpoint);
    stub._getServiceClient().engageModule("addressing");
    

    我什么也没看到 classpath-module 的项目 SoapMonitor on Maven Central 但是。