users@jersey.java.net

[Jersey] Re: Problems migrating from jersey 1.18 to jersey 2.12

From: Consultant <emma.wermstrom_at_consultant.volvo.com>
Date: Thu, 4 Sep 2014 14:03:57 +0000

Very good question.

Whenever I try a GET request to the rest web service (using a client or browser) I get HTTP 404 Not found. This does not happen in the jersey 1.x case.

I’m also using eclipse. I’m not using maven.

Best regards,
Emma

From: Gili T. [mailto:cowwoc_at_bbs.darktech.org]
Sent: den 4 september 2014 3:54
To: users_at_jersey.java.net
Subject: [Jersey] Re: Problems migrating from jersey 1.18 to jersey 2.12


What is actually not working? What errors do you get?

Gili
On Sep 4, 2014 9:10 AM, "Wermström Emma (Consultant)" <emma.wermstrom_at_consultant.volvo.com<mailto:emma.wermstrom_at_consultant.volvo.com>> wrote:
Hi!

Recently I've been trying to setup a restful web service using jetty and jersey following the tutorial found here: http://jlunaquiroga.blogspot.se/2014/01/restful-web-services-with-jetty-and.html
I've only implemented the XML web service.

I had no problems implementing this using Jersey 1.x (jersey-bundle 1.18). But I can't migrate to the latest jersey 2.x (jersey 2.12).
So should I migrate at all, or just stick with jersey 1.x? I would like to know why the restful web service does not work with jersey 2.12.

I'm using jetty 9.2.0.RC0 and JavaSE-1.7 in both cases.

Server code using Jersey 1.18:
package examplejersey1.server;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;

import com.sun.jersey.spi.container.servlet.ServletContainer;

public class MinimalServerRest {
                             public static void main(String[] args) throws Exception {
                                  ServletHolder sh = new ServletHolder(ServletContainer.class);
                                  sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
                                  sh.setInitParameter("com.sun.jersey.config.property.packages", "rest");//Set the package where the services reside
                                  sh.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");

                                  Server server = new Server(9999);

                                  ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
                                  context.addServlet(sh, "/*");
                                  server.start();
                                  server.join();
                             }
}

Server code using Jersey 2.12:
package examplejersey2.server;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;

public class MinimalServerRest {
                             public static void main(String[] args) throws Exception {

                                  Server server = new Server(9999);
                                  ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
                                  ServletHolder jerseyServlet = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/*");
                                  jerseyServlet.setInitOrder(1);
                                  jerseyServlet.setInitParameter("jersey.config.server.provider.packages","rest");
                                  context.setContextPath("/");
                                  context.setServer(server);

                                  server.start();
                                  server.join();
                              }
}


The server provider package “rest” is identical in both cases. The clients are a little different but that doesn't seem to be the problem. I doesn't work using a simple browser either in the Jersey 2.x case.

Notable is that for the case using jersey 1.x I have included the following jars in my java project:
     +- file:/C:/Users/xxx/workplace/example/lib/jetty-all-9.2.0.RC0.jar
     +- file:/C:/Users/xxx/workplace/example/lib/javax.servlet-api-3.1.0.jar
     +- file:/C:/Users/xxx/workplace/example/lib/jersey-bundle-1.18.jar
     +- file:/C:/Users/xxx/workplace/example/lib/asm-3.1.jar
For the case using jersey 2.x I have included the following jars in my java project:
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/aopalliance-repackaged-2.3.0-b05.jar
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/asm-debug-all-5.0.2.jar
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/eclipselink.jar
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/guava-18.0.jar
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/hk2-api-2.3.0-b05.jar
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/hk2-locator-2.3.0-b05.jar
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/hk2-utils-2.3.0-b05.jar
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/javassist-3.18.1-GA.jar
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/javax.annotation-api-1.2.jar
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/javax.inject-2.3.0-b05.jar
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/javax.servlet-api-3.1.0.jar
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/javax.ws.rs-api-2.0.jar
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/jaxb-api-2.2.7.jar
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/jersey-client.jar
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/jersey-common.jar
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/jersey-container-servlet.jar
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/jersey-container-servlet-core.jar
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/jersey-entity-filtering-2.12.jar
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/jersey-guava-2.11.jar
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/jersey-media-moxy-2.12.jar
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/jersey-server.jar
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/jetty-all-9.2.0.RC0.jar
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/org.osgi.core-4.2.0.jar
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/osgi-resource-locator-1.0.1.jar
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/persistence-api-1.0.jar
     +- file:/C:/Users/xxx/workplace/examplejersey2/lib/validation-api-1.1.0.Final.jar

Thanks for your support!
Best regards,
Emma