Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-24

WebApplicationException and http status codes

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • Beta2
    • Beta1
    • jaxrs
    • None

      Hello,

      A couple of days ago I ran into a problem with throwing WebApplication examples with a response object:

      throw new WebApplicationException(Response.status(412)
      .type("text/plain;charset=utf-8")
      .entity("Something went wrong").build());

      Throwing this exception would give a text/plain body with the entity body but with http code 200. Throwing the same exception without an entity would give the expected (412 response with an empty body).

      After a little code browsing I found the problem in Dispatcher.java invoke method. I created a patch file from revision 133 attached to this email.

      Regards,

      Thomas Cremers

      Index: Dispatcher.java
      ===================================================================
      — Dispatcher.java (revision 135)
      +++ Dispatcher.java (working copy)
      @@ -136,6 +136,7 @@

      if (jaxrsResponse.getEntity() != null)

      { + response.setStatus(jaxrsResponse.getStatus()); MediaType responseContentType = resolveContentType(invoker, in, jaxrsResponse); writeResponse(response, invoker, jaxrsResponse.getEntity(), responseContentType); }

              patriot1burke@gmail.com Bill Burke (Inactive)
              patriot1burke@gmail.com Bill Burke (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: