From: Gregor J. <gr...@ja...> - 2013-05-30 13:37:23
|
On the other hand, adding the entity to the response might not fit all use cases. Especially when it comes to browsers and caching - as far as I know - they won't cache POST responds (due to spec). -------- Original Message -------- Subject: Re: [Resteasy-developers] Fwd: Setting the response http code Date: Thu, 30 May 2013 15:33:10 +0200 From: Gregor Jarisch <gr...@ja...> To: res...@li... Good idea and fits my use case, thanks for the input. But the problem is not whether to send the created resource back, but on how to set 201 and the Location header the best way. On 29.05.2013 18:53, Geyer, Randy wrote: > Why not define your Rest response to return the created Resource along > with the 201 and location header? Saves a client round trip to retrieve > the resource and simplifies your API. > > WDYT? - rg > > On 5/29/13 10:16 AM, "Bill Burke" <bb...@re...> wrote: > >> Well, if you are returning a 201, most clients will be expecting a >> Location header in the response with a URI pointing to the new resource >> you created. Especially for POST requests. >> >> i.e. >> >> POST /customers >> Content-Type: application/xml >> >> <customer.../> >> >> response >> >> 201 Created >> Location: /customers/1234 >> >> >> >> On 5/29/2013 10:54 AM, Gregor Jarisch wrote: >>> I am aware of this possibility - I am trying to prevent it though. >>> The reason for this is, I want my interface definitions to be readable >>> without having to look into the implementation. >>> Having the Response Object as a return type won't tell me what I can >>> expect as a return value when developing the client side. >>> This is the reason why I prefer returning the concrete objects which >>> will end up in the response body. >>> Nevertheless, doing so doesn't allow me to set the http code... >>> >>> >>> ----- Original Message ----- >>> From: "Bill Burke" <bb...@re...> >>> To: res...@li... >>> Sent: Wednesday, May 29, 2013 4:36:08 PM >>> Subject: Re: [Resteasy-developers] Fwd: Setting the response http code >>> >>> Send a javax.ws.rs.core.Response back? >>> >>> On 5/29/2013 10:18 AM, Gregor Jarisch wrote: >>>> Well, having the use case that I want a client to know that a resource >>>> was successfully created (201) - how can I achieve this instead? >>>> >>>> ----- Original Message ----- >>>> From: "Bill Burke" <bb...@re...> >>>> To: res...@li... >>>> Sent: Wednesday, May 29, 2013 4:08:15 PM >>>> Subject: Re: [Resteasy-developers] Fwd: Setting the response http code >>>> >>>> You should rethink your design if you're using HttpResponse in your >>>> jaxrs code. >>>> >>>> On 5/29/2013 10:03 AM, Gregor Jarisch wrote: >>>>> Looks like it will solve this bug, yes. >>>>> >>>>> Nevertheless, when a developer injects the HttpResponse and sets a >>>>> http code within the rest method, shouldn't that be enough for >>>>> resteasy not to override it [in case no exception has been thrown of >>>>> course]? >>>>> The filter solution works, but it feels like a work around.. >>>>> >>>>> ----- Original Message ----- >>>>> From: "Bill Burke" <bb...@re...> >>>>> To: res...@li... >>>>> Sent: Wednesday, May 29, 2013 3:35:11 PM >>>>> Subject: Re: [Resteasy-developers] Fwd: Setting the response http >>>>> code >>>>> >>>>> This test just wrote, passes in master/ >>>>> >>>>> >>>>> https://github.com/patriot1burke/Resteasy/blob/master/jaxrs/resteasy-ja >>>>> xrs-testsuite/src/test/java/org/jboss/resteasy/test/nextgen/resource/Re >>>>> sponse4Test.java >>>>> >>>>> So maybe 3.0-beta-6 fixes your problem. >>>>> >>>>> On 5/29/2013 9:23 AM, Bill Burke wrote: >>>>>> So, how to reproduce? >>>>>> >>>>>> @PATH >>>>>> @POST >>>>>> void put() {} >>>>>> >>>>>> >>>>>> and a response filter that sets the status to 201? >>>>>> >>>>>> On 5/29/2013 9:15 AM, Gregor Jarisch wrote: >>>>>>> Hi Bill, >>>>>>> >>>>>>> no exceptions. Resteasy is overriding 201 with its 200 (void) - I >>>>>>> stepped through it. >>>>>>> As described below - resteasy ignores what http code the >>>>>>> HttpResponse already has and just overrides it. >>>>>>> >>>>>>> It's happening here: org.jboss.resteasy.core.ServerResponseWriter >>>>>>> >>>>>>> In case the code of this class didn't change in the coming beta, I >>>>>>> am pretty sure it not gonna change. >>>>>>> Shall I raise a ticket for this? >>>>>>> >>>>>>> ----- Original Message ----- >>>>>>> From: "Bill Burke" <bb...@re...> >>>>>>> To: res...@li... >>>>>>> Sent: Wednesday, May 29, 2013 2:37:33 PM >>>>>>> Subject: Re: [Resteasy-developers] Fwd: Setting the response http >>>>>>> code >>>>>>> >>>>>>> If you cannot override the status via the >>>>>>> ContainerResponseContext.setStatus() then this is a bug. If >>>>>>> Resteasy is >>>>>>> overriding it, then there is some other exception happening after >>>>>>> your >>>>>>> ContainerResponseFilter that is changing the status. >>>>>>> >>>>>>> I'm releasing Beta-6 tomorrow. maybe your problems will go away. >>>>>>> >>>>>>> On 5/29/2013 5:12 AM, Gregor Jarisch wrote: >>>>>>>> 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 >>>>>>>> >> -- >> Bill Burke >> JBoss, a division of Red Hat >> http://bill.burkecentral.com >> >> -------------------------------------------------------------------------- >> ---- >> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET >> Get 100% visibility into your production application - at no cost. >> Code-level diagnostics for performance bottlenecks with <2% overhead >> Download for free and get started troubleshooting in minutes. >> http://p.sf.net/sfu/appdyn_d2d_ap1 >> _______________________________________________ >> Resteasy-developers mailing list >> Res...@li... >> https://lists.sourceforge.net/lists/listinfo/resteasy-developers > > ------------------------------------------------------------------------------ > Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET > Get 100% visibility into your production application - at no cost. > Code-level diagnostics for performance bottlenecks with <2% overhead > Download for free and get started troubleshooting in minutes. > http://p.sf.net/sfu/appdyn_d2d_ap1 > _______________________________________________ > Resteasy-developers mailing list > Res...@li... > https://lists.sourceforge.net/lists/listinfo/resteasy-developers -- Ing. Gregor Jarisch entrepreneurship & development |