Uploaded image for project: 'JBoss Enterprise Application Platform'
  1. JBoss Enterprise Application Platform
  2. 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.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 7.1.0.DR13
    • 7.1.0.DR5
    • REST
    • None
    • Hide

      git clone https://github.com/resteasy/Resteasy.git
      git checkout -b 3.0
      cd testsuite
      mvn clean verify -Dserver.home=SERVER_PATH -Dtest=SpringMvcHttpResponseCodesTest -Dmaven.test.redirectTestOutputToFile=false -fn -Denable.expected.failing

      Show
      git clone https://github.com/resteasy/Resteasy.git git checkout -b 3.0 cd testsuite mvn clean verify -Dserver.home=SERVER_PATH -Dtest=SpringMvcHttpResponseCodesTest -Dmaven.test.redirectTestOutputToFile=false -fn -Denable.expected.failing

      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&gt;org.springframework.web.context.ContextLoaderListener</listener-class&gt;
      </listener>
      
      <servlet>
              <servlet-name>mvc-dispatcher</servlet-name>
              <servlet-class&gt;org.springframework.web.servlet.DispatcherServlet</servlet-class&gt;
              <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.

              rhn-support-asoldano Alessio Soldano
              kanovotn Katerina Odabasi
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: