users@jersey.java.net

Re: [Jersey] Problem (+ cryptic error message) with _at_Provider / ContextResolver

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 13 Nov 2009 15:53:11 +0100

On Nov 13, 2009, at 11:45 AM, Stefane Fermigier wrote:

> Hi,
>
> I'm running into a serious problem when trying to create my own
> ContextResolvers to inject context into my method calls, and the
> error message "Method, ... is not recognized as valid Java method
> annotated with @HttpMethod." is not very helpful. Any idea on how to
> fix it ?
>
> Here are three classes that showcase the problem I have:
>
> A resource class:
>
> @Path("/")
> public class TestPage {
> @GET
> @Path("/test")
> public String home(@Context MyContext context) throws Exception {

You need to be explicit in the use of ContextResolver. Try:

     public String home(@Context ContextResolver<MyContext> context)
throws Exception {


And i agree the error is cryptic. I need to improve error reporting
when a value cannot be injected.

Paul.


> return "OK: " + context.hello();
> }
> }
>
> A dummy context class:
>
> public class MyContext {
> public String hello() {
> return "hello!";
> }
> }
>
> And a context provider:
>
> @Provider
> public final class MyContextProvider implements
> ContextResolver<MyContext> {
> public MyContext getContext(Class<?> type) {
> return new MyContext();
> }
> }
>
> The server logs say:
>
> 11:28:16,995 INFO [JavaUtilLoggingHelper$LogHandler] Scanning for
> root resource and provider classes in the packages:
> org.nuxeo.community
> 11:28:17,136 INFO [JavaUtilLoggingHelper$LogHandler] Root resource
> classes found:
> class org.nuxeo.community.TestPage
> 11:28:17,136 INFO [JavaUtilLoggingHelper$LogHandler] Provider
> classes found:
> class org.nuxeo.community.MyContextProvider
> class org.nuxeo.community.CoreSessionProvider
> 11:28:17,278 INFO [JavaUtilLoggingHelper$LogHandler] Initiating
> Jersey application, version 'Jersey: 1.1.3-ea 10/06/2009 05:13 PM'
> 11:28:19,278 ERROR [JavaUtilLoggingHelper$LogHandler] service
> exception:
> com.sun.jersey.api.container.ContainerException: Method, public
> java.lang.String
> org.nuxeo.community.TestPage.home(org.nuxeo.community.MyContext)
> throws java.lang.Exception, annotated with GET of resource, class
> org.nuxeo.community.TestPage, is not recognized as valid Java method
> annotated with @HttpMethod.
> at
> com
> .sun
> .jersey
> .server
> .impl.model.method.ResourceHttpMethod.<init>(ResourceHttpMethod.java:
> 92)
>
>
> S.
>
>
> --
> Stefane Fermigier, Founder and Chairman, Nuxeo
> Open Source, Java EE based, Enterprise Content Management (ECM)
> Web: http://www.nuxeo.com/ - Tel: +33 1 40 33 79 87
> New: follow me on Twitter: http://twitter.com/sfermigier
>
>
>
> --
> Stefane Fermigier, Founder and Chairman, Nuxeo
> Open Source, Java EE based, Enterprise Content Management (ECM)
> Web: http://www.nuxeo.com/ - Tel: +33 1 40 33 79 87
> New: follow me on Twitter: http://twitter.com/sfermigier
>