I have been struggling with a problem I have with Axis2 and Rampart for a few hours. I have googled quite extensively and have yet to find a solution. I have even looked at the source code and stepped through it with a debugger. Though this has enlightened me about the error and its cause it has not brought me closer to a solution.

The error that is occurring is

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)

While I have used Axis2 before, I'm no expert with it and even less so with Rampart. I had an existing Web App that has been extended to introduce a client for a Web Service interaction. I installed Axis2 v1.6.1 and Rampart v1.6.1 as instructed. I built the client-side Java classes using the WSDL2Java script and bundled the generated classes into a jar. I then added the appropriate jars and Axis2 repository to the Web App. The WSDL and XSDs are contained in the wsdl.zip attachment of http://mail-archives.apache.org/mod_mbox/axis-java-user/201112.mbox/%3C4B95BC7335A13A42AD0D23462F91AE6F615D057F41%40echo.geometryit.com%3E (Axis2 User Mailing List) The atachments are at the bottom of the page.

The section of code that initialises the client-side of the web service is

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();
}

I know that Rampart is not configured properly but the error is being thrown at the highlighted line (**). This is before where the Rampart configuration would occur, if done.

In debugging, I noticed that the XML, as an OMElement instance, being passed to the SymmetricBindingBuilder.build() (see stacktrace) is (cut down for brevity)

<wsp:Policy>
  <sp:ProtectionToken>
    .
    .
    .
  </sp:ProtectionToken>
  .
  .
  .
</wsp:Policy>

From the code in SymmetricBindingBuilder.build(), I think the XML should be:

<sp:SymmetricBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
  <wsp:Policy>
    <sp:ProtectionToken>
      .
      .
      .
    </sp:ProtectionToken>
    .
    .
    .
  </wsp:Policy>
</sp:SymmetricBinding>

A change to the XML being passed would fix the error but how to accomplish this.

I may have made errors or omissions in what I have said or done in order to be brief. If important details are missing, please highlight these. I'm familiar with Axis2 and not at all with Rampart so any help is appreciated. I am happy to answer questions. Any help is greatly appreciated.

有帮助吗?

解决方案

I'm guessing you're already past this issue. But it's a fresh, raw, itchy wound for me. After many hours of struggling with almost the exact same issue, I finally found a solution.

In the generated client code, eg ClientStub, there's a static getPolicy() function that needs to be adjusted from this (whitespace adjusted for readability):

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);
}

To this:

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;
}

I ran across this solution in this mail thread.

. Topher

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top