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 18:05:01 +0200

On Tue, Jun 3, 2008 at 5:52 PM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:
> I wonder if it is my fault. This is the rather embarrassing piece of code:
>
> public BaseRule(UriTemplate template) {
> assert template != template; <- !!!!!!!!!!!!
>
> this.template = template;
> }
>
> Find bugs spotted it, but i did not spot that find bugs did until after 0.7
> was released. However, it seemed to be benign and did not result in any
> failures to unit tests or running the examples, otherwise i would have
> noticed and fixed it immediately.

Indeed it is fixed in the latest maven pom snapshot, which can be
obatined by adding the following lines to pom.xml

--
<repository>
        <id>java.net</id>
	<url>http://download.java.net/maven/2</url>
</repository>
and
<dependency>
	<groupId>com.sun.jersey</groupId>
	<artifactId>jersey</artifactId>
	<version>0.8-ea-SNAPSHOT</version>
</dependency>
--
The unit test below now works (note this will not work on 0.7 or
earlier due to the package name changes):
----
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.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.spi.container.servlet.ServletContainer;
public class JettyTest {
	private static Server server;
	@Path("/")
	public static class TestResource {
		@GET
		public String get() {
			return "GET";
		}
	}
	@BeforeClass
	public void setUp() 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", "jetty");
		server = new Server(9999);
		Context context = new Context(server, "/", Context.SESSIONS);
		context.addServlet(sh, "/*");
		server.start();
	}
	@AfterClass
	public 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");
	}
}
----
Thanks for helping out with this.
-- 
Yours sincerely
Lars Tackmann