![]() |
| |||||||||||||||||||
| 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 |
Writing a service for the Resin SOA as a plain-old Java object (POJO) eliminates protocol dependencies and simplifies service testing. With the Resin Service-Oriented Architecture, services can be written as plain-old Java objects (POJOs) and made available to many different protocols using simple configuration changes. Files in this tutorial
What is a Service-Oriented Architecture?![]() The Resin Service-Oriented Architecture is an infrastructure that allows a service to be exposed via many different service protocols. For example in this tutorial, there is a plain-old Java object (POJO) that implements a service and this service is made available using REST, SOAP, Hessian, and JNDI. The service is implemented once and these protocols are activated with a few simple changes to the configuration file. Service InterfaceIn this example, the service interface is for a simple Hello, World service.
There is a single method,
package example;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public interface HelloService {
/**
* Returns "hello, world".
*/
@WebMethod
public HelloResult hello();
}
Notice that the service returns a
package example;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name="hello")
public class HelloResult {
@XmlElement
public String value = "hello, world";
public String toString()
{
return value;
}
}
Service ImplementationThe HelloService implementation is just a Java class that implements the HelloService API. For Java Web Service (JAX-WS) compatibility, the class also has @WebService and @WebMethod annotations.
package example;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService(endpointInterface="example.HelloService")
public class HelloServiceImpl implements HelloService {
/**
* Returns "hello, world".
*/
@WebMethod
public HelloResult hello()
{
return new HelloResult();
}
}
Service configurationServices in the Resin SOA are configured with the <servlet>
tag. The implementation class is given as
the To expose the service as a Hessian service, use the <hessian> tag. Hessian is one of the protocols available for web services.
Here a REST interface is also exposed. In this
example, the REST interface uses the default
query-based binding that interprets URLs of the form
Finally, a SOAP interface is available.
<servlet-mapping url-pattern="/hello/hessian/*"
jndi-name="service/HelloService"
servlet-name="hello-hessian"
servlet-class="example.HelloServiceImpl">
<protocol type="hessian"/>
</servlet-mapping>
<servlet-mapping url-pattern="/hello/rest/*"
servlet-name="hello-rest"
servlet-class="example.HelloServiceImpl">
<protocol type="rest"/>
</servlet-mapping>
<servlet-mapping url-pattern="/hello/rest/*"
servlet-name="hello-soap"
servlet-class="example.HelloServiceImpl">
<protocol type="soap"/>
</servlet-mapping>
Client configurationResin also makes it easy to access services using the <web-service-client> tag. This tag connects to a service using a URL of the form <encoding>:<protocol>:<location>. The example below shows just such a URL. The interface of the service and a JNDI name must also be given. The <web-service-client> tag creates a proxy client instance for the service and registers the proxy with the given JNDI name.
<web-service-client jndi-name="hessian/HelloService">
<url>hessian:${webApp.url}/hello/hessian/</url>
<interface>example.HelloService</interface>
</web-service-client>
<web-service-client jndi-name="rest/HelloService">
<url>rest:${webApp.url}/hello/rest/</url>
<interface>example.HelloService</interface>
</web-service-client>
<web-service-client jndi-name="soap/HelloService">
<url>soap:${webApp.url}/hello/soap/</url>
<interface>example.HelloService</interface>
</web-service-client>
JSP Client ScriptThe client can now connect to the HelloService using any supported encoding simply by doing a lookup in JNDI.
<%@ page import="com.caucho.naming.Jndi" %>
<%@ page import="example.HelloService" %>
<%
HelloService hessianHello = (HelloService) Jndi.lookup("hessian/HelloService");
HelloService restHello = (HelloService) Jndi.lookup("rest/HelloService");
HelloService soapHello = (HelloService) Jndi.lookup("soap/HelloService");
HelloService vmHello = (HelloService) Jndi.lookup("service/HelloService");
%>
<pre>
From Hessian: <%= hessianHello.hello() %>
From REST: <%= restHello.hello() %>
From SOAP: <%= soapHello.hello() %>
From VM: <%= vmHello.hello() %>
</pre>
From Hessian: hello, world From REST: hello, world From SOAP: hello, world From VM: hello, world
| |||||||||||||||||||