Java RestFull WebService: JAX-RS implementation with Jersey 2.3.1 libraries - java

I am trying to run a simple "Hallo World" application Jersey 2.3.1 REST service on JBoss jboss-eap-6.1 AS. In web.xml i have disabled restEasy library. During deployment i am getting the error:
JBWEB000289: Servlet
com.sun.jersey.samples.helloworld.resources.MyApplication threw load()
exception: java.lang.NoSuchMethodError:
javax.ws.rs.core.Application.getProperties()Ljava/util/Map;
In POM i put these dependencies:
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
</dependency>
This is my web.xml with restEasy tags disabling:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>com.sun.jersey.samples.helloworld.resources.MyApplication</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.sun.jersey.samples.helloworld.resources.MyApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.providers</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.resources</param-name>
<param-value>false</param-value>
</context-param>
<servlet-mapping>
<servlet-name>com.sun.jersey.samples.helloworld.resources.MyApplication</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
And my resource config java class:
package com.sun.jersey.samples.helloworld.resources;
import org.glassfish.jersey.server.ResourceConfig;
public class MyApplication extends ResourceConfig {
public MyApplication() {
packages("com.sun.jersey.samples.helloworld.resources");
//super(HelloWorldResource.class);
}
}
Someone have any idea to solve it?
thanks in advance,
Roberto

NoSuchMethodError usually means you are having two different versions of the class on your classpath. As the javax.ws.rs.core.Application class does have the getProperties() method in its JAX-RS 2 version, but not in JAX-RS 1.x, I would guess that somehow you are combining the old 1.x Jersey (or old REST api) with the current (2.3.1) one.
Also the package you are working in (com.sun.jersey - the 'old' Jersey package) points a bit towards this direction (although just placing your code into that package itself cannot cause the mentioned problem), you obviously started with the Jersey 1.x example as a base (there are samples in Jersey 2 as well, see helloworld-webapp on Jersey GitHub).
Is it possible, that restEasy (also definitely containing the javax.ws.rs.core.Application class) is not completely switched off and somehow defaults to JAX-RS 1.x version?
I would start with inspecting your pom file, look at the effective pom (if your project descriptor has some parent) and check carefully what is on your classpath - I believe there is a 1.x version of javax.ws.rs-api somewhere. Also try to clean all the compiled stuff and rebuild from scratch.
Speaking of dependencies, if your list is exhaustive (regarding Jersey), you will most likely have to add jersey-common (2.3.1) dependency, as already during the initialization, the ResourceConfig.packages() method calls the PackageScanner constructor, which contains call to ReflectionHelper - and this is not a part of the server jar any more.
Hope this helps.

I faced same problem recently. I thought share my steps for you. As the other answers state, the problem is mainly because of having two different versions of the same class on your classpath. So when you add maven dependencies in your pom be careful.
These kind of problems are normally called as Jar Hell. You can use jhades API for investigate the classes overlap one another. Here is the simple steps i have followed.
Add jhades dependency into your pom.
<dependency>
<groupId>org.jhades</groupId>
<artifactId>jhades</artifactId>
<version>1.0.4</version>
</dependency>
Show the report
Call new JHades().overlappingJarsReport(); in your main method, it will output to stdout.
Sample Output:
file:/Users/justin/.m2/repository/javax/ws/rs/jsr311-api/1.1.1/jsr311-api-1.1.1.jar overlaps with
file:/Users/justin/.m2/repository/javax/ws/rs/javax.ws.rs-api/2.0/javax.ws.rs-api-2.0.jar - total overlapping classes: 55 - same classloader ! This is an ERROR!
Remove one of overlap maven dependency in your pom.
Also you can use another approach like maven's dependency exclusions.
Source: Blog post on jhades
Hope this will help someone :)

