CXF ClassNotFoundException: javax.ws.rs.MessageProcessingException - java

I'm trying to start a jax ws & rs server endpoints, I can get them started using rs-api 2.0 (and version 2.0.1) but when I try to make a request it throws
java.lang.NoClassDefFoundError: javax/ws/rs/MessageProcessingException
There are some other threads in SO regarding this matter but the suggestions don't work for me. Using any of the rs-api 2 milestone versions throws issues
Exception in thread "main" java.lang.NoClassDefFoundError: javax/ws/rs/BadRequestException
I'm running this as a java application, not a webapp. Anyone have any ideas to try? Thanks
EDIT: My dependencies. I added jsr311 but that did not change the MessageProcessingException
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
CXF: version 2.7.0
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-security</artifactId>
</dependency>
rs-api version: 2.0
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
jsr311 version: 1.1.1
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</dependency>

Faced the same issue, but later when I used 3.0.0-milestone2 of cxf-bundle with 2.1-m01 of javax.ws.rs-api, it worked like a charm.
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1-m01</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-bundle</artifactId>
<version>3.0.0-milestone2</version>
</dependency>

<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0-m10</version>
</dependency>
This version has support for javax.ws.rs.MessageProcessingException class.

I took this same error using Jersey client without JSON/JAXB providers to do the calls to server, when I configure Jettison provider the problem was solved. This erros also occour when I use a incompatible POJO to marshaling object to call service. check it. I hope this help.
The problem also occur when you have Classloader problems, check your maven dependecy hierarchy conflicts of jax-rs. In my case I need to use exlcusion filter in my pom.xml like
<exclusions>
<exclusion>
<artifactId>javax.ws.rs-api</artifactId>
<groupId>javax.ws.rs</groupId>
</exclusion>
</exclusions>
I made exclusion in cxf-bundle-jaxrs in another project that uses javax.ws.rs-api dependency. Using dependency of cxf-rt-frontend-jaxrs:2.7.11 was sufficient.

I had the same issue & I had to add this exclusion -
<exclusion>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
</exclusion>

Related

How to fix ClassCastException when using jaxb dependency

I am developing jira server plugin which uses a 3rd party library which contains jaxb as a runtime dependency. Following is the pom xml file of that 3rd party library
<dependencies>
<dependency>
<groupId>org.threeten</groupId>
<artifactId>threetenbp</artifactId>
<version>1.3.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.gsonfire</groupId>
<artifactId>gson-fire</artifactId>
<version>1.8.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.12</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.20</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
<scope>compile</scope>
</dependency>
And also a jaxb version (v2.3.0) is available in the jira server runtime. I am getting the following error
ClassCastException: attempting to cast jar:file:/C:/JiraServer/Jira%20Software/Atlassian/Jira/atlassian-jira/WEB-INF/lib/jaxb-api-2.3.0.jar!/javax/xml/bind/JAXBContext.class to
bundle://252.0:18/javax/xml/bind/JAXBContext.class. Please make sure that you are specifying the proper ClassLoader.
I tried to exclude the jaxb from the 3rd party library that I am using, but it did not worked for me. Can someone please advice how to resolve this issue.
Thanks!
Mifraz

Why #Secured is not working in Tapestry 5.4.0?

