users@jersey.java.net

Re: [Jersey] FormParam problem in InjectableProvider and Spring

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 12 Nov 2009 18:32:08 +0100

On Nov 12, 2009, at 6:12 PM, Cemo Koc wrote:

>
>
> Hi Paul,
>
> Thanks for explanation.
>
> But I did not understand this part at the documentation.
>
> The @FormParam annotation is special and may only be utilized on
> resource
> and sub-resource methods. This is because it extracts information
> from a
> request entity.
>
> What is making it special?

Because the request entity may not be of the type application/x-www-
form-urlencoded. Other parameters can be obtained regardless of the
request entity. Request entity processsing should be closely coupled
with the resource method that declares what it consumes.

What if one uses @FormParam but the request entity is not of the type
application/x-www-form-urlencoded? Should values be null? If so this
does not differentiate between a different request entity type and an
absent parameter.

Note that form parameters and query parameters are not
interchangeable. The Servlet API makes this fundamental mistake.


> I really need such a thing because I am
> considering to use jersey with a template engine. Defining annotation
> driven reusable form components will decrease my development time
> greatly.
>

Will a @FormParamBean solution i previously outlined work for you?

It should be possible to combine @FormParam and other @*Param for such
beans. But the @FormParamBean will only be supported on a resource
method parameter that consumes application/x-www-form-urlencoded. Is
that sufficient for your needs?


> I tried to make a injector but I have not been successful yet.
>

It will not currently work because @FormParam is only processed on
parameters of a resource or sub-resource methods.

The solution requires some tweaking to the internals of Jersey.
Specifically to create sub-sets of injectable provider factories for
parameters. Once that capability is enabled it will be very easy to
support @FormParamBean and @ParamBean using the same injection rules
on resource classes themselves but only supporting injection of
parameter-based information.

Stay tuned i might if lucky be able to fully implement this in the
trunk tomorrow!

Paul.