几个小时以来,我一直在努力解决 Axis2 和 Rampart 的问题。我已经在谷歌上进行了广泛的搜索,但尚未找到解决方案。我什至查看了源代码并使用调试器逐步完成了它。虽然这让我了解了错误及其原因,但它并没有让我更接近解决方案。
发生的错误是
java.lang.IllegalArgumentException: {http://schemas.xmlsoap.org/ws/2005/07/securitypolicy}ProtectionToken is not a <wsp:Policy> element.
at org.apache.neethi.PolicyBuilder.getPolicyOperator(PolicyBuilder.java:177)
at org.apache.neethi.PolicyBuilder.getPolicy(PolicyBuilder.java:125)
at org.apache.neethi.PolicyEngine.getPolicy(PolicyEngine.java:102)
at org.apache.ws.secpolicy11.builders.SymmetricBindingBuilder.build(SymmetricBindingBuilder.java:41)
at org.apache.ws.secpolicy11.builders.SymmetricBindingBuilder.build(SymmetricBindingBuilder.java:36)
at org.apache.neethi.AssertionBuilderFactoryImpl.invokeBuilder(AssertionBuilderFactoryImpl.java:129)
at org.apache.neethi.AssertionBuilderFactoryImpl.build(AssertionBuilderFactoryImpl.java:110)
at org.apache.neethi.PolicyBuilder.processOperationElement(PolicyBuilder.java:225)
at org.apache.neethi.PolicyBuilder.getAllOperator(PolicyBuilder.java:185)
at org.apache.neethi.PolicyBuilder.processOperationElement(PolicyBuilder.java:218)
at org.apache.neethi.PolicyBuilder.getExactlyOneOperator(PolicyBuilder.java:181)
at org.apache.neethi.PolicyBuilder.processOperationElement(PolicyBuilder.java:216)
at org.apache.neethi.PolicyBuilder.getPolicyOperator(PolicyBuilder.java:175)
at org.apache.neethi.PolicyBuilder.getPolicy(PolicyBuilder.java:114)
at org.apache.neethi.PolicyBuilder.getPolicy(PolicyBuilder.java:100)
at org.apache.neethi.PolicyEngine.getPolicy(PolicyEngine.java:80)
at com.geometryit.blis.ablis.contentManagement.ContentManagementServiceStub.getPolicy(ContentManagementServiceStub.java:413)
at com.geometryit.blis.ablis.contentManagement.ContentManagementServiceStub.populateAxisService(ContentManagementServiceStub.java:57)
at com.geometryit.blis.ablis.contentManagement.ContentManagementServiceStub.<init>(ContentManagementServiceStub.java:108)
at com.geometryit.blis.ablis.contentManagement.ContentManagementServiceStub.<init>(ContentManagementServiceStub.java:97)
at com.geometryit.blis.production.Publish.init(Publish.java:214)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1133)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1087)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:996)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4834)
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5155)
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5150)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
虽然我以前使用过 Axis2,但我不是它的专家,更不用说 Rampart。我有一个现有的 Web 应用程序,它已被扩展为引入 Web 服务交互的客户端。我按照指示安装了 Axis2 v1.6.1 和 Rampart v1.6.1。我使用 WSDL2Java 脚本构建了客户端 Java 类,并将生成的类捆绑到一个 jar 中。然后,我将适当的 jar 和 Axis2 存储库添加到 Web 应用程序。WSDL 和 XSD 包含在http://mail-archives.apache.org/mod_mbox/axis-java-user/201112.mbox/%3C4B95BC7335A13A42AD0D23462F91AE6F615D057F41%40echo.geometryit.com%3E的 wsdl.zip 附件中 (Axis2 用户邮件列表)附件位于页面底部。
初始化 Web 服务客户端的代码部分是
try
{
ConfigurationContext context = ConfigurationContextFactory.createConfigurationContextFromFileSystem(this.getWebInfPath() + "repository" );
**ablisContentManagementService = new ContentManagementServiceStub( context, "http://services.ablis.uat.business.gov.au/ContentManagement.svc" );
ServiceClient ablisContentManagementServiceClient = ablisContentManagementService._getServiceClient();
ablisContentManagementServiceClient.engageModule( "addressing" );
ablisContentManagementServiceClient.engageModule( "rampart" );
ablisAxisFault = null;
}
catch ( AxisFault af )
{
ablisContentManagementService = null;
ablisAxisFault = af;
af.printStackTrace();
}
catch ( Throwable t )
{
t.printStackTrace();
}
我知道 Rampart 配置不正确,但在突出显示的行 (**) 处引发了错误。如果完成,这是在 Rampart 配置发生之前。
在调试中,我注意到作为 OMElement 实例的 XML 被传递给 SymmetricBindingBuilder.build() (参见stacktrace)是(为简洁起见)
<wsp:Policy>
<sp:ProtectionToken>
.
.
.
</sp:ProtectionToken>
.
.
.
</wsp:Policy>
从 SymmetricBindingBuilder.build() 中的代码来看,我认为 XML 应该是:
<sp:SymmetricBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:ProtectionToken>
.
.
.
</sp:ProtectionToken>
.
.
.
</wsp:Policy>
</sp:SymmetricBinding>
对正在传递的 XML 的更改将修复错误,但如何完成此操作。
为了简短起见,我可能在我所说或所做的事情中犯了错误或遗漏。如果缺少重要细节,请突出显示这些。我对 Axis2 很熟悉,但对 Rampart 一点也不熟悉,因此不胜感激。我很乐意回答问题。任何帮助是极大的赞赏。