7 Replies Latest reply on Sep 20, 2010 7:25 AM by Leo van den berg

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

    David Haynes Newbie

      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.