I just upgraded Tapestry 5.3.8 to 5.4.0, and then I found the #Secured annotation has an issue. If I go to page which has this #Secured, the exception org/apache/tapestry5/services/TransformMethodSignature and could not initialize class nu.localhost.tapestry5.springsecurity.services.internal.TransformConstants2 will thrown (with no detail). Is it no longer supported in 5.4.0? Or do I need to upgrade something in my pom.xml?
pom.xml
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-core</artifactId>
<version>${tapestry-release-version}</version>
</dependency>
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-hibernate</artifactId>
<version>${tapestry-release-version}</version>
</dependency>
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-upload</artifactId>
<version>${tapestry-release-version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>4.2.0.Final</version>
</dependency>
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-spring</artifactId>
<version>${tapestry-release-version}</version>
</dependency>
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-kaptcha</artifactId>
<version>${tapestry-release-version}</version>
</dependency>
<dependency>
<groupId>org.got5</groupId>
<artifactId>tapestry5-jquery</artifactId>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>com.github.lltyk</groupId>
<artifactId>tapestry-spring-security</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.0.RELEASE</version>
<scope>test</scope>
</dependency>
Well, after struggling for days, I'm finally figured out that this library:
<dependency>
<groupId>com.github.lltyk</groupId>
<artifactId>tapestry-spring-security</artifactId>
<version>3.0.3</version>
</dependency>
Can not keep up with Tapesty 5.4, because it has a class: nu.localhost.tapestry5.springsecurity.services.internal.TransformConstants2 that refers to org.apache.tapestry5.services.TransformMethodSignature which is not available any longer in Tapestry 5.4.
I've tried to upgrade tapestry-spring-security to highest version: 3.0.5, but still can't keep up with Tapestry 5.4, so the only way to solve it, is to remove it. And to replace all the functionalities which was provided by tapestry-spring-security, I need to add 4 new libs to pom (in your case you might need to add more or less than 4): spring-security-core: 4.0.0.M1, spring-security-web: 4.2.3.RELEASE, spring-dao: 2.0.8, servlet-api: 2.5
In my case, I need to copy the code from the original source for these classes: LogoutService (interface), LogoutServiceImpl, IfRole and IfLoggedIn. Create the files and paste the code.

javax.enterprise.inject.Vetoed Open web beans, which jar?

I'm wanting to try out Open Web Beans 1.6.2, but the jars it lists on it's website for adding CDI support to a Java SE application
openwebbeans-spi.jar
openwebbeans-impl.jar
geronimo-jcdi_1.0_spec.jar
geronimo-atinject_1.0_spec.jar
geronimo-interceptor_1.2_spec.jar
geronimo-annotation_1.2_spec.jar
Don't seem to contain the javax.enterprise.inject.Vetoed annotation, I've had to add cdi-api 1.2 as a dependency to resolve the issue, but I'm not sure if this is correct as all other CDI dependencies were resolved by the above? Here are the dependencies I have in my pom, is this correct?
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-impl</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-spi</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jcdi_1.0_spec</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-atinject_1.0_spec</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-interceptor_1.2_spec</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-annotation_1.2_spec</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.2</version>
</dependency>
This link seems to suggest support for #Vetoed was added in Open Web Beans 1.5.0
Please upgrade geronimo-jcdi_1.0_spec to jcdi_1.1 version
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jcdi_1.1_spec</artifactId>
<version>1.0</version>
</dependency>
Although your problem is weird, because you have also following entry:
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.2</version>
</dependency
which also contains #Vetoed and thus should be enough. Does maven ignore it somehow?

Hibernate Issue with Spring Maven & Tomcat

I have been scratching my head for a few hours and can't seem to solve this issue. I have been following several tutorials on getting started with Maven & Hibernate, following this and this. Each time I deploy on Virgo Tomcat, I get the following error spitting out
An Import-Package could not be resolved. Caused by missing constraint in bundle <com.stuart.contextmanagement_0.1.0>
constraint: <Import-Package: javassist.util.proxy; version="[3.18.0,4.0.0)">
So I added Java Assist as a dependency in my pom, then is spat out
An Import-Package could not be resolved. Caused by missing constraint in bundle
com.stuart.contextmanagement_0.1.0>
constraint: <Import-Package: com.sun.jdi.request; version="0.0.0">
I can't find the above package when searching through repo's. I have also experienced a similar issue before, and every time I add a new dependency which it can't find, it can't find another one and so on...
A snippet of my pom is as follows;
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.5.Final</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
Thanks for your help.
hm, have you tried also the jboss javassist?
I ended up finding a solution. For any one who's interested, I ended up creating another maven project and exporting several other dependencies than I could see any any documentation or tutorial. Below is the snippet of my final pom.xml.
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.spring-library</artifactId>
<type>libd</type>
<version>3.0.5.RELEASE</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.javassist</groupId>
<artifactId>com.springsource.javassist</artifactId>
<version>3.15.0.GA</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>com.springsource.javax.persistence</artifactId>
<version>2.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>com.springsource.org.apache.commons.dbcp</artifactId>
<version>1.2.2.osgi</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>com.springsource.org.apache.derby</artifactId>
<version>10.5.1000001.764942</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>com.springsource.org.hibernate</artifactId>
<version>3.3.2.GA</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>com.springsource.org.hibernate.annotations</artifactId>
<version>3.4.0.GA-A</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>com.springsource.org.hibernate.annotations.common</artifactId>
<version>3.3.0.ga</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.dom4j</groupId>
<artifactId>com.springsource.org.dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.9</version>
<scope>compile</scope>
</dependency>
</dependencies>

NoSuchMethodError: JsonFactory.fromInputStream

I am trying to get a clean code sample of Google API OAuth2 authentication.
My code is mostly based on the explanation at https://code.google.com/p/google-api-java-client/wiki/OAuth2
I deviate from this tutorial because I want my libraries be managed by Maven and because I want to create a project without Google Apps Engine dependencies.
Each time I try to the run the project on my Glassfish server, I get the following error, probably indicating a dependency conflict.
java.lang.NoSuchMethodError: com.google.api.client.json.JsonFactory.fromInputStream(Ljava/io/InputStream;Ljava/lang/Class;)Ljava/lang/Object;
The relevant piece of my pom.xml:
<dependencies>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.14.1-beta</version>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
<version>1.14.1-beta</version>
</dependency>
<dependency>
<groupId>com.google.api-jackson2</groupId>
<artifactId>google-api-jackson2</artifactId>
<version>1.14.1-beta</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-calendar</artifactId>
<version>v3-rev34-1.14.1-beta</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client</artifactId>
<version>1.14.1-beta</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client-servlet</artifactId>
<version>1.14.1-beta</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.CR2</version>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.1-PRD</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
</dependency>
</dependencies>
Please help me find the root cause of this error, because the used dependencies seem just fine to me and there's no similar problem case I could find.
The correct dependency for jackson2 is:
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-jackson2</artifactId>
<version>1.14.1-beta</version>
</dependency>
Once I changed that, the project built successfully, and I was able to call the method in question just fine.
There could be something else on the classpath that's interfering. I suggest you run the program with -verbose: class (see here for a more detailed explanation), which will show any conflicts.

Categories

Resources