caarlos0
caarlos0

Reputation: 20633

JAX-WS in JBoss AS7, getting cast exception

I created a simple webservice with JAX-WS, but I expecting a anoying issue.

My webservice code is something like this:

@WebService
public class UpdateList implements IUpdateList {

    public UpdateList() {
    }

    @Override
    public Collection<Long> getFrom(Long version) {
        System.out.println("test");
        return new ArrayList<Long>();
    }

}

I generated the client code with wsimport and created a simple main for it:

public class App {

    public static void main(String[] args) {
        System.out.println(new UpdateListService().getUpdateListPort().getFrom(183L));
    }
}

But, when I run it, I got a unexplainable class cast exception:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
    at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(Unknown Source)
    at $Proxy29.getFrom(Unknown Source)
    at com.test.App.main(App.java:8)
Caused by: java.lang.ClassCastException: com.sun.xml.bind.v2.runtime.JAXBContextImpl cannot be cast to com.sun.xml.internal.bind.api.JAXBRIContext
    at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.<clinit>(Unknown Source)
    ... 5 more

Then I just realized that it could be some dependency conflict, so I run mvn dependency:tree, and it's clean, my only deps are hibernate, guava, guice and jaxws-rt. (you can see that in my webservice example, it is not using any of cited dependencies, but I'll do it soon, when I fix this issue).

Well, the complete list, for client:

+- com.google.guava:guava:jar:13.0:compile
+- com.google.inject:guice:jar:3.0:compile
|  +- javax.inject:javax.inject:jar:1:compile
|  \- aopalliance:aopalliance:jar:1.0:compile
+- log4j:log4j:jar:1.2.17:compile
+- junit:junit:jar:4.10:test
|  \- org.hamcrest:hamcrest-core:jar:1.1:test
+- com.sun.xml.bind:jaxb-impl:jar:2.2.6:compile
+- org.hsqldb:hsqldb:jar:2.2.8:test
+- com.google.inject.extensions:guice-persist:jar:3.0:compile
+- org.hibernate:hibernate-entitymanager:jar:4.1.6.Final:compile
|  +- org.jboss.logging:jboss-logging:jar:3.1.0.GA:compile
|  +- org.hibernate:hibernate-core:jar:4.1.6.Final:compile
|  |  \- antlr:antlr:jar:2.7.7:compile
|  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.0.Final:compile
|  +- dom4j:dom4j:jar:1.6.1:compile
|  +- org.javassist:javassist:jar:3.15.0-GA:compile
|  \- org.hibernate.common:hibernate-commons-annotations:jar:4.0.1.Final:compile
+- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
+- mysql:mysql-connector-java:jar:5.1.21:compile
\- commons-lang:commons-lang:jar:2.6:compile

and for service:

 +- com.sun.xml.ws:jaxws-rt:jar:2.2.6-2:compile
 |  +- javax.xml.ws:jaxws-api:jar:2.2.8:compile
 |  |  +- javax.xml.bind:jaxb-api:jar:2.2.4:compile
 |  |  +- javax.xml.soap:saaj-api:jar:1.3.4:compile
 |  |  +- org.glassfish:javax.annotation:jar:3.1.1:runtime
 |  |  \- javax.jws:jsr181-api:jar:1.0-MR1:runtime
 |  +- com.sun.xml.messaging.saaj:saaj-impl:jar:1.3.18:compile
 |  +- com.sun.xml.stream.buffer:streambuffer:jar:1.4:compile
 |  |  +- javax.xml.stream:stax-api:jar:1.0-2:compile
 |  |  \- javax.activation:activation:jar:1.1:compile
 |  +- org.codehaus.woodstox:woodstox-core-asl:jar:4.1.2:compile
 |  +- org.codehaus.woodstox:stax2-api:jar:3.1.1:compile
 |  +- org.jvnet.mimepull:mimepull:jar:1.8:compile
 |  +- com.sun.xml.ws:policy:jar:2.3.1:compile
 |  |  +- com.sun.xml.txw2:txw2:jar:20110809:compile
 |  |  |  \- relaxngDatatype:relaxngDatatype:jar:20020414:compile
 |  |  \- com.sun.istack:istack-commons-runtime:jar:2.4:compile
 |  +- org.jvnet.staxex:stax-ex:jar:1.7:compile
 |  +- org.glassfish.gmbal:gmbal-api-only:jar:3.1.0-b001:compile
 |  |  \- org.glassfish.external:management-api:jar:3.0.0-b012:compile
 |  \- org.glassfish.ha:ha-api:jar:3.1.8:compile
 +- com.google.guava:guava:jar:13.0:compile
 +- com.google.inject:guice:jar:3.0:compile
 |  +- javax.inject:javax.inject:jar:1:compile
 |  \- aopalliance:aopalliance:jar:1.0:compile
 +- log4j:log4j:jar:1.2.17:compile
 +- junit:junit:jar:4.10:test
 |  \- org.hamcrest:hamcrest-core:jar:1.1:test
 +- com.sun.xml.bind:jaxb-impl:jar:2.2.6:compile
 +- org.hsqldb:hsqldb:jar:2.2.8:test
 +- com.google.inject.extensions:guice-persist:jar:3.0:compile
 +- org.hibernate:hibernate-entitymanager:jar:4.1.6.Final:compile
 |  +- org.jboss.logging:jboss-logging:jar:3.1.0.GA:compile
 |  +- org.hibernate:hibernate-core:jar:4.1.6.Final:compile
 |  |  \- antlr:antlr:jar:2.7.7:compile
 |  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.0.Final:compile
 |  +- dom4j:dom4j:jar:1.6.1:compile
 |  +- org.javassist:javassist:jar:3.15.0-GA:compile
 |  \- org.hibernate.common:hibernate-commons-annotations:jar:4.0.1.Final:compile
 +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
 +- mysql:mysql-connector-java:jar:5.1.21:compile
 \- commons-lang:commons-lang:jar:2.6:compile

I end this thinking that's some config or jar file missing in my jboss.. I do some research, but not found anything relevant.

Someone already passed througt this? Any suggestion? Thanks

Upvotes: 0

Views: 1812

Answers (1)

James R. Perkins
James R. Perkins

Reputation: 17770

It looks like you're bundling a JAXP implementation, com.sun.xml.bind:jaxb-impl:jar:2.2.6:compile. Try changing the scope to <scope>provided</scope>. Same for the com.sun.xml.ws:jaxws-rt:jar:2.2.6-2:compile.

In fact, most of those should be provided.

Upvotes: 1

Related Questions