users@jersey.java.net

Re: [Jersey] 0.6 -> 0.7 problem with jetty

From: Lars Tackmann <lars_at_randompage.org>
Date: Tue, 3 Jun 2008 17:34:00 +0200

On Tue, Jun 3, 2008 at 4:46 PM, Jean Aurambault <aurambaj_at_yahoo-inc.com> wrote:
> Hi,
>
> I've the following error when running unit tests (I've just updated to
> jersey 0.7). I suppose there is a problem with jetty configuration but I
> don't know where to start... Any idea?

I have the exact same problem. For me it seams to be some sort of
strange problem involving unit testing, Jersey and jetty.
The problem can be reproduced by rewriting the Jersey Jetty example
into somthing like this:

----
package jetty;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.ServletHolder;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.sun.ws.rest.api.client.Client;
import com.sun.ws.rest.api.client.WebResource;
import com.sun.ws.rest.spi.container.servlet.ServletContainer;
public class JettyTest {
	private static Server server;
	@Path("/")
	public static class TestResource {
		@GET
		public String get() {
			return "GET";
		}
	}
	@BeforeClass
	public static void setUp() throws Exception {
		ServletHolder sh = new ServletHolder(ServletContainer.class);
		sh.setInitParameter(
				"com.sun.ws.rest.config.property.resourceConfigClass",
				"com.sun.ws.rest.api.core.PackagesResourceConfig");
		sh.setInitParameter("com.sun.ws.rest.config.property.packages",
				"jetty");
		server = new Server(9999);
		Context context = new Context(server, "/", Context.SESSIONS);
		context.addServlet(sh, "/*");
		server.start();
	}
	@AfterClass
	public static void tearDown() throws Exception {
		if (server != null)
			server.stop();
	}
	@Test
	public void simpleTest() {
		Client c = Client.create();
		WebResource r = c.resource("http://localhost:9999/");
		assert r.get(String.class).equals("GET");
	}
}
----
I will look into it tomorrow after work.
-- 
Yours sincerely
Lars Tackmann