<document>
<s1>

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

</s1> <deftable>
Interface for the hello service.
The main service implementation.
Configures the environment
Client JSP
</deftable>

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.

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; } }

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

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

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

<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 jndi-name="hessian/HelloService"> <url>hessian:${webApp.url}/hello/</url> <interface>example.HelloService</interface> </web-service-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.

<%@ 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> <results> From Hessian: hola mundo From VM: hola mundo </results>
</document>