1
votes

I attempt to deploy a very simple RESTful Web Service using Jersey 1.18 within Tomee 1.5.2 WebProfile. My project is fully inspired from the tomee-jersey-eclipselink

example that I further simplified by removing the persistence part: the Web Service simply retuns "Hello, World!"

@Path("/hello")
@RequestScoped
public class HelloService {

    public HelloService() {
    }

    @GET
    public String test() {
        return "Hello, World!";
    }
}

My dependencies in my POM:

<dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.18</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-servlet</artifactId>
        <version>1.18</version>
    </dependency>
</dependencies>

I deploy my Web Service with the agnostic Application model:

import javax.ws.rs.core.Application;
import java.util.HashSet;
import java.util.Set;

public class JerseyApplication extends Application {

    @Override
    public Set<Class<?>> getClasses() {
        final Set<Class<?>> classes = new HashSet<Class<?>>();
        classes.add(HelloService.class);
        return classes;
    }
}

And here is my web.xml:

<web-app>
  <servlet>
    <servlet-name>Jersey Web Application</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>javax.ws.rs.Application</param-name>
      <param-value>org.superbiz.service.JerseyApplication</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Jersey Web Application</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
</web-app>

I also added the following property in $TOMEE/conf/system.properties:

com.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager=true

Everything works fine with Tomcat 7 (In this case, I replace the javax:javaee-api dependency by javax.enterprise:cdi-api:1.1 in the POM), but when I try with Tomee, I just get a 404 HTTP status, with no exception and no additional logging message.

The result is the same whenever I deploy the application from my Eclipse IDE or with Maven in command line.

Note:

  • I do not want to use Tomee JAX-RS with Apache CXF, and I cannot upgrade to Tomee 1.6.
  • I already tried all possible ways from this post, that did not help.

Any idea ?

1
Do you see some Jersey logs (i.e. during deployment)?Michal Gajdos
Actually no, I see no log statement related to Jersey. I suspect that javaee-api is the source of all my problems (I tried to reorder the listing of my dependencies in my POM to reorder the class loading). This minimalistic project is supposed to help me to reproduce and understand this bug in a larger project that fully uses JEE features such as CDI, JSF, etc.: so, I cannot do without the dependency to javaee-api. Do you know a Jersey class where I can put a relevant breakpoint and to see what is going on. Subsidiary question: what is the jersey-cdi artifact? Can it be useful for me?Pascal GILLET
Another precision: my web.xml contains nothing but the servlet mapping listed above. Yet another precision: in the real project, I can see that my provider and resources classes are well loaded by Jersey (I use a PackagesResourceConfig here). Thanks for your reply.Pascal GILLET

1 Answers

2
votes

There was an issue resolved in TomEE 1.7.0 that fixed this problem. As the issue notes, you also need to add the following line to your catalina.properties:

openejb.classloader.forced-load=javax.ws.rs

This worked for me with Jersey 2.