Caucho Technology

amber (jpa)

hessian serialization
hessian addition
service addition
hessian with di
burlap addition
simple service
client injection

a simple service for resin remoting

Writing a service for the Resin remoting as a plain-old Java object (POJO) eliminates protocol dependencies and simplifies service testing.


With the Resin remoting, services can be written as plain-old Java objects (POJOs) and made available to many different protocols using simple configuration changes.

See Also

Files in this tutorial

WEB-INF/classes/example/HelloService.javaInterface for the hello service.
WEB-INF/classes/example/HelloServiceImpl.javaThe main service implementation.
WEB-INF/resin-web.xmlConfigures the environment
demo.jspClient JSP
demo.phpClient PHP


The Resin remoting is an infrastructure that allows a service to be exposed via many different service protocols. For example in this tutorial, there is a plain-old Java object (POJO) that implements a service and this service is made available using REST, SOAP, Hessian, and WebBeans. The service is implemented once and these protocols are activated with a few simple changes to the configuration file.

Service Interface

In this example, the service interface is for a simple Hello, World service. There is a single method, hello() that the service must implement and the client may invoke.
package example;

public interface HelloService {
   * Returns "hello, world".
  public String hello();

Service Implementation

The HelloService implementation is just a Java class that implements the HelloService API. It can optionally use EJB annotations like @Remote, @Stateless or @TransactionAttribute.
package example;

public class HelloServiceImpl implements HelloService {
   * Returns "hello, world".
  public String hello()
    return "hello, world";

Service configuration

Services for Resin remoting are configured with the <servlet> tag. The implementation class is given as the servlet-class attribute. It is possible to allow access to the service within the same virtual machine by registering the service as a WebBeans singleton with <bean>.

To expose the service as a Hessian service, use the <hessian> tag. Hessian is one of the protocols available for web services.

Finally, a SOAP interface is available, using CXF or XFire.

remoting service for hessian
<web-app xmlns="">

  <servlet-mapping url-pattern="/hello/hessian/*"
    <protocol uri="hessian:"/>

remote service for CXF
<web-app xmlns="">

  <servlet-mapping url-pattern="/hello/hessian/*"
    <protocol uri="cxf:"/>

service as WebBeans singleton
<web-app xmlns="">

  <bean class="example.HelloServiceImpl" name="vm"/>


Client configuration

Resin also makes it easy to access services using the <remote-client> tag. This tag connects to a service using a URI of the form <protocol>:url=<location>. The example below shows just such a URL. The interface of the service is required. The <remote-client> tag creates a proxy client instance for the service and registers the proxy with WebBeans.

<web-app xmlns="">

  <remote-client interface="example.HelloService" name="hessian">

  <remote-client interface="example.HelloService" name="rest">

  <remote-client interface="example.HelloService" name="soap">


JSP Client Script

The client can now connect to the HelloService using any supported encoding simply by doing a WebBeans injection.

<%@ page import="javax.webbeans.Named" %>
<%@ page import="example.HelloService" %>
@Named("hessian") HelloService _hessianHello;
@Named("rest") HelloService _restHello;
@Named("soap") HelloService _soapHello;
@Named("vm") HelloService _vmHello;
From Hessian: <%= _hessianHello.hello() %>
From REST: <%= _restHello.hello() %>
From SOAP: <%= _soapHello.hello() %>
From VM: <%= _vmHello.hello() %>
From Hessian: hello, world
From REST: hello, world
From SOAP: hello, world
From VM: hello, world

PHP Client Script

The client can now connect to the HelloService using PHP with the java_bean() method.

$hessian = java_bean("hessian");
$rest = java_bean("rest");
$soap = java_bean("soap");
$vm = java_bean("vm");
From Hessian: <?= $hessian->hello() ?>
From REST: <?= $rest->hello() ?>
From SOAP: <?= $soap->hello() ?>
From VM: <?= $vm->hello() ?>
From Hessian: hello, world
From REST: hello, world
From SOAP: hello, world
From VM: hello, world


Copyright © 1998-2008 Caucho Technology, Inc. All rights reserved.
Resin ® is a registered trademark, and Quercustm, Ambertm, and Hessiantm are trademarks of Caucho Technology.