jsr339-experts@jax-rs-spec.java.net

[jsr339-experts] Re: Contexts in TimeoutHandler

From: Sergey Beryozkin <sberyozkin_at_talend.com>
Date: Wed, 10 Jul 2013 14:04:28 +0100

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
>>
>
>


-- 
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com