(@Context HttpServletResponse answer not working in resteasy

Web application with resteasy infrastructure.

@Path("/do3")
@GET
public void response(@Context HttpServletResponse response) throws IOException{ 
    response.setStatus(202);

}

why get / do3 return 204, not 202? Thanks in advance.

PS: (1) I switch to the @post method. he also cannot get the expected code: 202 by get. (2) response.addHeader ("key", "value"); may work fine.

+5
source share
1 answer

RESTEasy interprets your method as best as possible - you did not specify a return type so that it returns 204 (without content) back to the client. The void method GETreally doesn't make much sense and should be avoided or converted to another HTTP verb (like POST).

, JAX-RS. ResponseBuilder.

Response.status(202).build();

, , HttpServletResponse , :

response.setHeader("Location", "http://www.example.com/myresource/5");
+6

All Articles