[英]How do I use WS-Addressing properly in an Axis2 client?
所有,我正在嘗試編寫一個 Junit 測試來調用 Axis2.1.5 中的 Web 服務客戶端,但我對如何准確設置它以使用 WS-Addressing 感到困惑。
我已經使用 wsdl2java 生成了一個客戶端存根,並且我正在使用axis2 二進制分發版中的axis2.xml 和模塊存儲庫。
我知道我需要使用 WS-Addressing 的 MemberSubmission 版本,並且我認為我已經正確設置了(使用選項),但是標題似乎沒有正確生成。 (我說“似乎”是因為我也無法弄清楚 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:最終收件人的操作是必需的,但不會出現在消息中。
因此,我還看到一些文檔引用了“引人入勝”的模塊。 但是,當我嘗試將此行添加到我的代碼並將addressing-1.5.1.mar 添加到我的類路徑時:
stub._getServiceClient().engageModule("addressing");
我收到一條錯誤消息:
無法參與模塊:解決 org.apache.axis2.AxisFault:無法參與模塊:在 org.apache.axis2.client.ServiceClient.engageModule(ServiceClient.java:358) 的soapmonitor
但是,日志中沒有其他信息或堆棧跟蹤,所以我很困惑。
關於我做錯了什么的任何想法?
將 addressign.mar 和 sopamoniter.mar 放入項目的 lib 或 classpath 中。 它對我有用,可以從axis2套件中找到mar
在我的 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");
不過,我在 Maven Central 上沒有看到SoapMonitor 的任何classpath-module
工件。
地址可以直接添加到 Soap Header 中。
SOAPHeader soapHeader = soapEnvelope.getHeader();
soapHeader.declareNamespace("http://www.w3.org/2005/08/addressing", "wsa");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.