org.apache.cxf.binding.soap.SoapHeader cannot be cast to org.apache.cxf.binding.soap.SoapHeader

StackOverflow https://stackoverflow.com/questions/22634730

  •  20-06-2023
  •  | 
  •  

Question

I have one WebService installed on JBOSS EAP 6.2. Problem appears when i want to fetch SOAP headers.

Code, where exception is raised:

 ArrayList<SoapHeader> hl = (ArrayList<SoapHeader>) wsctx.getMessageContext().get("org.apache.cxf.headers.Header.list");
    String username = "";
    String password = "";

    for (int i = 0; i < hl.size(); i++) { //for(SoapHeader header : hl) gives this same exception
        SoapHeader header = hl.get(i);
        //here is fetching data from this header. Not important to this case.
    }

I know it isn't really pretty, but i really interested in fetching header and exception raised percisely in this method:

hl.get(i)

And message of exception is:

 org.apache.cxf.binding.soap.SoapHeader cannot be cast to org.apache.cxf.binding.soap.SoapHeader

At first i thought about wrong version in my Maven's POM file so:

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-bindings-soap</artifactId>
        <version>2.4.2</version>
    </dependency>

But it work good i think.

So my question: how to avoid it? Can anyone help me? Thanks

Was it helpful?

Solution 2

Solution was found, just add other library than usual apache-cxf bindings:

    <dependency>
        <groupId>org.jboss</groupId>
        <artifactId>jboss-jaxws</artifactId>
        <version>2.0.1.SP2</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.ws.cxf</groupId>
        <artifactId>jbossws-cxf-server</artifactId>
        <version>4.2.0.Alpha1</version>
        <scope>provided</scope>
    </dependency>

OTHER TIPS

There could be indirect dependency. One of your modules or libraries could also have dependency org.apache.cxf.

Try to figure out whether there are multiple versions. The simplest way is to check all the target dirs and find all the jars. Then compare versions and exclude incorrect ones

  <exclusions>
    <exclusion>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-bindings-soap</artifactId>
      <version>2.4.2</version>
    </exclusion>
  </exclusions>

Also it is possible that JBoss somehow also has the library.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top