Just got this working on JBoss EAP 6.1.1 - Jersey 2.3.1.
The usual things don't seem to work/are not enough on their own:
disabling the jaxrs-subsystem in standalone.xml/domain.xml
or, excluding the jax-rs modules in jboss-deployment-structure.xml
Additionaly you need to disable the loading of the jax-rs 1.1 API completely by modifying module.xml in
jboss-eap-6.1/modules/system/layers/base/javax/ws/rs/api/main/module.xml like this:
<module xmlns="urn:jboss:module:1.1" name="javax.ws.rs.api">
<resources>
<!-- Disable the next line -->
<!-- resource-root path="jboss-jaxrs-api_1.1_spec-1.0.1.Final-redhat-2.jar"/ -->
<!-- Insert resources here -->
</resources>
<dependencies>
<module name="org.jboss.resteasy.resteasy-jaxrs" services="export"/>
</dependencies>
</module>
Please note that this will disable the jax-rs implementation of JBoss (RestEasy) for all other applications as well (as does disabling the jaxrs subsystem in standalone/domain.xml).

This is a Jersey version conflict problem. I had the same problem. Here is how it is resolved:
See your package dependencies "mvn dependency:tree"
If there is a library dependency that depends on an old Jersey version, you could add an exclusions section in the dependency tag for that library in pom.xml

Using mvn dependency:tree (thanks for suggestion above) I was able to identify that the culprit (in my case) was: javax.ws.rs:jsr311-api:1.1
Removing this dependency solved my problem.

Related

Maven cargo during merging web.xml not include all error-page

I trying to merge two war files using maven cargo plugin. The problem is that. I have only one web.xml in one archive. Other archives not include web.xml. So the situation looks like below:
first.war --> with web.xml
second.war --> without web.xml
third.war --> without web.xml
So after merging my merged file uberwar.war file should contain exactly the same web.xml which is included in first.war.
Every tags in merged web.xml are the same instead of error-page. There is only taken first error-page from web.xml. Rest of the error-page tags are skipped. I dont know why. Have someone exeprience with this plugin and could help with issue?? I will be grateful for any help.
1. assemble.xml
<?xml version="1.0"?>
<uberwar>
<wars>
<war>org.vcm.modules:core-web</war>
<war>org.vcm.modules:attributes-web</war>
<war>org.vcm.modules:delivers-web</war>
<war>org.vcm.modules:movies-web</war>
<war>org.vcm.modules:zones-web</war>
<war>org.vcm.modules:opinions-web</war>
<war>org.vcm.modules:payments-web</war>
<war>org.vcm.modules:storages-web</war>
<war>org.vcm.modules:taxes-web</war>
<war>org.vcm.shops:shops-web</war>
</wars>
2. pom.xml
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.7.9</version>
<extensions>true</extensions>
<configuration>
<descriptor>src/assemble/merge.xml</descriptor>
</configuration>
</plugin>
I found cause. The problem was with my web.xml version. I used 3.1 when I change to 2.3 the merging process working correct. It seems the cargo plugin analyze the xml in different way when is newest version.

Eclipse can't find JSF 2.2 taglibs

I am using JSF 2.2 taglibs but Eclipse is displaying the following warning message:
Can't find facelet tag library for uri http://xmlns.jcp.org/jsf
What bugs me is that I've faced this issue before and it was related to classpath JARs, but now it is only affecting JSF 2.2 tag libs.
Taglib xmlns:h="http://xmlns.jcp.org/jsf/html" is working fine, the warning is shown to JSF 2.2 specifics like "/jsf" and "/jsf/passthrough". Here is an image showing warnings for JSF 2.2. tag libs, but prior namespaces are loaded correctly.
I have tried to solve the issue with help of posts like this but none of the procedures (clean, restart, close/open, validate, etc) have worked for me.
Dependencies for JSF (derived from WildFly 10.1 pom.xml):
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.13</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.13.SP1</version>
<scope>provided</scope>
</dependency>
Eclipse info:
Version: Neon.1a Release (4.6.1)
Build id: 20161007-1200
Update
After looking into the taglib files I found no "passthrough" or "friendly markup" reference. So there is no surprise Eclipse won't find it...
There is no file under com.sun.faces.metadata.taglib for Friendly Markup and Passthrough, for both Glassfish and JBoss implementations.
The question now is where should these files be?
Update: opened issue WFLY-9579
It seems that the taglib files are missing from the implementation JARs, for both Glassfish and JBoss projects. I hope to be wrong but I found no other explanation.
I've posted a thread so this behavior can be investigated.
https://developer.jboss.org/thread/274046
Workaround
To stop the IDE from warning simply create empty taglibs files and associate to the web.xml. Files should go under /WEB-INF/ and have the appropriate extension taglib.xml.
The JSF implementation will behave normally and should process the facelets correctly.
friendly_markup.taglib.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<facelet-taglib xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facelettaglibrary_2_2.xsd"
version="2.2">
<namespace>http://xmlns.jcp.org/jsf</namespace>
</facelet-taglib>
passthrough.taglib.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<facelet-taglib xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facelettaglibrary_2_2.xsd"
version="2.2">
<namespace>http://xmlns.jcp.org/jsf/passthrough</namespace>
</facelet-taglib>
web.xml
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/passthrough.taglib.xml;/WEB-INF/friendly_markup.taglib.xml</param-value>
</context-param>
Here is what it looks like. Now the warnings are gone (and my OCD is calm again). I would like to try and make JAR dependency for it, if I find some spare time.

