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

a frontend client for a hessian service

This tutorial shows how to access services with Resin WebBeans injection. A servlet does frontend presentation for the results of a Hessian web service.


Files in this tutorial

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

Service Interface and Configuration

The service used in this example is the same hello world service used in the simple service tutorial. The interface used by the frontend is shown below.
package example;

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

Configuring the service is also the same as in the the simple service tutorial.

<servlet-mapping url-pattern="/hello/*"

  <protocol uri="hessian:"/>

Frontend Client

The client in this case is simply a servlet that uses J2EE injection to access the service.
package example;

import javax.annotation.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ServiceFrontendServlet extends HttpServlet {
  private HelloService _helloService;

  public void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws IOException, ServletException
    PrintStream out = new PrintStream(resp.getOutputStream());

    out.println("service result: " + _helloService.hello());

Configuring the client is nearly the same as in the the simple service tutorial, the only difference being adding the mapping for the servlet.

Client configuration
<remote-client name="hessian">

<servlet servlet-name="service-frontend" 
         servlet-class="example.ServiceFrontendServlet" />
<servlet-mapping url-pattern="/frontend/" servlet-name="service-frontend" />


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, CNET, DZone and many more are powered by Resin.

home company docs 
app server