Hessian Java API Overview

From Resin 3.0

(Difference between revisions)
Jump to: navigation, search
 
 
Line 62: Line 62:
 
     HessianProxyFactory factory = new HessianProxyFactory();
 
     HessianProxyFactory factory = new HessianProxyFactory();
 
     BasicAPI basic = (BasicAPI) factory.create(BasicAPI.class, url);
 
     BasicAPI basic = (BasicAPI) factory.create(BasicAPI.class, url);
 
+
 
     System.out.println("hello(): " + basic.hello());
 
     System.out.println("hello(): " + basic.hello());

Latest revision as of 17:09, 28 March 2006


Contents

[edit] Introduction to Hessian

Creating a Hessian service using Java has four steps:

  1. Create an Java interface as the public API
  2. Create a client using HessianProxyFactory
  3. Create the Service implementation class
  4. Configure the service in your servlet engine.

[edit] The Service API

A Hessian service's API is just a plain old Java interface.

[edit] Hello, World API

 public interface BasicAPI {
     public String hello();
 }

The Hessian protocol eliminates external API descriptions like CORBA IDL files or WSDL. Documenting a Hessian service API is as simple as providing the JavaDoc. Because Hessian is language-independent, the Java interface classes are not required for non-Java languages. For external languages, the Java interfaces serve only to document the service methods.

[edit] Service Implementation

The service implementation can be a plain-old Java object (POJO) or can extend HessianServlet to make the servlet-engine configuration trivial.

[edit] Hello, World Service

public class BasicService extends HessianServlet implements BasicAPI {
      private String _greeting = "Hello, world";

      public void setGreeting(String greeting)
      {
          _greeting = greeting;
      }

      public String hello()
      {
          return _greeting;
      }
 }


The service implementation can also be a plain-old Java object (POJO), avoiding any dependency on HessianServlet. More details are at Hessian introduction and in the [http://www.caucho.com/resin-3.0/protocols/tutorial/hessian-ioc/index.xtp Hessian Service using Dependency Injection] tutorial.

[edit] Client Implementation

Creating a client is as simple as creating an API interface:

[edit] Hello, World Client

   String url = "http://www.caucho.com/hessian/test/basic";

   HessianProxyFactory factory = new HessianProxyFactory();
   BasicAPI basic = (BasicAPI) factory.create(BasicAPI.class, url);

   System.out.println("hello(): " + basic.hello());
Personal tools