Can a class in one WAR be referenced in web.xml of another WAR in the same EAR, in Wildfly 10?

I have an ear with 2 .war files.
In war #1, under WEB-INF/classes/com/my there is a BatchTriggerBuildServlet.class
In war #2 i have the following in its web.xml (in its WEB-INF)
(a reference to a class in war #1):
<web-app id="WebApp">
<!-- other stuff -->
<servlet>
<servlet-name>BatchTriggerBuildServlet</servlet-name>
<display-name>BatchTriggerBuildServlet</display-name>
<servlet-class>com.my.BatchTriggerBuildServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>BatchTriggerBuildServlet</servlet-name>
<url-pattern>/BatchTriggerBuildServlet</url-pattern>
</servlet-mapping>
<!-- other stuff -->
</web-app>
This is deployed in Wildfly 10.
I also have a jboss-deployment-structure.xml in the META-INF folder of the containing .ear containing the following:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<!-- Make sub deployments NOT isolated by default, so they can see each others classes without a Class-Path entry -->
<ear-subdeployments-isolated>false</ear-subdeployments-isolated>
</jboss-deployment-structure>
Is this legitimate? Because I'm getting a ClassNotFoundException for the above class when i try to deploy the ear, along with the message that it
"Failed to start service ... from [Module "<my ear name>.<my war #2 name>:main" from Service Module Loader]"
Is there a way to get this to work?
thanks in advance.
ear-subdeployments-isolated does not apply to web modules, which are always isolated from each other. See Class Loading in WildFly.
Try moving the classes and their dependencies into a jar in the EAR/lib directory.

java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet in spring project

one hello.jsp
web.xml is
<?xml version="1.0" encoding="UTF-8"?>
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- The front controller of this Spring Web application, responsible for
handling all application requests -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map all requests to the DispatcherServlet for handling -->
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
dispatcher-servlet.xml is
<?xml version="1.0" encoding="UTF-8"?>
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
xmlns:p="http://www.springframework.org/schema/p">
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean name="/hello.html" class="com.spring.HelloWorldController"></bean>
</beans>
JAR Files are:
spring.jar
spring-webmvc.jar
spring-aop
spring-beans
spring-context
spring-context-support
spring-core
spring-jdbc
spring-orm
spring-source
spring-test
spring-tx
The ClassNotFoundException clearly indicates that you are missing org.springframework.web.servlet classes.
If you are not using Maven, make sure you include all the appropriate Spring JARs.
If you are using Maven, make sure you include the spring-web dependency:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version><!-- Your spring version here --></version>
</dependency>
If none of these work, take a look at this thread.
In my case I used Ivy and I faced the same issue. You can do either of the two
Either move your libraries to WEB-INF/lib . Because this is the
folder from where Eclipse searches for corresponding jars. OR
Let Eclipse know that it can search the jars from ivy library folder
which is not same as WEB-INF/lib i.e Change java build path in Deployment Assembly via Project properties.
For 2nd approach you can refer details post with screenshots (Link to my personal blog with more detials). Or you can also go through similar question I asked here.
Problem:
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet in spring project
The issue is necessary jar are not present in the proper classpath
Solution
Place all the necessary jars in the classpath .Since the project is dynamic webproject place all the spring jars in the WEB-INF/Lib folder
The issue will be resloved
I had a similar issue and I resolved it this way. If all the required libraries are added and you are still getting this error. Try running this in command line:
mvn eclipse:eclipse
then
mvn clean install
If this doesn't resolve it, rightclick on your eclipse project,
go to >>properties >> targeted runtime
then click the checkbox next to
apache tomcat v8.0
depending on the version of you tomcat.
If you are running jboss, choose a jboss version instead.
and then after this run the above 2 commands(mvn eclipse:eclipse and mvn clean install) again.
Problem: java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet in spring project.
By adding the below jars into WEB-INF/Lib folder we can resolve this issue.
org.springframework.asm-3.1.4.RELEASE.jar
org.springframework.aspects-3.1.4.RELEASE.jar
org.springframework.beans-3.1.4.RELEASE.jar
org.springframework.context-3.1.4.RELEASE.jar
org.springframework.context.support-3.1.4.RELEASE.jar
org.springframework.core-3.1.4.RELEASE.jar
org.springframework.web.struts-3.1.4.RELEASE.jar
org.springframework.web.servlet-3.1.4.RELEASE.jar
org.springframework.web-3.1.4.RELEASE.jar
Of Course you will be added in Build Path but it will take up to Compile time only. So we have to added above jars into WEB-INF/Lib folder

JBoss AS 7.1.1 not picking up my JSF implementation

When I deploy my .war file in JBoss AS 7.1.1 and call
FacesContext.class.getPackage().getImplementationTitle()
and
FacesContext.class.getPackage().getImplementationVersion()
I get a different version then when I deploy it on tomcat.
JBoss: JSF JavaServer Faces API 2.0.1.Final
Tomcat: JSF Mojarra 2.0.6-FCS
It seems JBoss is not picking the correct JARs that I have in my WEB-INF\lib\.
This causes different behaviour in my website.
I tried to solve the problem with
<context-param>
<param-name>org.jboss.jbossfaces.WAR_BUNDLES_JSF_IMPL</param-name>
<param-value>true</param-value>
</context-param>
But that didn't work. I read Alternative JSF implementation with JBoss 71 but apparently it is not solved in 7.1.1.
I added jboss-deployment-structure.xml to WEB-INF\ with the following content.
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="javax.faces.api" slot="main"/>
<module name="com.sun.jsf-impl" slot="main"/>
</exclusions>
<dependencies>
<module name="org.apache.commons.logging" />
<module name="org.apache.commons.collections" />
<module name="org.apache.log4j" />
<module name="org.dom4j" />
<module name="javax.faces.api" slot="1.2"/>
<module name="com.sun.jsf-impl" slot="1.2"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
But then my app is not deployed and I get the following errors in server.log:
14:06:14,733 SEVERE [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-4) Critical error during deployment: : com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! Class org.jboss.as.web.deployment.jsf.JandexAnnotationProvider is not an instance of com.sun.faces.spi.AnnotationProvider
at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:357) [jsf-impl.jar:2.0.6-FCS]
How can I solve my problem?
Could there be something else that depends on the JSF API? I'm not sure why it would be different between JBoss and Tomcat, but try running mvn dependency:tree and mvn dependency:analyze with and without the JSF excluded.
JBoss AS 7.1.1 is by default with JSF 2, but is backward compatible with JSF 1.2.
I had the same issue and solved it as follow: I used the same jboss-deployment-structure.xml as you and added the following parameter in the web.xml:
<context-param>
<param-name>org.jboss.jbossfaces.JSF_CONFIG_NAME</param-name>
<param-value>Mojarra-1.2</param-value>
</context-param>
You don't need the JSF 1.2 JARs in the lib directory (and thus the org.jboss.jbossfaces.WAR_BUNDLES_JSF_IMPL parameter is not needed in web.xml).
Source: http://tapas-tanmoy-bose.blogspot.ch/2014/01/how-to-run-jsf-12-application-in-jboss.html
I suspect JBoss AS 7.1.1 to ignore the excluded modules of jboss-deployment-structure.xml for JSF (but I have org.hibernate as another excluded module which is effectively excluded, proving that the jboss-deployment-structure.xml is taken into account).

Categories