IllegalArgumentException:ProtectionToken不是<wsp:policy>元素</wsp:policy>

时间:2011-12-02 23:57:15

标签: java web-services client axis2 rampart

我一直在努力解决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 App。 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一点都不熟悉,所以对任何帮助表示赞赏。我很乐意回答问题。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

我猜你已经过了这个问题。但这对我来说是一个新鲜的,原始的,发痒的伤口。经过几个小时的努力几乎完全相同的问题,我终于找到了解决方案。

在生成的客户端代码中,例如ClientStub,需要从中调整静态getPolicy()函数(为了可读性而调整空白):

private static org.apache.neethi.Policy getPolicy (java.lang.String policyString) 
{
  java.io.ByteArrayInputStream bais = new java.io.ByteArrayInputStream(policyString.getBytes());
  return org.apache.neethi.PolicyEngine.getPolicy(bais);
}

对此:

private static org.apache.neethi.Policy getPolicy (java.lang.String policyString) 
{
  java.io.ByteArrayInputStream bais = new java.io.ByteArrayInputStream(policyString.getBytes());
  try 
  {
    StAXOMBuilder builder = new StAXOMBuilder(bais);
    OMElement documentElement = builder.getDocumentElement();
    return org.apache.neethi.PolicyEngine.getPolicy(documentElement);
  } 
  catch (XMLStreamException e) 
  {
    e.printStackTrace();
  }
  return null;
}

我在this mail thread中遇到了这个解决方案。

。托弗