jersey icon indicating copy to clipboard operation
jersey copied to clipboard

JettyHttpContainer URL handling broken

Open glassfishrobot opened this issue 9 years ago • 4 comments

I'm creating a JAX-RS server using the jetty http container. The resource is annotated with @Path("/services") and the whole JAX-RS handler is put under context "/my/path" (see code snippet below for details)

So an HTTP GET on server:port/my/path/service should end up in my rest resource. However, it does not on 2.22.2.

After stepping through the code, it seems that the JettyHttpContainer.handle constructs a wrong requestUri:"http://localhost:52021/my/path/my/path/services" (notice the duplication of /my/path)

It is related to fixed done in scope of https://github.com/jersey/jersey/commit/239d02fcc0792155eb5aaf51e5c2b68e61203c19#diff-1997febdf388bca1dd941929123602df

I have reverted back to 2.21.1, which works fine.

ContextHandler context = new ContextHandler();
        final Handler endpoint = RuntimeDelegate.getInstance().createEndpoint(application, Handler.class);

        context.setHandler(endpoint);
        context.setContextPath("/my/path");

Affected Versions

[2.22.2]

glassfishrobot avatar Mar 01 '16 14:03 glassfishrobot

Reported by janssk1

glassfishrobot avatar Mar 01 '16 14:03 glassfishrobot

fholmqvist said: Seeing the same with an EmbeddedJetty:

ContextHandler appContext = new ContextHandler("/path");
        appContext.setHandler(new HttpContainer(app));
        contexts.setHandlers(new Handler[] { rootContext, appContext });
        server.setHandler(contexts);

Any request to /path/resource will become /path/path/resource in JettyHttpContainer by getBaseURI() and getRequestURI()

glassfishrobot avatar May 23 '16 08:05 glassfishrobot

This issue was imported from java.net JIRA JERSEY-3066

glassfishrobot avatar Apr 25 '17 05:04 glassfishrobot

As a workaround, if you're willing to use jetty-servlet, you can use:

ServletContextHandler servletContextHandler = new ServletContextHandler(null, "/path");
servletContextHandler.addServlet(new ServletHolder(new ServletContainer(config)), "/*");
server.setHandler(servletContextHandler);

brettkail-wk avatar Mar 23 '18 12:03 brettkail-wk