Embedded Tomcat and jersey

1k Views Asked by At

I am trying to deploy an embedded tomcat server and implement some jersey web services. I managing to run the server correctly and access any other servlet except the ones handled by jersey. When I am trying to access the jersey services through the web browser I am getting the following error

Dec 02, 2014 6:21:41 PM org.apache.coyote.http11.AbstractHttp11Processor process
SEVERE: Error processing request
java.lang.NoSuchMethodError: javax.servlet.ServletContext.getEffectiveSessionTrackingModes()Ljava/util/Set;
    at org.apache.catalina.connector.CoyoteAdapter.postParseRequest(CoyoteAdapter.java:675)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:403)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)

Due to the initialization of the application the following is printed, indicating that jersey container has load correctly the servlets

Dec 02, 2014 6:21:11 PM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
    controllerModule.servlet
Dec 02, 2014 6:21:11 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
    class controllerModule.servlet.HelloWorldService
Dec 02, 2014 6:21:11 PM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
Dec 02, 2014 6:21:11 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.18.1 02/19/2014 03:28 AM'

The code I am using to register the resources is the following

Wrapper a = Tomcat.addServlet(rootCtx, "rest", "com.sun.jersey.spi.container.servlet.ServletContainer");
a.addInitParameter("com.sun.jersey.config.property.packages","controllerModule.servlet");
a.setLoadOnStartup(1);
rootCtx.addServletMapping("/*", "rest");

Some things to take in mind
- The HelloWorldService is the common testing servlet found in most Jersey tutorials
- It is essential to use jersey 1.18.x and tomcat, any other suggestion is acceptable but I cannot consider it as a solution, at least for the time being. I have seen many tutorials with alternatives e.g greater jersey version, using jetty, http-jersey-server etc

Update 03.12.2014

It seems like the problem was a dependency on my pom.xml file

I was using:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
</dependency>

Which I had to change to:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.0.1</version>
</dependency>

Strangely that way the jersey Servlets works but not the other servlet I have, which extend HttpServlet class

0

There are 0 best solutions below