|
From: Gregor J. <gr...@ja...> - 2013-05-28 13:13:42
|
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 |
|
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 |
|
From: Bill B. <bb...@re...> - 2013-05-29 12:37:36
|
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 |
|
From: Gregor J. <gr...@ja...> - 2013-05-29 13:15:26
|
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 |
|
From: Bill B. <bb...@re...> - 2013-05-29 13:23:25
|
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
|
|
From: Bill B. <bb...@re...> - 2013-05-29 13:35:13
|
This test just wrote, passes in master/ https://github.com/patriot1burke/Resteasy/blob/master/jaxrs/resteasy-jaxrs-testsuite/src/test/java/org/jboss/resteasy/test/nextgen/resource/Response4Test.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 |
|
From: Gregor J. <gr...@ja...> - 2013-05-29 14:03:26
|
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-jaxrs-testsuite/src/test/java/org/jboss/resteasy/test/nextgen/resource/Response4Test.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 |
|
From: Bill B. <bb...@re...> - 2013-05-29 14:08:18
|
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-jaxrs-testsuite/src/test/java/org/jboss/resteasy/test/nextgen/resource/Response4Test.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 |
|
From: Gregor J. <gr...@ja...> - 2013-05-29 14:19:02
|
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-jaxrs-testsuite/src/test/java/org/jboss/resteasy/test/nextgen/resource/Response4Test.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 |
|
From: Bill B. <bb...@re...> - 2013-05-29 14:36:11
|
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-jaxrs-testsuite/src/test/java/org/jboss/resteasy/test/nextgen/resource/Response4Test.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 |
|
From: Gregor J. <gr...@ja...> - 2013-05-29 14:54:36
|
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-jaxrs-testsuite/src/test/java/org/jboss/resteasy/test/nextgen/resource/Response4Test.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 |
|
From: Bill B. <bb...@re...> - 2013-05-29 15:16:49
|
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-jaxrs-testsuite/src/test/java/org/jboss/resteasy/test/nextgen/resource/Response4Test.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 |
|
From: Geyer, R. <Ran...@in...> - 2013-05-29 17:07:16
|
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 |
|
From: Gregor J. <gr...@ja...> - 2013-05-30 13:33:23
|
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 |
|
From: Bill B. <bb...@re...> - 2013-05-30 14:17:49
|
The best way is through the Response object. On 5/30/2013 9:33 AM, Gregor Jarisch wrote: > 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 > > -- Bill Burke JBoss, a division of Red Hat http://bill.burkecentral.com |
|
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 |
|
From: Geyer, R. <Ran...@in...> - 2013-05-31 06:02:21
|
You can always return it, regardless of whether the client will cache and/or ignore it. You would also provide a GET method for those other use cases. - rg From: Gregor Jarisch <gr...@ja...<mailto:gr...@ja...>> Date: Thursday, May 30, 2013 8:36 AM To: RestEasy Developers <Res...@li...<mailto:Res...@li...>> Subject: [Resteasy-developers] Fwd: Re: Fwd: Setting the response http code 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...><mailto:gr...@ja...> To: res...@li...<mailto: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...><mailto: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...><mailto:bb...@re...> >>> To: res...@li...<mailto: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...><mailto:bb...@re...> >>>> To: res...@li...<mailto: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...><mailto:bb...@re...> >>>>> To: res...@li...<mailto: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...><mailto:bb...@re...> >>>>>>> To: res...@li...<mailto: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...><mailto:gr...@ja...> >>>>>>>> To: res...@li...<mailto: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...<mailto: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...<mailto:Res...@li...> > https://lists.sourceforge.net/lists/listinfo/resteasy-developers -- Ing. Gregor Jarisch entrepreneurship & development |
|
From: Gregor J. <gr...@ja...> - 2013-05-31 08:10:22
|
I cannot fully agree. Sending back the response to the client is not necessarily a good idea in any use case. 1. It produces more traffic (too much - if the response body is ignored anyways) 2. If the client posts a content which should be created on the server it doesn't make sense to send back the very same content ----- Original Message ----- From: "Randy Geyer" <Ran...@in...> To: "Gregor Jarisch" <gr...@ja...>, res...@li... Sent: Friday, May 31, 2013 8:02:10 AM Subject: Re: [Resteasy-developers] Fwd: Re: Fwd: Setting the response http code You can always return it, regardless of whether the client will cache and/or ignore it. You would also provide a GET method for those other use cases. - rg From: Gregor Jarisch < gr...@ja... > Date: Thursday, May 30, 2013 8:36 AM To: RestEasy Developers < Res...@li... > Subject: [Resteasy-developers] Fwd: Re: Fwd: Setting the response http code 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 |
|
From: Gregor J. <gr...@ja...> - 2013-05-30 13:29:46
|
That's exactly what I am trying to achieve without any workarounds. But it seems to me that I have to inject the HttpResponse in order to set the 201 and add the URI to the Location header (if I don't want to use the Response Object and return void instead). On 29.05.2013 17:16, Bill Burke 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-jaxrs-testsuite/src/test/java/org/jboss/resteasy/test/nextgen/resource/Response4Test.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 >>>>>>> -- Ing. Gregor Jarisch entrepreneurship & development |