users@jax-rs-spec.java.net

[jax-rs-spec users] [jsr339-experts] Re: Contexts in TimeoutHandler

From: Bill Burke <bburke_at_redhat.com>
Date: Wed, 10 Jul 2013 09:35:46 -0400

It is not a valid option because UriInfo may be proxied depending on the
lifecycle of the resource class (per request or singleton) and the
implementation.

On 7/10/2013 9:04 AM, Sergey Beryozkin wrote:
> One more thought:
>
> public class Root {
> @Context
> private UriInfo ui;
>
> @GET
> public void get(@Suspended AsyncResponse ar) {
> ar.setTimeoutHandler(new MyTimeoutHandler());
> // instead of new MyTimeoutHandler(ui.getAbsoluteUri());
> }
>
> private class MyTimeoutHandler implements TimeoutHandler {
> public void handleTimeout(AsyncResponse asyncResponse) {
> URI uri = Root.this.ui.getAbsoluteUri();
> // use this uri to create a response somehow
> }
> }
> }
>
> I think this is a valid code option, I'm not advocating strongly for it
> to be supported, but it seems to me users may expect the above code
> working, i.e, TimeoutHandler implementation being able to access a
> request context from a root class.
>
> If this case is not going to be supported then IMHO it has to be noted
> (say in TimeoutHandler docs) that the implementations should store the
> context information at the handler initialization time should they need
> an access to it
>
> Sergey
>
> On 09/07/13 17:11, Sergey Beryozkin wrote:
>> Hi Marek
>> On 09/07/13 16:50, Marek Potociar wrote:
>>> Hi Sergey,
>>>
>>> What is the use case you have in mind?
>> I was looking at something else and then realized that if we have
>> TimeoutHandler then it means by the time it is ready to provide a final
>> Response, it won't be able to use a context info to build this Response
>> (for whatever reasons one may want to do it, example, build new links
>> based on the info obtained from UriInfo, etc),
>> unless this info was captured when AsyncResponse method was invoked.
>>
>> I guess this can work actually so I'm fine with not doing anything extra
>> in this regard unless it proves limiting...
>>
>> Thanks, Sergey
>>
>>
>>>
>>> Marek
>>>
>>> On Jul 9, 2013, at 1:23 PM, Sergey Beryozkin <sberyozkin_at_talend.com>
>>> wrote:
>>>
>>>> Hi,
>>>>
>>>> would anyone see a value in injecting contexts in AsyncResponse
>>>> TimeoutHandler implementations ?
>>>>
>>>> Otherwise, when needed, a context info would need to be saved in the
>>>> original AsyncResponse method handler for TimeoutHandler see UriInfo,
>>>> etc...
>>>>
>>>> Sergey
>>>
>>
>>
>
>

-- 
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com