users@jersey.java.net

Re: [Jersey] Re:Best way to pass data from a container/resource filter back to a object

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 13 Apr 2010 12:01:43 +0200

On Apr 11, 2010, at 2:39 PM, John Lister wrote:

> Hi Paul, apologies for not replying I seemed to have missed your
> reply. I would be interested in seeing your solution as I always
> keen to learn new ideas...
>

Since you are using CDI you can write a CDI provider to extract
objects out of the servlet request attributes. That might be better
than using the Jersey-specific injection APIs.

An alternative could be to inject the CDI managed filter (or an
interface it implements) on to the CDI managed resource.

Paul.

> Thanks
>
> John
>
>
> On Mar 31, 2010, at 10:10 AM, John Lister wrote:
>> Hi John,
>> The basic way is for the filter to add a property to
>> ContainerRequest. Then the resource class can inject HttpConttext
>> and the property can be retrieved from that (i realize that is a
>> little confusing, it is the way the API evolved with filters being
>> designed after HttpContext was designed).
>>
>> Another way is to create your own InjectableProvider that extracts
>> an object out of the request properties. In fact one could write
>> such a general provider.
>>
>> So the filter adds an name/value to the request properties and the
>> injectable provider extracts that out e.g.:
>>
>> @RequestProperty("name") MyObject o;
>>
>> I can send more details if required.
>>
>> Paul.
>>
>> On Mar 25, 2010, at 11:24 PM, John Lister wrote:
>>
>> > I may have solved this, I decided to read the JAX-RS specs to
>> see > what was injectable and discovered that I should be
>> injecting the > Request interface - I'd tried using the
>> ContainerRequest class... > Although this still seems a little
>> cludgy, am I on the right track > or is there a much simpler
>> solution?
>> >
>> > Thanks
>> >
>> > John
>> >
>> > >Hi, this seems an obvious thing but I can't seem to find an
>> answer. > What is the best/recommended way (if at all) of passing
>> data from a
>> > >container/resource filter back to the resource object after the
>> > filter completes..
>> >
>> > >For example I have a container filter that does some checks
>> after > which I'd like to make the results available in the
>> resource object, > but I
>> > >can't find a simple way to do it.
>> >
>> >
>> > >At first I thought I could add a property to the
>> ContainerRequest > object passed to my filter method, but I can't
>> seem to find a way to > get
>> > >access to this (either directly or via something else) in my
>> GET > function for example within the resource object.
>> >
>> >
>> >
>> ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> > For additional commands, e-mail: users-help_at_jersey.dev.java.net
>> >
>>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>