Caucho maker of Resin Server | Application Server (Java EE Certified) and Web Server


 

Resin Documentation

home company docs 
app server 
 Resin Server | Application Server (Java EE Certified) and Web Server
 

hessian service


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

Demo

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

FILEDESCRIPTION
WEB-INF/classes/example/MathService.javaInterface for the math service.
WEB-INF/classes/example/MathServiceImpl.javaThe main service implementation.
WEB-INF/resin-web.xmlConfigures the environment
demo.jspClient JSP
demo.phpClient PHP

Service Implementation

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

Example: 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.

Example: MathService.java
package example;

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

Service configuration

Example: resin-web.xml
<web-app xmlns="http://caucho.com/ns/resin">

  <servlet-mapping url-pattern="/math/*"
                   servlet-class="example.MathService">
    <protocol uri="hessian:"/>
  </servlet-mapping>

  <remote-client name="math">
    <uri>hessian:url=${webApp.url}/math/</uri>
    <interface>example.MathService</interface>
  </remote-client>

</web-app>

Java Client

The client is identical to the basic example.

Example: demo.jsp
<%@ page import="javax.webbeans.In" %>
<%@ page import="example.MathService" %>
<%!
@In MathService math;
%>
<pre>
3 + 2 = <%= math.add(3, 2) %>
3 - 2 = <%= math.sub(3, 2) %>
3 * 2 = <%= math.mul(3, 2) %>
3 / 2 = <%= math.div(3, 2) %>
</pre>
3 + 2 = 5
3 - 2 = 1
3 * 2 = 6
3 / 2 = 1

PHP Client

The client is identical to the basic example.

Example: demo.php
<?php

$math = java_bean("math");
?>
<pre>
3 + 2 = <?= $math->add(3, 2) ?>
3 - 2 = <?= $math->sub(3, 2) ?>
3 * 2 = <?= $math->mul(3, 2) ?>
3 / 2 = <?= $math->div(3, 2) ?>
</pre>
3 + 2 = 5
3 - 2 = 1
3 * 2 = 6
3 / 2 = 1

Demo


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

Cloud-optimized Resin Server is a Java EE certified Java Application Server, and Web Server, and Distributed Cache Server (Memcached).
Leading companies worldwide with demand for reliability and high performance web applications including SalesForce.com, CNET, DZone and many more are powered by Resin.

home company docs 
app server