documentation examples changes amber (jpa) ejb database ioc jmx jsf messaging quercus remoting servlet security hessian serialization hessian addition service addition hessian with di burlap addition custom-protocol simple service client injection | a simple service for resin remoting
Writing a service for the Resin remoting as a plain-old Java object (POJO) eliminates protocol dependencies and simplifies service testing. With the Resin remoting, services can be written as plain-old Java objects (POJOs) and made available to many different protocols using simple configuration changes.
The Resin remoting 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 WebBeans. The service is implemented once and these protocols are activated with a few simple changes to the configuration file. In this example, the service interface is for a simple Hello, World service.
There is a single method, package example; public interface HelloService { /** * Returns "hello, world". */ public String hello(); } The HelloService implementation is just a Java class that implements the HelloService API. It can optionally use EJB annotations like @Remote, @Stateless or @TransactionAttribute. package example; public class HelloServiceImpl implements HelloService { /** * Returns "hello, world". */ public String hello() { return "hello, world"; } } Services for Resin remoting 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. Finally, a SOAP interface is available, using CXF or XFire. <web-app xmlns="http://caucho.com/ns/resin"> <servlet-mapping url-pattern="/hello/hessian/*" servlet-class="example.HelloServiceImpl"> <protocol uri="hessian:"/> </servlet-mapping> </web-app> <web-app xmlns="http://caucho.com/ns/resin"> <servlet-mapping url-pattern="/hello/hessian/*" servlet-class="example.HelloServiceImpl"> <protocol uri="cxf:"/> </servlet-mapping> </web-app> <web-app xmlns="http://caucho.com/ns/resin"> <bean class="example.HelloServiceImpl" name="vm"/> </web-app> Resin also makes it easy to access services using the <remote-client> tag. This tag connects to a service using a URI of the form <protocol>:url=<location>. The example below shows just such a URL. The interface of the service is required. The <remote-client> tag creates a proxy client instance for the service and registers the proxy with WebBeans. <web-app xmlns="http://caucho.com/ns/resin"> <remote-client interface="example.HelloService" name="hessian"> <uri>hessian:url=${webApp.url}/hello/hessian/</uri> </remote-client> <remote-client interface="example.HelloService" name="rest"> <uri>rest:url=${webApp.url}/hello/rest/</uri> </web-service-client> <remote-client interface="example.HelloService" name="soap"> <uri>xfire:url=${webApp.url}/hello/soap/</url> </remote-client> </web-app> The client can now connect to the HelloService using any supported encoding simply by doing a WebBeans injection. <%@ page import="javax.webbeans.Named" %> <%@ page import="example.HelloService" %> <%! @Named("hessian") HelloService _hessianHello; @Named("rest") HelloService _restHello; @Named("soap") HelloService _soapHello; @Named("vm") HelloService _vmHello; %> <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 The client can now connect to the HelloService
using PHP with the <?php $hessian = java_bean("hessian"); $rest = java_bean("rest"); $soap = java_bean("soap"); $vm = java_bean("vm"); ?> <pre> From Hessian: <?= $hessian->hello() ?> From REST: <?= $rest->hello() ?> From SOAP: <?= $soap->hello() ?> From VM: <?= $vm->hello() ?> </pre> From Hessian: hello, world From REST: hello, world From SOAP: hello, world From VM: hello, world
|