10 Replies Latest reply on Jul 16, 2012 10:31 PM by caiocarlo

    Problem with RESTeasy

    lbot

      Hello,


      i'm trying to integrate RESTeasy with SEAM 2.1.0.CR1 into my application. I started with a very simple test and ran into problems.


      This is my ressource class:




      @Stateful
      @Scope(ScopeType.EVENT)
      @Name("dokumentenRessource")
      @Path("/dokument")
      public class DokumentenRessourceBean implements DokumentenRessource {
           @GET
           @ProduceMime("text/plain")
           @Path("/id")
           public String getTest( @PathParam("id") int id )
           {
                return "Servus " + id;
           }
      
           @Destroy @Remove
           public void destroy() {}
      }
      



      The interface has no REST annotations. I deployed jboss-seam-resteasy.jar, resteasy-jaxrs.jar and jaxrs-api.jar with the libraries of my application.
      I got the following error when the jboss server starts.




      22:18:21,543 ERROR [[/bxtranet]] 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:2049)
              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.endIn.....
      
      ...
      ...
       at org.jboss.Main$1.run(Main.java:508)
              at java.lang.Thread.run(Thread.java:613)
      Caused by: java.lang.RuntimeException: Class is not a root resource.  It, or one of its interfaces must be annotated with @Path: com.bxtranet.basic.session.DokumentenRessourceBean implements:  com.bxtranet.basic.session.DokumentenRessource
              at org.resteasy.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:104)
              at org.resteasy.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:83)
              at org.jboss.seam.resteasy.ResteasyDispatcher.onStartup(ResteasyDispatcher.java:54)
      



      I also tried to annotate the interface or use a POJO as resource class but i got the same error. Now i'm running out of ideas. Did i miss something ?

        • 1. Re: Problem with RESTeasy
          christian.bauer

          EJBs have not been tested, the RESTEasy integration is beta and so they might not work. However, basic POJOs have been tested and should work.

          • 2. Re: Problem with RESTeasy
            lbot

            ok, i changed the class to this:



            @Path("/dokument")
            public class DokumentenRessource{
                 
                 @GET
                 @ProduceMime("text/plain")
                 @Path("/{id}")
                 public String getTest( @PathParam("id") int id )
                 {
                      return "Servus " + id;
                 }
            }
            


            but the problem still exists.

            • 3. Re: Problem with RESTeasy
              johnnyren
              Why not use Page Actions?

              <pages>
                  <page view-id="/hello/*" action="#{helloWorld.sayHello}"/>
              </pages>
              • 4. Re: Problem with RESTeasy
                marcincaban
                I have the same problem with serving a binary document (from blob) as in Your DokumentenRessource.
                Have You resolved it?

                My alternative solution is:
                (...)
                @Stateless
                @Name("zzz")
                @Import("org.jboss.seam.document")
                public class ZzzBean implements Zzz {

                (...)  
                        @In
                        private Manager manager;
                       
                        @In(create = true)
                        private DocumentStore documentStore;
                       
                        @In
                        private FacesContext facesContext;
                       
                        @Begin(flushMode = FlushModeType.MANUAL)
                        @Override
                        public void zzzDokument(int idDokumentu) {
                (...)          
                                byte[] plik = dokument.getPlik();
                                DocumentData dane = new DocumentData("filename",
                                                new DocumentData.DocumentType("pdf",
                                                                "application/pdf"), plik);
                                String docId = documentStore.newId();
                                documentStore.saveData(docId, dane);
                                String documentUrl =
                                        documentStore.preferredUrlForContent(
                                                        dane.getBaseName(),
                                                        dane.getDocumentType().getExtension(),
                                                        docId);
                                try {
                                        facesContext.getExternalContext().redirect(
                                                        manager.encodeConversationId(documentUrl, manager.getCurrentConversationViewId()));
                                }
                                catch (IOException ioe) {
                                        throw new RedirectException(ioe);
                                }
                        }
                }


                but I think seam/resource would be smarter


                Thanks.
                • 5. Re: Problem with RESTeasy
                  mvdvlies

                  I'm having the same problem. I used both an EJB and a POJO, both with the same result. Could it somehow be related to: https://jira.jboss.org/jira/browse/RESTEASY-47 ?

                  • 6. Re: Problem with RESTeasy
                    mvdvlies

                    Ok, I fixed it (with some help of a colleague), after some debugging we discovered that there were two javax.ws.rs.Path's in the classpath. Make sure you have the following layout:


                    war-file/WEB-INF/lib:


                    jboss-seam-resteasy.jar


                    ear-file/lib:


                    jaxrs-api.jar
                    resteasy-jaxrs.jar


                    And in no other combination or duplicates. This should solve your problem. It solved mine :)

                    • 7. Re: Problem with RESTeasy
                      nhhagen

                      Could you please add the MANIFEST.MF files here. I'm having a problem with the clathpath for classes in the jaxrs-api.jar

                      • 8. Re: Problem with RESTeasy
                        kongo09

                        I had exactly the same problem with Seam 2.2 and your .jar layout solved it for me. Thanks!!!

                        • 9. Re: Problem with RESTeasy
                          keurvet

                          Yes, me too, thanks a lot !!!!!

                          • 10. Re: Problem with RESTeasy

                            Does anyone know of any definitive solution to the use of RESTEasy in each WAR file in the same server?