Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Jersey 3.0.1 no longer defaults to */* consumes #4722

Closed
brettkail-wk opened this issue Feb 15, 2021 · 2 comments · Fixed by #4728
Closed

Jersey 3.0.1 no longer defaults to */* consumes #4722

brettkail-wk opened this issue Feb 15, 2021 · 2 comments · Fixed by #4728
Labels
bug Something isn't working
Milestone

Comments

@brettkail-wk
Copy link

JAX-RS section 3.5 says:

In the absence of either of these annotations, support for any media type (“*/*”) is assumed.

We have applications that run on Java 11, do not declare @Consumes, and have endpoints like this, which rely on a custom media type:

@POST
@Path("/test")
public void test(@Context HttpServletRequest req, @Context HttpServletResponse resp) throws Exception {

This approach was working in Jersey 3.0.0, but as of Jersey 3.0.1, the client now receives HTTP 415:

Exception
2021-02-15 21:31:51,283 DEBUG [http-8082-27] o.g.j.s.ServerRuntime$Responder [ServerRuntime.java:566] [] WebApplicationException (WAE) with no entity thrown and no ExceptionMappers have been found for this WAE. Response with status 415 is directly generated from the WAE.
jakarta.ws.rs.NotSupportedException: HTTP 415 Unsupported Media Type
at org.glassfish.jersey.server.internal.routing.MethodSelectingRouter.getMethodRouter(MethodSelectingRouter.java:412)
at org.glassfish.jersey.server.internal.routing.MethodSelectingRouter.access$000(MethodSelectingRouter.java:73)
at org.glassfish.jersey.server.internal.routing.MethodSelectingRouter$4.apply(MethodSelectingRouter.java:665)
at org.glassfish.jersey.server.internal.routing.MethodSelectingRouter.apply(MethodSelectingRouter.java:305)
at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:86)
at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:89)
at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:89)
at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:89)
at org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:69)
at org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:38)
at org.glassfish.jersey.process.internal.Stages.process(Stages.java:173)
at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:247)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)
at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
at org.glassfish.jersey.internal.Errors.process(Errors.java:244)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:234)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:680)
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:394)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:346)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:366)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:319)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:205)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:761)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:517)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:226)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1355)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:181)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:472)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:179)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1279)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:134)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
at org.eclipse.jetty.server.Server.handle(Server.java:567)
at org.eclipse.jetty.server.HttpChannel.lambda$handle$0(HttpChannel.java:404)
at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:661)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:396)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:289)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:324)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105)
at org.eclipse.jetty.io.SocketChannelEndPoint$1.run(SocketChannelEndPoint.java:106)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:790)
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:912)
at java.base/java.lang.Thread.run(Thread.java:829)

From a brief investigation, it appears that in 3.0.0, the @Consumes("*/*") on XmlRootObjectJaxbProvider was being detected by MethodSelectingRouter, but this is presumably longer happening as of #4634. Our application does not use JAXB at all, but adding explicit jakarta.xml.bind-api and jersey-media-jaxb dependencies works around the issue (this workaround is not really satisfactory, but was done to illustrate the point).

@jansupol jansupol added the bug Something isn't working label Feb 16, 2021
@boris-petrov
Copy link

I hit a similar thing but on 2.33 and with @Produces. Doesn't happen on 2.32.

Either using an explicit @Produces("*/*") or without it (according to the documentation that should do the same) - when a client sends a request with an Accept header of some value (say text/csv) - Jersey returns a 406 instead of using the endpoint marked as producing a wildcard response.

The workaround mentioned in the original post also works in this case.

@jansupol
Copy link
Contributor

jansupol commented Feb 22, 2021

The HTTP status 415 means that there is no MessageBodyReader for media type */* and Object type registered, HTTP status 406 means that there is no MessageBodyWriter for media type */* and Object type.

Until Jersey 3.32/3.0.1 the module jersey-media-jaxb was a mandatory dependency to jersey-core-server. When we made that optional, the JAX-B providers capable of handling */* and Object are no longer on a classpath. For keeping status quo, the jersey-media-jaxb dependency needs to be added.

I agree that when no entity is read or written, the message body provider is not required. That is handled by the fix.

@senivam senivam linked a pull request Feb 22, 2021 that will close this issue
@senivam senivam added this to the 2.34 milestone Feb 25, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants