google Analytics

Thursday, September 23, 2010

RestEasy with EJB Integration Example

RestEasy with EJB Example
Using Restfull webservices with EJB

Deployed as EAR folder Structure




=============================================================
 

The code in the WAR project configures RESTEasy. It also registers the EJBs defined
by the EJB project with the JAX-RS runtime.

resteasy.jndi.resources, A comma delimited list of JNDI names which reference objects you want to register as
JAX-RS resources

================================================================================
 <?xml version="1.0" encoding="UTF-8"?>
<web-app>
   <display-name>Created Web Application</display-name>
   <context-param>
      <param-name>resteasy.jndi.resources</param-name>
      <param-value>Spring-RESTEasy/ProductResourceBean/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>


=============================================================================

package com.test;
import javax.ejb.Local;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
/**
 *
 * @author Anish Nath
 *
 */
@Local
@Path("/")
public interface ProductResource
{
   @GET
   @Path("hello")
   @Produces("text/plain")
   String sayHelloWorld();

   @PUT
   @Path("hello")
   @Consumes("text/plain")
   void sayHelloWorld(String body);

}

/**
 * ======================================================================
 * END OF PROGRAM
 */

 package com.test;
import javax.ejb.Stateless;
/**
 *
 * @author ANish Nath
 *
 */
@Stateless(mappedName="productBean")
public class ProductResourceBean implements ProductResource
{
   public String sayHelloWorld()
   {
      System.out.println("sayHelloWorld()");
      return "HelloWorld";
   }
   public void sayHelloWorld(String body)
   {
      System.out.println("sayHelloWorld(anish)");
      System.out.println(body);
   }
}


/**
 * ======================================================================
 *
 */

====================

Helloworld With RestEasy WebServices
JBoss RESTEasy and Spring MVC
REST with Spring
http://opensourceframework.blogspot.com/2010/09/resteasy-and-spring-mvc.html
ANish

3 comments:

  1. Well begun :)
    Also

    http://docs.jboss.org/resteasy/docs/1.0.0.GA/userguide/html_single/index.html#RESTEasy_EJB_Integration

    -- Anish

    ReplyDelete
  2. Hi,Website building involves many types of IT specialists with different technical and creative professional specializations with Web Design Cochin. Web Developers, Web Programmers Web programmers or web developers are web specialists.Thanks....

    ReplyDelete