JettyHttpContainer URL handling broken
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]
Reported by janssk1
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()
This issue was imported from java.net JIRA JERSEY-3066
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);