|
From: Gregor J. <gr...@ja...> - 2013-05-29 09:12:52
|
Hi, Looking at the code of resteasy - I figured out how the http status can be set. In a ContainerResponseFilter the method filter has a ContainerResponseContext as on of its params. At first I tried to set the status via setStatus() and getHttpResponse().setStatus - both don't work since resteasy overrides it at a later time. The solution I found is to override the http code of the JaxrsResponse (getJaxrsResponse().setStatus()) with the http code from the HttpResponse. This is in fact the status resteasy going to use for overriding. Although this does work - I think it would be nice if resteasy could do this for us in general. Looking at the method org.jboss.resteasy.core.ServerResponseWriter#writeNomapResponse there could be a check whether the HttpResponse is anything else then 200 (or if it has been manually set [could be remembered in the HttpServletResponseWrapper]). If so, resteasy should not override this value. My suggestion includes the assumption that if the http code is different then 200 it was set by the developer (in one of the rest methods). Is there a scenario I am missing here or any other reason why this is not a good idea? - Gregor ----- Forwarded Message ----- From: "Gregor Jarisch" <gr...@ja...> To: res...@li... Sent: Tuesday, May 28, 2013 3:13:32 PM Subject: [Resteasy-developers] Setting the response http code Hi there, something that is bugging me for quite some time since using resteasy is setting the http code in the response. In my scenario I would like to create a resource by invoking a POST request. After creating the resource I would like to return a 201 (created) to the client as well as a Location URI pointing to the newly created resource. I set the 201 by injecting the HttpResponse. Unfortunately, resteasy ignores my set value an puts a 204 (No Content) instead, since the POST method's return type is void. Back in 2.3.* I was able to achieve this by overriding the value set by resteasy in a PostProcessInterceptor. Since this is deprecated now - what other options do I have? I am aware that I could build the Response object and return it - but this is not a clean interface definition in my opinion, since one couldn't see what's coming back only by looking at the return value of the interface. Is there any way to set the http code without returning the Response object? Thanks, Gregor -- Ing. Gregor Jarisch entrepreneurship & development ------------------------------------------------------------------------------ Try New Relic Now & We'll Send You this Cool Shirt New Relic is the only SaaS-based application performance monitoring service that delivers powerful full stack analytics. Optimize and monitor your browser, app, & servers with just a few lines of code. Try New Relic and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may _______________________________________________ Resteasy-developers mailing list Res...@li... https://lists.sourceforge.net/lists/listinfo/resteasy-developers |