1 Reply Latest reply on Mar 25, 2014 5:22 AM by Sebastian Sommerfeld

    Resteasy service setup in JBoss 7.2 & Liferay 6.2

    Sebastian Sommerfeld Newbie

      Hi 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

        • 1. Re: Resteasy service setup in JBoss 7.2 & Liferay 6.2
          Sebastian Sommerfeld Newbie

          Found something about the Application init-param. (http://docs.jboss.org/resteasy/docs/1.0.0.GA/userguide/html/Installation_Configuration.html). Above param-name is not corrent. Must look like this:

          <init-param>

              <param-name>javax.ws.rs.core.Application</param-name>

              <param-value>com.dkv.liferay.services.RestApplication</param-value>

          </init-param>

           

          But now I'm getting an error that's even more strange to me:

          java.lang.ClassCastException: com.dkv.liferay.services.RestApplication cannot be cast to javax.ws.rs.core.Application

          org.jboss.resteasy.spi.ResteasyDeployment.createApplication(ResteasyDeployment.java:267)

          org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:228)

          org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.init(ServletContainerDispatcher.java:67)

          org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.init(HttpServletDispatcher.java:36)

          org.jboss.modcluster.container.jbossweb.JBossWebContext$RequestListenerValve.event(JBossWebContext.java:67)

          org.jboss.modcluster.container.jbossweb.JBossWebContext$RequestListenerValve.invoke(JBossWebContext.java:48)

          org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169)

          org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97)

          org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:336)

          org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)

          org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653)

          org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:920)

          java.lang.Thread.run(Thread.java:662)

           

          My Class looks like this:

          package com.dkv.liferay.services;

           

          import javax.ws.rs.ApplicationPath;

          import javax.ws.rs.core.Application;

           

          @ApplicationPath("rest")

          public class RestApplication extends Application {

           

              public RestApplication() {

                  super();

              }

          }

           

          It's correctly extending Application, so why is the cast failing?

           

          Thanks again guys. Sebastian