users@jersey.java.net

Re: [Jersey] FormParam problem in InjectableProvider and Spring

From: Cemo Koc <cem.koc.fwd_at_gmail.com>
Date: Thu, 19 Nov 2009 04:19:25 -0800 (PST)

Hi,

@Inject annotation can not work me. I can see these logs at my console

[#|2009-11-19T14:05:54.450+0200|SEVERE|sun-appserver2.1|com.sun.jersey.spi.container.ContainerRequest|_ThreadID=26;_ThreadName=TP-Processor3;_RequestID=d0825c03-00a7-4c9d-bbb7-778764691361;|A
message body reader for Java type, class xxx.Sample, and MIME media type,
application/x-www-form-urlencoded, was not found|#]


And for your other question, I wanted to say that I suspected about one
thing... While I was debugging, I saw such a thing... I just want to share
with you....

http://img36.imageshack.us/img36/7444/prtscrcapture2o.jpg

http://n2.nabble.com/file/n4031501/prtscrcapture2o.jpg


And the test case testFormParamBean in FormParamTest is running perfectly.

Thanks







Paul Sandoz wrote:
>
> Hi,
>
> @FormParam stuff should work with the latest 1.1.5-ea-SNAPSHOT
> artifacts on the maven repo (there are unit tests in place for this).
>
> Does the @Inject annotation work for you?
>
> For example in your resource method can you do:
>
> @POST
> public ... post(@Inject Sample s) {
> assertNotNull(s.param1);
> assertNotNull(s.param2);
> ...
> }
>
>
> I do not understand what you mean by:
>
>> . But then, when I check at my provider class at above, I see that
>> this
>> provider is not there.
>
>
> Paul.
>
> On Nov 18, 2009, at 10:52 AM, Cemo Koc wrote:
>
>>
>> Hi Paul,
>>
>> I installed latest code from trunk as 1.1.5-ea-snapshot.
>>
>> I have such an implementation.
>>
>> public class Sample extends SimpleForm {
>>
>> @FormParam("param1")
>> String param1;
>>
>> @FormParam("param2")
>> String param2;
>>
>> @QueryParam("x")
>> String param3;
>> ///
>> }
>>
>>
>> @Provider
>> public class FormBeanInjector implements
>> InjectableProvider<FormBean, Type>
>> {
>>
>> private final ResourceContext rc;
>>
>> public FormBeanInjector(@Context ResourceContext rc) {
>> this.rc = rc;
>> }
>>
>> public ComponentScope getScope() {
>> return ComponentScope.PerRequest;
>> }
>>
>> public Injectable getInjectable(ComponentContext ic, FormBean a,
>> Type
>> type) {
>> if (type instanceof Class) {
>> final Class c = (Class) type;
>>
>> return new Injectable() {
>> public Object getValue() {
>> return rc.getResource(c);
>> }
>> };
>> }
>> return null;
>> }
>> }
>>
>> However my resourceContext can not return FormParam setted FormBean
>> object.
>> I can see that QueryParam annotated variable can be setted but
>> FormParam
>> annotated variables can not be setted.
>>
>>
>> When I checked at initiliaziting of my application, I could see that
>> formParam bean provider is setted in injectableFactory in
>> WebapplicationImpl
>> . But then, when I check at my provider class at above, I see that
>> this
>> provider is not there.
>>
>>
>> Thanks
>>
>>
>>
>> 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-tp3992897p4024398.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-tp3992897p4031501.html
Sent from the Jersey mailing list archive at Nabble.com.