Configuring a Service on the Resin ESB using JAXB
Resin 3.1

Documentation
Examples
Changes

Quercus
Database
Amber
EJB
SOA/ESB
IoC
JMS
Servlet
JMX
Hessian
Security

Simple Service
Configuring a service with JAXB
An ESB client
Flickr REST
JAX-WS example
Simple Service
SOA/ESB
An ESB client

A service on the Resin ESB can be configured easily using JAXB.

Demo

Services on the Resin ESB can be configured easily using JAXB.

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

Service Implementation

The HelloService implementation for this tutorial still conforms to the same API as in the Simple Service tutorial, but now has an annotated field to allow the hello message to be changed via JAXB configuration.

HelloServiceImpl.java
package example;

import javax.jws.WebMethod;
import javax.jws.WebService;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@WebService(endpointInterface="example.HelloService")
@XmlRootElement
public class HelloServiceImpl implements HelloService {
  @XmlElement(name="hello")
  private String _hello;

  /**
   * Returns "hello, world".
   */
  @WebMethod
  public String hello()
  {
    return _hello;
  }
}

Remote Interface

The Java interface describes the remote API. The API here is the same as in the Simple Service tutorial.

HelloService.java
package example;

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

Service configuration

The configuration of this service is almost identical to the Simple Service tutorial, but now includes data to be unmarshalled into the service. Specifically, the hello field is initialized from the <init> child tag of <web-service>.

<web-service>
<servlet-mapping url-pattern="/hello/*"
                 servlet-class="example.HelloServiceImpl">
                 jndi-name="service/HelloService">

  <init>
    <hello>hola mundo</hello>
  </init>

  <protocol type="hessian"/>
</servlet-mapping>

Since the service API has not changed, the <web-service-client> tag and its contents remain unchanged from the Simple Service tutorial.

<web-service-client>
<web-service-client jndi-name="hessian/HelloService">
  <url>hessian:${webApp.url}/hello/</url>
  <interface>example.HelloService</interface>
</web-service-client>

Java Client

The client can now connect to the HelloService using any supported encoding simply by doing a lookup in JNDI. The message returned now is the one initialized via JAXB.

demo.jsp
<%@ page import="com.caucho.naming.Jndi" %>
<%@ page import="example.HelloService" %>
<%
HelloService hessianHello = (HelloService) Jndi.lookup("hessian/HelloService");
HelloService vmHello = (HelloService) Jndi.lookup("service/HelloService");
%>
<pre>
From Hessian: <%= hessianHello.hello() %>
From VM: <%= vmHello.hello() %>
</pre>
From Hessian: hola mundo
From VM: hola mundo

Demo


Simple Service
SOA/ESB
An ESB client
Copyright © 1998-2006 Caucho Technology, Inc. All rights reserved.
Resin ® is a registered trademark, and Quercustm, Ambertm, and Hessiantm are trademarks of Caucho Technology.