7 Replies Latest reply on Sep 20, 2010 7:25 AM by lvdberg

    Getting RESTeasy working with seam-gen and eclipse (my notes)

    dhcinc

      I spent the last couple of days working out how to integrate RESTeasy services with seam using the seam-gen process and eclipse.


      Along the way, I discovered some 'gotchas' that made the process a little frustrating at times. In order to help other folks who are trying to set RESTeasy up in this environment, I will use this posting to make notes of things I found out.


      I encourage others to add to these notes so that the body of knowledge is increased.


      To start, here are the versions of code I used:



      • JBoss server 5.1.0.GA,

      • JBoss Seam 2.2.0.GA,

      • Eclipse JEE Galileo SR1 for Linux.



      When I unpacked the seam archive, the seam-gen script 'seam' was not executable. A quick chmod 750 seam fixed this. Then I ran the commands './seam setup' and './seam create-project'. For this note, I will specify that the project is created in /root/workspace/seamrest.


      You then need to copy the file 'lib/jboss-seam-resteasy.jar' to the lib directory of the project. (e.g. cp lib/jboss-seam-resteasy.jar /root/workspace/seamrest/lib/)


      In your project directory (/root/workspace/seamrest), there is a file named 'deployed-jars.list'. This file must contain the following jar references:



      • jaxrs-api.jar,

      • jboss-seam-resteasy.jar,

      • resteasy-jaxrs.jar.



      These jar files must also be present in the project's lib directory.


      Now you can import the project into eclipse using the File - Import - Existing Projects into Workspace methology.


      Add the JBoss server and associate it with this project.


      Now is a good time to test that the general plumbing works. Start the JBoss application server and check out the following URLs with a browser:


      http://localhost:8080/  -- should return the JBoss AS management screen
      http://localhost:8080/seamrest  -- should return the default seam project welcome page


      If all this works correctly, it is time to add a test REST page.


      Add a package to the src/hot directory. For this note, I will use com.dhc.rest as the package.


      Add a new Java class and name it 'PingService'. Enter the following code, adjusting the package to match your environment.


      package com.dhc.rest;
      
      import javax.ws.rs.GET;
      import javax.ws.rs.Path;
      import javax.ws.rs.core.Response;
      
      import org.jboss.seam.annotations.Name;
      
      @Name("ping")
      @Path("/ping")
      public class PingService {
          @GET
          public Response get() {
              return Response.ok("ping succeeded").build();
          }
      }
      



      Try to access the REST service at http://localhost:8080/seamrest/seam/resource/ping. You should get a web page with 'ping succeeded' on it.


      Important notes:



      1. The need to update the deployed-jars.list file was not one I have seen documented anywhere. Perhaps it is common knowledge for everyone else but it took me some time to find.

      2. The @Name annotation is required for seam to find the service class.

      3. At this point, we have are using all the default values for the REST paths. So our REST service will be located at http://localhost:8080/seamrest/seam/resource/ping. There are good notes in Chapter 24 of the seam manual on how to change this.

      4. You can expand the debugging level of the JBoss server by editing the jboss-log4j.xml file in the server/default/conf directory and changing the value of the org.jboss.seam category to 'DEBUG'. (i.e the xml should be changed to this:



      <category name="org.jboss.seam">
          <priority value="WARN"/>
      </category>
      



      I hope that others find this note useful and I encourage anyone to add to it so that we can expand the pool of knowledge.

        • 1. Re: Getting RESTeasy working with seam-gen and eclipse (my notes)
          ibenjes

          I needed to add





          • resteasy-atom-provider.jar

          • resteasy-jaxb-provider.jar

          • resteasy-jettison-provider.jar



          to the deployed-jars.list. Otherwise I got an exception saying 'Could not find MessageBodyWriter for response ...'


          The deployed-jars.list file is used by the ant buildscript to copy the jars to the deploy directory. So whenever you add a jar add it to the deployed-jars.list as well.


          Another problem I had when using Eclipse is that the deploy task and explode task don't like each other. Best is to add
          this to the explode task:



          <delete file="${deploy.dir}/${project.name}.war"> </delete>



          and this to the deploy task:




          <delete dir="${deploy.dir}/${project.name}.war"> </delete>



          Otherwise you might run into problems that the build scrips can't copy the war file/directory to the deploy directory

          • 2. Re: Getting RESTeasy working with seam-gen and eclipse (my notes)
            iamvijayakumar

            Hi,


            These are the steps I followed to create the RestWebService ear file


            1. Created seam ear project using seam-gen ( using Seam 2.2 )
            2. Then exported this project into Eclipse 3.3.2
            3. Added three 3 jar files jaxrs-api.jar, jboss-seam-resteasy.jar, reateasy-jaxrs.jar into RestWebswervice/WEB-INF/lib
            (  Followed the instructions in http://docs.jboss.org/seam/2.2.0.GA/reference/en-US/html/webservices.htmld0e22078)
            4. From eclipse deployed RestWebService project on JBOss 5.1
            5. Then tried accessing the JAX-RS class using url
            http://localhost:8080/RestWebService/seam/resource/rest/customer/123
            6. Got  HTTP Status 404 error on the browser.


            We tried a simil,ar thing with Seam 2.1 and jboss 4.2.3 but were stuck with the same issue.
            Looks like seam integration with RestEasy is buggy!!
            If anyone has been able to get RestEasy working with seam pls let us Know. We tried it with both Seam 2.1 and Seam 2.2 its not working.


            Thanks
            vijay






            • 3. Re: Getting RESTeasy working with seam-gen and eclipse (my notes)
              lvdberg

              Hi,


              We have it working , but without Eclipse/Seam-gen but Eclipse/maven. Seamgen is great to kick-off your first project, but it is also very helpful to learn how to configure the stuff yourself. The dependency stuff is really complex and sometimes conflicts with the Jboss pre-installed XML libs, but maven helps you solve this problem.


              It can be VERY helpful to unzip the finally created WAR/EAR to see where stuff gets at the end.


              My only wish it that Seam gets Maven as its tool-core in the near future.


              Leo




              • 4. Re: Getting RESTeasy working with seam-gen and eclipse (my notes)
                iamvijayakumar

                HI,
                  can you give much more explain...



                if you give mean it's helpful for me

                • 5. Re: Getting RESTeasy working with seam-gen and eclipse (my notes)
                  iamvijayakumar

                  Leo van den Berg wrote on Sep 20, 2010 06:28:


                  Hi,

                  We have it working , but without Eclipse/Seam-gen but Eclipse/maven. Seamgen is great to kick-off your first project, but it is also very helpful to learn how to configure the stuff yourself. The dependency stuff is really complex and sometimes conflicts with the Jboss pre-installed XML libs, but maven helps you solve this problem.

                  It can be VERY helpful to unzip the finally created WAR/EAR to see where stuff gets at the end.

                  My only wish it that Seam gets Maven as its tool-core in the near future.

                  Leo






                  Click HELP for text formatting instructions. Then edit this text and check the preview.

                  • 6. Re: Getting RESTeasy working with seam-gen and eclipse (my notes)
                    iamvijayakumar




                    • 7. Re: Getting RESTeasy working with seam-gen and eclipse (my notes)
                      lvdberg

                      Hi,


                      The thing we did was to embrace Maven as our build tool and create basically a jar per sub-project. With Maven you define the dependencies and you can create a sort of super-project which contains all important dependencies. Switching Seam (or whatever) versions is as aesy as editing the configuration and Maven will take care of the rest. This doesn't take away programming your beans, but helps to get the configuration right during test AND for deployment.


                      See the Maven website for more information and there are some threads about the subject.


                      Leo