-
Bug
-
Resolution: Done
-
Major
-
3.1.0.Beta2
-
None
-
None
Application with spring mvc dispatcher configured doesn't return correct http response codes to the client. The response codes not being correctly returned are:
- Not Acceptable (406)
- Not Allowed (405)
- NotSupported (415)
- Forbidden (403 or 404)
The issue was first reported here - http://lists.jboss.org/pipermail/resteasy/2016-September/000011.html
Example of incorrect http response code returned NotAcceptableException:
web.xml:
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>mvc-dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet>
Attached application resource doesn't support sending response of Media type json. Client sends request:
Response response = authorizedClient.target(testPath)).request() .accept(MediaType.APPLICATION_JSON_TYPE).get();
Actual http response code send by server to the client is 500 instead of 406 (NotAcceptable), while server internally raises the correct exception:
12:20:01,444 ERROR [io.undertow.request] (default task-2) UT005023: Exception handling request to /SpringMvcHttpResponseCodesTest/test: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is javax.ws.rs.NotAcceptableException: RESTEASY003635: No match for accept header at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:980) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:859) ... Caused by: javax.ws.rs.NotAcceptableException: RESTEASY003635: No match for accept header at org.jboss.resteasy.core.registry.SegmentNode.match(SegmentNode.java:389) at org.jboss.resteasy.core.registry.SegmentNode.match(SegmentNode.java:121) at org.jboss.resteasy.core.registry.RootNode.match(RootNode.java:43) at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48) at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:445) at org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousDispatcher.java:264) at org.jboss.resteasy.springmvc.ResteasyHandlerMapping.getInvoker(ResteasyHandlerMapping.java:108) at org.jboss.resteasy.springmvc.ResteasyHandlerMapping.getHandler(ResteasyHandlerMapping.java:84) at org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1120) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:932) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:968) ... 43 more
See attached reproducer (org.jboss.resteasy.test.spring.inmodule.SpringMvcHttpResponseCodesTest) for examples of other http response codes.
- is cloned by
-
JBEAP-6179 Application using spring mvc-dispatcher servlet doesn't return correct http response codes from server to the client for various client request exceptions.
- Closed