users@jersey.java.net

Re: [Jersey] Custom Parameter Binding

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 29 Jun 2009 09:27:43 +0200

On Jun 27, 2009, at 2:36 PM, Meeraj Kunnumpurath wrote:

> Paul,
>
> I tried your example, and it works fine standalone. I tried hooking
> that in with my container, I get the following error if the resource
> method is annotated with @GET
>
> SEVERE: A HTTP GET method, public abstract java.lang.String
> tests.rs.CardService.upload(tests.rs.CardUploadRequest), should not
> consume any entity.
>
> if I change it to @POST, I get the following error
>
> SEVERE: A message body reader for Java type, class
> tests.rs.CardUploadRequest, and MIME media type, application/octet-
> stream, was not found
>
> I can't see the Jersey runtime trying to instantiate an instance of
> the new ResourceParamInjector.

How are you registering your root resource and provider classes?

You register your @Provider provider classes in the same way as your
@Path root resource classes.

I suspect that you have not registered the ResourceParamInjector.
Notice in the example i sent that the class is annotated with
@Provider and it is picked up by the package scanning:

         initParams.put("com.sun.jersey.config.property.packages",
                 "com.sun.jersey.samples.resourceinject");

You can declare more than one package by using the ";" separator.

Plus you should ensure that your IocComponentProviderFactory returns
"null" for stuff it does not know how to instantiate. If you have
registered your ResourceParamInjector correctly your
IocComponentProviderFactory will get asked to instantiate it, if you
return null, then you defer to another IocComponentProviderFactory
that can instantiate it.

Paul.

> FYI, I have all the JAX-RS annotations on an interface in my test
> and I pass a dynamic proxy to the Jersey runtime through the
> IocComponentProviderFactory. This is how my resource interface looks
> like,
>
> @Path("/card")
> public interface CardService {
>
> @Path("/upload")
> @POST
> String upload(@ResourceParam CardUploadRequest cardUploadRequest);
>
> @Path("/disable")
> @POST
> String disable(@QueryParam("cardNumber") String cardNumber);
>
> }
>
> One possibility I thought was with reflection proxies, the
> annotations on the proxied interface were not available for runtime
> introspection. However, it seems to be able to find other
> annotations like @QueryParam on the interface. Any pointers would be
> highly helpful.
>
> Ta
> Meeraj
>
>
> On Fri, Jun 26, 2009 at 8:30 AM, Meeraj Kunnumpurath <mkunnumpurath_at_googlemail.com
> > wrote:
> Thanks Paul.
>
>
> On Fri, Jun 26, 2009 at 7:53 AM, Paul Sandoz <Paul.Sandoz_at_sun.com>
> wrote:
>
> On Jun 26, 2009, at 12:54 AM, Meeraj Kunnumpurath wrote:
>
> Paul,
>
> Couple of questions on the example ..
>
> 1. If I run within a Servlet container instead Grizzly, how do I
> configure the runtime to use the ResourceParamInjector?
>
> There is no difference. It is annotated with @Provider. Just make
> sure in your web.xml you have:
>
> <init-param>
> <param-name>com.sun.jersey.config.property.packages</
> param-name>
> <param-value>com.sun.jersey.samples.resourceinject</
> param-value>
> </init-param>
>
> (the above is declared programatically in the main method of the
> example). See the following for more details:
>
> https://jersey.dev.java.net/documentation/1.1.0-ea/user-
> guide.html#d4e115
>
>
>
>
> 2. Where is the logic of injecting the value of query parameter x
> into the instance variable x of MyBean?
>
>
> You mean in the Jersey code ? Note that it is the same logic if you
> added that field (+annotation) to MyResource.
>
> To understand that i think it might be instructive to do a debug
> session, modify the MyBean to be:
>
> public static class MyBean {
> public MyBean(@QueryParam("x") String x) {
> // Set break point here
> }
>
> @QueryParam("x") String x;
>
> @QueryParam("x)
>
> public void setFoo(String foo) {
> // Set break point here
> }
> }
>
> Then you can get an idea where in Jersey things get invoked. The
> that performs the injection of a query parameter is here:
>
> http://fisheye4.atlassian.com/browse/jersey/trunk/jersey/jersey-server/src/main/java/com/sun/jersey/server/impl/model/parameter/QueryParamInjectableProvider.java?r=2097
>
> Paul.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>
>