| ||||||||||||||||||
Resin 3.1 Documentation Examples Changes Quercus Database Amber EJB SOA/ESB IoC JMS Servlet JMX Hessian Security Hessian Serialization Hessian Addition Service Addition Hessian with DI Burlap Addition custom-protocol |
Writing a Hessian service as a plain-old Java object (POJO) eliminates protocol dependencies and simplifies service testing. 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
Service ImplementationThe MathService implementation is just a Java class that implements the MatchService API. package example; import javax.jws.WebService @WebService public class MathServiceImpl implements MathService { public int add(int a, int b) { return a + b; } } Remote InterfaceThe Java interface describes the remote API. This example has an addition method, .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. package example; public interface MathService { public int add(int a, int b); } Service configuration<web-app xmlns="http://caucho.com/ns/resin"> <servlet-mapping url-pattern="/math/*" servlet-class="example.MathService"> <protocol type="hessian"/> </servlet-mapping> <web-service-client jndi-name="hessian/MathService"> <url>hessian:http://localhost:8080/resin-doc/hessian/tutorial/hessian-service/math/</url> <interface>example.MathService</interface> </web-service-client> </web-app> Java ClientThe client is identical to the basic example. <%@ page import="javax.annotation.Resource" %> <%@ page import="example.MathService" %> <%! @Resource(name="hessian/MathService") 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
|