users@jersey.java.net

Re: [Jersey] FormParam problem in InjectableProvider and Spring

From: Cemo Koc <cem.koc.fwd_at_gmail.com>
Date: Mon, 16 Nov 2009 04:37:28 -0800 (PST)

Thank you so much Paul...

I will try tomorrow this. And after it I will share my experience.

Cem



Paul Sandoz wrote:
>
> Hi,
>
> This is fixed in the trunk (jars on repo not yet available).
>
> You can now use the @Inject annotation to obtain a resource and that
> resource can have @FormParam instances injected on to it.
>
> If @FormParam injection occurs when there is no request entity the
> media type is anything other than "application/x-www-form-urlencoded"
> an IllegalStateException will be thrown.
>
> If you need to inject a per-request resource onto a singleton resource
> you can do:
>
> @Singleton
> public class SingletonResource {
> private final Injectable<PerRequestResouce> ipr;
>
> public SingletonResource(@Inject Injectable<PerRequestResouce>
> ipr) {
> this.ipr = ipr;
> }
> }
>
> Paul.
>
> On Nov 13, 2009, at 10:55 AM, Cemo Koc wrote:
>
>>
>> Despite of being newbie in restful area, I believe that such an
>> implementation can be very beneficial for us. :) I am looking for your
>> implementation.
>>
>> Thanks
>>
>>
>>
>>
>>
>> Paul Sandoz wrote:
>>>
>>>
>>> Thinking out loud in the following....
>>>
>>> Having thought about this some more ideally what i would like to
>>> achieve is:
>>>
>>> @GET
>>> public XXX get(@Inject MyParamBean b) { ... } // I am referring to
>>> Jersey's @Inject annotation.
>>>
>>> which would replace:
>>>
>>> @GET
>>> public XXX get(@ResourceContext ResourceContext rc) { ...
>>> MyParamBean b = rc.get(MyParamBean.class);
>>> }
>>>
>>>
>>> Then for forms ideally we could do the same like:
>>>
>>> @POST
>>> @Consumes("application/x-www-form-urlencoded")
>>> public XXX post(@Inject MyParamBean b) { ... }
>>>
>>>
>>> The problem is there is a slight inconsistency in all this. Consider
>>> the following:
>>>
>>> public class Foo {
>>> public Foo(@Inject MyParamBean b) { ... }
>>>
>>> @GET
>>> public XXX get(@Inject MyParamBean b) { ... }
>>>
>>> @POST
>>> @Consumes("application/x-www-form-urlencoded")
>>> public XXX post(@Inject MyParamBean b);
>>> }
>>>
>>> Currently we only know that form parameters are present when the POST
>>> method is called, but the reference to b in the constructor parameter
>>> should be the same as the parameter of the get or post (default life-
>>> cycle is per-request).
>>>
>>> I am wondering if i should really relax things in this respect and go
>>> back on some of the things i said. The way we could do this is to
>>> buffer the request entity if it is of "application/x-www-form-
>>> urlencoded" and also parse the entity to an instance of Form from
>>> which @FormParam can operate. If there is no Form present we can
>>> throw
>>> an exception. Buffering would only occur if form parameters are
>>> accessed outside of the resource method, or cannot be detected from a
>>> resource method. However, i still do not like the fact form
>>> parameters
>>> could be processed from outside of the resource method.
>>>
>>> Marc, if you got this far :-), what do you think?
>>>
>>> Paul.
>>>
>>>
>>>
>>
>> --
>> View this message in context:
>> http://n2.nabble.com/FormParam-problem-in-InjectableProvider-and-Spring-tp3992897p3998312.html
>> Sent from the Jersey mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> 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
>
>
>

-- 
View this message in context: http://n2.nabble.com/FormParam-problem-in-InjectableProvider-and-Spring-tp3992897p4011778.html
Sent from the Jersey mailing list archive at Nabble.com.