Hessian Service
Resin 3.0

Features
Installation
Configuration
Web Applications
IOC/AOP
Resources
JSP
Quercus
Servlets and Filters
Databases
Admin (JMX)
CMP
EJB
Amber
EJB 3.0
Security
XML and XSLT
XTP
JMS
Performance
Protocols
Third-party
Troubleshooting/FAQ

Hessian
Hessian Messaging
Hessian 1.0 spec
Hessian 2.0 draft spec
Java Binding
Burlap
Burlap 1.0 Spec
Burlap Design Notes
Tutorials

Hessian Addition
Service Addition
Hessian with DI
Burlap Addition
custom-protocol
Hessian Addition
Tutorials
Hessian with DI

Find this tutorial in: /usr/local/resin/webapps/resin-doc/protocols/tutorial/hessian-service
Try the Tutorial

Writing a Hessian service as a plain-old Java object (POJO) eliminates protocol dependencies and simplifies service testing.

  1. Files in this tutorial
  2. Service Implementation
  3. Remote Interface
  4. Service configuration
  5. Java Client

The addition example built the Hessian service as an extension of HessianService for simplicity. Most services will want to be independent of the Hessian protocol itself.

Files in this tutorial

WEB-INF/classes/example/MathService.java Interface for the math service.
WEB-INF/classes/example/MathServiceImpl.java The main service implementation.
WEB-INF/web.xml Configures the environment
demo.jsp Client JSP

Service Implementation

The MathService implementation is just a Java class that implements the MatchService API.

MathServiceImpl.java
package example;

public class MathServiceImpl implements MathService {
  public int add(int a, int b)
  {
    return a + b;
  }
}

Remote Interface

The Java interface describes the remote API. This example has an addition method, add().

Resin's proxy client implementation uses the remote interface to expose the API to the proxy stub. Strictly speaking, though, the Java remote interface is not required for Hessian. A non-Java client will not use the Java interface, except possibly as documentation.

MathService.java
package example;

public interface MathService {
  public int add(int a, int b);
}

Service configuration

web.xml
<servlet servlet-name="hessian"
         servlet-class="com.caucho.hessian.server.HessianServlet">
  <init-param service-class="example.MathServiceImpl"/>
  <init-param api-class="example.MathService"/>
</servlet>

Java Client

The client is identical to the basic example.

client.jsp
<%@ page import="com.caucho.hessian.client.HessianProxyFactory" %>
<%@ page import="example.MathService" %>
<%
HessianProxyFactory factory = new HessianProxyFactory();

// http://localhost:8080/resin-doc/protocols/tutorial/hessian-service/hessian/math

String url = ("http://" +
              request.getServerName() + ":" + request.getServerPort() +
              request.getContextPath() + "/hessian/math");

MathService math = (MathService) factory.create(MathService.class, url);

out.println("3 + 2 = " + math.add(3, 2));
%>

3 + 2 = 5

Try the Tutorial


Hessian Addition
Tutorials
Hessian with DI
Copyright © 1998-2006 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.