0 Replies Latest reply on Jun 9, 2011 4:36 PM by Eliram Aharon

    Consume Resteasy integrated with EJB

    Eliram Aharon Newbie

      Hi,

       

      I'm new to Restful web services.

      After spending lots of hours understaing how to build a simple server exposes an EJB through Resteasy, I finnaly got JBoss to deploy my app without any error.

       

      Now, I simply don't understand how to consume my service.

      I'm using IntelliJ 10.0.2 Rest Client for that. My project is here.

       

      I have GroupService interface:

      @Local
      @Path("/groups")
      public interface GroupService
      {
          @GET
          @Produces("application/json")
          @Path("/getGroupShapes/{groupName}")
          public String getGroupShapes(@PathParam("groupName")String groupName);
      }
      

      And GroupServiceBean:

      @Local
      @Stateless
      public class GroupServiceBean implements GroupService
      {
          Map<String,WhiteBoardGroup> groups;
        
          public GroupServiceBean()
          {
              groups = new HashMap<String, WhiteBoardGroup>();
              WhiteBoardGroup group = new WhiteBoardGroup("Yariv");
              Oval o = new Oval(-65536, new Point(5,5), new Point(20,20), true);
              Line l = new Line(-65536, new Point(60,60), new Point(90,90));
              group.addShape(o);
              group.addShape(l);
              groups.put(group.getName(), group);        
          }
      
          public String getGroupShapes(@PathParam("groupName") String groupName)
          {
              WhiteBoardGroup group = groups.get(groupName);
              ObjectMapper mapper = new ObjectMapper();
              try {
                  return mapper.writeValueAsString(group.getBorad());
              } catch (IOException e) {
                  e.printStackTrace();
              }
              return "";
           }
      }
      

       

      And a web.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
      
      
         <display-name>Archetype Created Web Application</display-name>
         <context-param>
            <param-name>resteasy.jndi.resources</param-name>
            <param-value>GroupServiceBean/local</param-value>
         </context-param>
      
      
         <listener>
            <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
         </listener>
      
      
          <servlet>
          <servlet-name>Resteasy</servlet-name>
              <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
         </servlet>
      
      
         <servlet-mapping>
            <servlet-name>Resteasy</servlet-name>
            <url-pattern>/*</url-pattern>
         </servlet-mapping>
      
      </web-app>
      

       

      I tried:

      rest-client.jpg

      but I get HTTP 404.

      Does it mean that after all I did not build my ear correctly?