Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] Problems with embedded jetty, eclipse and jersey 1.18

Hi,

 

I have created an eclipse plugin which uses the org.eclipse.ui to start an eclipse platform with an additional menu from where I can start an embedded jetty server. The plugin is run as an “Eclipse Application”. So far so good. I have no problems running the server and accessing data from the new eclipse platform workspace (which is the whole idea of this plugin).

 

I’m using:

Jetty 9.2.0.RC0

JavaSE-1.7

eclipselabs-automotive-target-kepler4.3

 

Now I want to create a RESTful web service using my embedded jetty server. I decided to use the Jersey framework selecting Jersey-bundle-1.18 and javax.server-api-3.1.0.

 

This is my embedded jetty server:

******************************************************

package org.eclipse.eatop.jetty.helloworld.handlers;

 

import javax.ws.rs.GET;

import javax.ws.rs.Path;

import javax.ws.rs.Produces;

import javax.ws.rs.core.MediaType;

 

import org.eclipse.core.commands.AbstractHandler;

import org.eclipse.core.commands.ExecutionEvent;

import org.eclipse.core.commands.ExecutionException;

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 HelloWorldHandler extends AbstractHandler {

                             public HelloWorldHandler() {

                             }

                            

                             /**

                             * the command has been executed, so extract extract the needed information

                             * from the application context.

                             */

                             public Object execute(ExecutionEvent event) throws ExecutionException {

                                                         

                             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", "org.eclipse.eatop.jetty.helloworld.rest");//Set the package where the services reside        

                                  sh.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");               

                                  Server server = new Server(8080);        

                                  ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);

                                  context.addServlet(sh, "/*");        

                                                           try {

                                                                                                                    server.start();

                                                                                                                    server.dumpStdErr();

                                                          } catch (Exception e) {

                                                                                                                    System.out.println("Unable to start jetty web server");

                                                                                                                                                 // TODO Auto-generated catch block

                                                                                                                    e.printStackTrace();

                                                          }

                                                         

                             return null;

                             }

******************************************************

This is my root resource package:

******************************************************

package org.eclipse.eatop.jetty.helloworld.rest;

 

import javax.ws.rs.GET;

import javax.ws.rs.Path;

import javax.ws.rs.Produces;

import javax.ws.rs.core.MediaType;

 

 

@Path("/xmlServices")

public class XMLProjectService {

                               @GET    

                               @Produces(MediaType.TEXT_PLAIN)    

                               public String getProject()

                               {        

                                                            return "hello world" ;    

                               }

}

******************************************************

 

This happens when I try to access my restful web service using an IE browser:

Sep 05, 2014 1:55:22 PM com.sun.jersey.api.core.PackagesResourceConfig init

INFO: Scanning for root resource and provider classes in the packages:

  org.eclipse.eatop.jetty.helloworld.rest

Sep 05, 2014 1:55:24 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate

INFO: Initiating Jersey application, version 'Jersey: 1.18 11/22/2013 03:05 AM'

Sep 05, 2014 1:55:24 PM com.sun.jersey.server.impl.application.RootResourceUriRules <init>

SEVERE: The ResourceConfig instance does not contain any root resource classes.

2014-09-05 13:55:24.974:WARN:/:qtp999796-43: unavailable

com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.

            at com.sun.jersey.server.impl.application.RootResourceUriRules.<init>(RootResourceUriRules.java:99)

            at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1359)

            at java.lang.Thread.run(Unknown Source)

 

Now, the reason for this may one of the following two:

1)      The root resource package is incorrectly formatted (for example missing @Path annotation)

2)      The root resource package is not located where it’s supposed to be

 

I have come to the conclusion that it must be the second reason causing this problem. My guess is that jersey simply cannot find the designated area where my root resource classes can be found. Does this have anything to do with the fact that I’m running the web service embedded into my eclipse plugin (starting the web service from the new platform)?

 

How can I expose the root resource package to jersey from my embedded jetty restful web service plugin?

 

I have no problems running this example when I’m embedding the jetty server into a simple java application. It just doesn’t work running it from inside an eclipse application.

 

Best regards,

 

Emma


Back to the top