6 Replies Latest reply on Feb 12, 2009 8:17 PM by J R

    Seam 2.1.1.GA RESTEasy problem

    Niels Henrik Hagen Newbie

      I'm using the integrated REASTEasy implementation that came with seam, and I get the following error when I access the resource with a browser:



      13:21:40,048 ERROR [STDERR] java.lang.RuntimeException: Bad arguments passed to public java.lang.String com.tracetracker.cci.session.GqiResourceBean.getShelfLife(java.lang.String,java.lang.String)  ( arg1, arg2
      13:21:40,049 ERROR [STDERR]      at org.resteasy.MethodInjectorImpl.invoke(MethodInjectorImpl.java:133)
      13:21:40,049 ERROR [STDERR]      at org.resteasy.ResourceMethod.invoke(ResourceMethod.java:162)
      13:21:40,049 ERROR [STDERR]      at org.resteasy.ResourceMethod.invoke(ResourceMethod.java:134)
      13:21:40,049 ERROR [STDERR]      at org.resteasy.Dispatcher.invoke(Dispatcher.java:161)
      13:21:40,049 ERROR [STDERR]      at org.jboss.seam.resteasy.ResteasyResourceAdapter$1.process(ResteasyResourceAdapter.java:127)
      13:21:40,049 ERROR [STDERR]      at org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:53)
      13:21:40,049 ERROR [STDERR]      at org.jboss.seam.resteasy.ResteasyResourceAdapter.getResource(ResteasyResourceAdapter.java:71)
      13:21:40,049 ERROR [STDERR]      at org.jboss.seam.servlet.SeamResourceServlet.service(SeamResourceServlet.java:80)
      13:21:40,049 ERROR [STDERR]      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      13:21:40,049 ERROR [STDERR]      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      13:21:40,049 ERROR [STDERR]      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      13:21:40,050 ERROR [STDERR]      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
      13:21:40,050 ERROR [STDERR]      at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
      13:21:40,050 ERROR [STDERR]      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      13:21:40,050 ERROR [STDERR]      at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
      13:21:40,050 ERROR [STDERR]      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      13:21:40,050 ERROR [STDERR]      at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
      13:21:40,050 ERROR [STDERR]      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      13:21:40,050 ERROR [STDERR]      at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
      13:21:40,050 ERROR [STDERR]      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      13:21:40,050 ERROR [STDERR]      at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:177)
      13:21:40,050 ERROR [STDERR]      at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
      13:21:40,050 ERROR [STDERR]      at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)
      13:21:40,050 ERROR [STDERR]      at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507)
      13:21:40,050 ERROR [STDERR]      at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
      13:21:40,050 ERROR [STDERR]      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      13:21:40,050 ERROR [STDERR]      at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
      13:21:40,050 ERROR [STDERR]      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      13:21:40,050 ERROR [STDERR]      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:73)
      13:21:40,050 ERROR [STDERR]      at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
      13:21:40,050 ERROR [STDERR]      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      13:21:40,051 ERROR [STDERR]      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      13:21:40,051 ERROR [STDERR]      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      13:21:40,051 ERROR [STDERR]      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      13:21:40,051 ERROR [STDERR]      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      13:21:40,051 ERROR [STDERR]      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
      13:21:40,051 ERROR [STDERR]      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      13:21:40,051 ERROR [STDERR]      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
      13:21:40,051 ERROR [STDERR]      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
      13:21:40,051 ERROR [STDERR]      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
      13:21:40,051 ERROR [STDERR]      at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
      13:21:40,051 ERROR [STDERR]      at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
      13:21:40,051 ERROR [STDERR]      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      13:21:40,051 ERROR [STDERR]      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      13:21:40,051 ERROR [STDERR]      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
      13:21:40,051 ERROR [STDERR]      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      13:21:40,051 ERROR [STDERR]      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
      13:21:40,051 ERROR [STDERR]      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
      13:21:40,051 ERROR [STDERR]      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
      13:21:40,051 ERROR [STDERR]      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      13:21:40,051 ERROR [STDERR]      at java.lang.Thread.run(Thread.java:619)
      13:21:40,052 ERROR [STDERR] Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
      13:21:40,052 ERROR [STDERR]      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      13:21:40,052 ERROR [STDERR]      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      13:21:40,052 ERROR [STDERR]      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      13:21:40,053 ERROR [STDERR]      at java.lang.reflect.Method.invoke(Method.java:597)
      13:21:40,053 ERROR [STDERR]      at org.resteasy.MethodInjectorImpl.invoke(MethodInjectorImpl.java:72)
      13:21:40,053 ERROR [STDERR]      ... 50 more
      



      The url used to access the server:



      http://localhost:8080/app/seam/resource/rest/restResource/method/arg1/arg2
      




      The Bean:


      package org.domain.app.session;
      
      import javax.ejb.Stateless;
      import javax.ws.rs.GET;
      import javax.ws.rs.Path;
      import javax.ws.rs.PathParam;
      import javax.ws.rs.ProduceMime;
      
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.international.StatusMessages;
      import org.jboss.seam.log.Log;
      
      @Stateless
      @Name("restResource")
      @Path("/restResource")
      public class RestResourceBean implements RestResource {
           @Logger
           private Log log;
      
           @In
           StatusMessages statusMessages;
      
           public void RestResource() {
                // implement your business logic here
                log.info("gqiResource.gqiResource() action called");
                statusMessages.add("gqiResource");
           }
           
           @GET
           @Path("/method/{arg1}/{arg2}")
           @ProduceMime("text/plain")
           public String getShelfLife( @PathParam("arg1") String a1, @PathParam("arg2") String a2 ) {
                return "This is a test, arg1: " + a1 + " arg2 " + a2;
           }
      
      }
      



      The interface:



      package org.domain.app.session;
      
      import javax.ejb.Local;
      
      @Local
      public interface RestResource {
           
           // seam-gen method
           public void restResource();
           
           public String method( String station, String date );
      
      }
      
      



      I've tried to google the 2 error message but without getting any luck with the results. Any help with this would be greatly appreciated.


        • 1. Re: Seam 2.1.1.GA RESTEasy problem
          John Ament Master

          Your implementation has..


          public String getShelfLife


          Your interface has...


          public String method

          • 2. Re: Seam 2.1.1.GA RESTEasy problem
            Niels Henrik Hagen Newbie

            Sorry for that, just an editing error when posting trying to make the post as generic as posible (I realize that I might have been to tired):


            in the real files


            Interface is: public String getShelfLife
            Implementation is: public String getShelfLife


            Pasting interface and implementation one more time (direct from source).


            Interface:



            package com.tracetracker.cci.session;
            
            import javax.ejb.Local;
            import javax.ws.rs.GET;
            import javax.ws.rs.Path;
            import javax.ws.rs.PathParam;
            import javax.ws.rs.ProduceMime;
            
            @Local
            public interface GqiResource {
                 
                 // seam-gen method
                 public void gqiResource();
                 
                 public String getShelfLife( String station, String date );
            
            }
            



            Bean:



            package com.tracetracker.cci.session;
            
            import javax.ejb.Stateless;
            import javax.ws.rs.GET;
            import javax.ws.rs.Path;
            import javax.ws.rs.PathParam;
            import javax.ws.rs.ProduceMime;
            
            import org.jboss.seam.annotations.In;
            import org.jboss.seam.annotations.Logger;
            import org.jboss.seam.annotations.Name;
            import org.jboss.seam.international.StatusMessages;
            import org.jboss.seam.log.Log;
            
            @Stateless
            @Name("gqiResource")
            @Path("/gqiResource")
            public class GqiResourceBean implements GqiResource {
                 @Logger
                 private Log log;
            
                 @In
                 StatusMessages statusMessages;
            
                 public void gqiResource() {
                      // implement your business logic here
                      log.info("gqiResource.gqiResource() action called");
                      statusMessages.add("gqiResource");
                 }
                 
                 @GET
                 @Path("/getShelfLife/{station}/{date}")
                 @ProduceMime("text/plain")
                 public String getShelfLife( @PathParam("station") String station, @PathParam("date") String date ) {
                      return "This is a test, station: " + station + " date " + date;
                 }
            
            }
            
            



            • 3. Re: Seam 2.1.1.GA RESTEasy problem
              Niels Henrik Hagen Newbie

              I could really need some help on this issue. Has anyone come across the same error before

              • 4. Re: Seam 2.1.1.GA RESTEasy problem
                J R Newbie

                I encountered this problem myself. Here is what I think is happening. Seam creates an instance of the 'restResource' component by obtaining an instance from JNDI. What it gets back is an EJB stub that implements RestResource, not an instance of RestResourceBean. However, it is RestResourceBean that is annotated and not RestResource. As a result Resteasy is trying to invoke methods on what it thinks is a RestResourceBean. This of course fails and you get the 'object is not an instance of declaring class' error.


                Did you try placing the JAX-RS annotations on RestResource? I think the problem there is going to be one of discovery -- seam/resteasy might not find the JAX-RS annotations on the interface.


                When I annotate the local interface instead of the bean I get the following exception on deploy:


                2009-02-10 18:27:27,532 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/jcourse/SeamTest]] Exception sending
                context initialized event to listener instance of class org.jboss.seam.servlet.SeamListener
                org.jboss.seam.InstantiationException: Could not instantiate Seam component: org.jboss.seam.resteasy.dispatcher
                        at org.jboss.seam.Component.newInstance(Component.java:2106)
                        at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304)
                        at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278)
                        at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:112)
                        at org.jboss.seam.init.Initialization.init(Initialization.java:735)
                        at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:35)
                        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3856)
                        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4361)
                        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:790)
                        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:770)
                        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:553)
                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)



                with the cause being:


                Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
                        at org.resteasy.plugins.server.resourcefactory.POJOResourceFactory.registered(POJOResourceFactory.java:31)
                        at org.resteasy.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:120)
                        at org.resteasy.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:106)
                        at org.resteasy.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:83)
                        at org.jboss.seam.resteasy.ResteasyDispatcher.onStartup(ResteasyDispatcher.java:90)
                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                        at java.lang.reflect.Method.invoke(Method.java:597)
                        at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
                        at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
                        at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                        at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
                        at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                        at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
                        at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                        at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
                        at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)


                The ArrayIndexOutOfBoundsException exception suggests that it is finding the component, but not the JAX-RS annotations on its interfaces.



                • 5. Re: Seam 2.1.1.GA RESTEasy problem
                  John Ament Master

                  apparently, based on the jboss docs, you should be annotating your interface, not implementation.  didn't know that myself either, but came up as the first hit when i searched on the google for resteasy ejb


                  My Link

                  • 6. Re: Seam 2.1.1.GA RESTEasy problem
                    J R Newbie

                    That indeed is the problem. See:


                    https://jira.jboss.org/jira/browse/JBSEAM-3938
                    and
                    https://jira.jboss.org/jira/browse/JBSEAM-3449


                    Looks like the problem will be resolved soon.


                    Annotated interfaces work just fine if you use the GA release of RESTeasy standalone.