CXF wsdl causes ClassCastException to org.apache.wss4j.policy.model.AlgorithmSuite

398 views Asked by At

I have a wsdl supplied by a service I need to access. I am using CXF V3.1.7, it detects a few issues with the supplied wsdl. I fix both issue, identified below. But the then valid wsdl results in a ClassCastException

Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: org.apache.neethi.builders.PolicyContainingPrimitiveAssertion cannot be cast to org.apache.wss4j.policy.model.AlgorithmSuite
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:161)
    at com.sun.proxy.$Proxy68.creditSearch(Unknown Source)
    at uk.co.example.service.TestServiceClient.directSearch(TestServiceClient.java:139)
    at uk.co.example.service.TestServiceClient.main(TestServiceClient.java:71)
Caused by: java.lang.ClassCastException: org.apache.neethi.builders.PolicyContainingPrimitiveAssertion cannot be cast to org.apache.wss4j.policy.model.AlgorithmSuite
    at org.apache.wss4j.policy.model.AbstractBinding.parseNestedBindingPolicy(AbstractBinding.java:78)
    at org.apache.wss4j.policy.model.AbstractBinding.<init>(AbstractBinding.java:43)
    at org.apache.wss4j.policy.model.TransportBinding.<init>(TransportBinding.java:36)
    at org.apache.wss4j.policy.builders.TransportBindingBuilder.build(TransportBindingBuilder.java:45)
    at org.apache.wss4j.policy.builders.TransportBindingBuilder.build(TransportBindingBuilder.java:34)
    at org.apache.neethi.AssertionBuilderFactoryImpl.invokeBuilder(AssertionBuilderFactoryImpl.java:138)
    at org.apache.neethi.AssertionBuilderFactoryImpl.build(AssertionBuilderFactoryImpl.java:117)
    at org.apache.neethi.PolicyBuilder.processOperationElement(PolicyBuilder.java:224)
    at org.apache.neethi.PolicyBuilder.getAllOperator(PolicyBuilder.java:184)
    at org.apache.neethi.PolicyBuilder.processOperationElement(PolicyBuilder.java:217)
    at org.apache.neethi.PolicyBuilder.getExactlyOneOperator(PolicyBuilder.java:180)
    at org.apache.neethi.PolicyBuilder.processOperationElement(PolicyBuilder.java:215)
    at org.apache.neethi.PolicyBuilder.getPolicyOperator(PolicyBuilder.java:174)
    at org.apache.neethi.PolicyBuilder.getPolicy(PolicyBuilder.java:124)
    at org.apache.cxf.ws.policy.attachment.reference.LocalServiceModelReferenceResolver.resolveReference(LocalServiceModelReferenceResolver.java:53)

The relevant part of the wsdl file is:

<wsp1:Policy sch0:Id="ConsumerServiceSoap11Policy">
<wsp1:ExactlyOne>
  <wsp1:All>
    <sp1:TransportBinding>
      <wsp1:Policy>
        <sp1:TransportToken>
          <wsp1:Policy>
            <sp1:HttpsToken RequireClientCertificate="false">
                <wsp1:Policy/>
            </sp1:HttpsToken>
          </wsp1:Policy>
        </sp1:TransportToken>
        <sp:AlgorithmSuite>
            <wsp:Policy>
                <sp:Basic256/>
            </wsp:Policy>
        </sp:AlgorithmSuite>
        <sp1:Layout>
          <wsp1:Policy>
            <sp1:Lax/>
          </wsp1:Policy>
        </sp1:Layout>
        <!--sp1:IncludeTimestamp/-->
      </wsp1:Policy>
    </sp1:TransportBinding>

I added the empty Policy element inside the HttpsToken element and added the AlgorithmSuite element to make CXF accept it as valid for CXF wsdl2java.

Here are the relevant CXF dependencies I include.

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-ws-policy</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.wss4j</groupId>
        <artifactId>wss4j-ws-security-common</artifactId>
        <version>2.1.7</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-ws-security</artifactId>
        <version>${cxf.version}</version>
    </dependency>

How can I prevent this exception?

1

There are 1 answers

0
Colm O hEigeartaigh On

It looks like you're mixing up the namespace definitions, e.g. TransportBinding has "sp1:" whereas AlgorithmSuite has "sp:".