Resteasy service setup in JBoss 7.2 & Liferay 6.2
sebastian.sommerfeld Mar 24, 2014 6:59 AMHi guys
I'm running into a problem with my Liferay 6.2 and JBoss 7.2. I'm developing a portlet using liferays maven sdk which contains a restful web service (resteasy). But I keep getting the exception java.lang.RuntimeException: Class is not a root resource. It, or one of its interfaces must be annotated with @Path: com.dkv.liferay.services.user.LiferayUserService implements: ... (normal Stacktrace information, no mentioned class is written by me)
.
I'm not doing anything special. Just set up a new project, added dependencies, added a dummy service and changed my web.xml.
Maven dependencies (these dependencies are working fine in another service which is not embedded in a liferay portlet):
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>2.3.4.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>jaxrs-api</artifactId>
<version>2.3.0.GA</version>
<scope>provided</scope>
</dependency>
Service:
@Path("users")
public class LiferayUserService {
@GET
@Path("get")
@Produces(MediaType.TEXT_PLAIN)
public String get() {
return "restful service";
}
}
web.xml:
<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">
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Resteasy -->
<listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<servlet>
<servlet-name>resteasy-servlet</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>resteasy-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>resteasy.resources</param-name>
<param-value>
com.dkv.liferay.services.user.LiferayUserService
</param-value>
</context-param>
</web-app>
The exception indicates I'm missing the @Path annotation, but I'm not. Implementing a subclass of javax.ws.rs.core.Application marked with @ApplicationPath and registering in web.xml is not doing the trick. That way I'm running into ClassNotFoundExceptions. I used "rest" as application path (same as in my servlet-mapping).
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.dkv.liferay.services.RestApplication</param-value>
</init-param>
Exception: java.lang.ClassNotFoundException: com.dkv.liferay.services.RestApplication from [Module "deployment.liferay-Rest-portlet.war:main" from Service Module Loader]
. Is it correct that the param-name is javax.ws.rs.Application but the base Application class is javax.ws.rs.core.Application (package core is not part of the param-name)?
I don't really get it ... My RestApplication class is part of my portlet, so why is the class not found? The war file contains this class as well. Seems pretty strange to me.
Running the service outside of liferay is not an options because I need to access liferays local-service-utils to access special information. Does anybody know a solution to my problem or can give me a hint? I'd really appreciate it ...
Thanks in advance and regards
Sebastian