Spring Document URL:
http://docs.spring.io/spring/docs/
Using Hessian
First we'll have the to create a new servlet in your application (this was an excerpt from ' Web. xml '):
<servlet> <Servlet-name>Remoting</Servlet-name> <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class> <Load-on-startup>1</Load-on-startup></servlet><servlet-mapping> <Servlet-name>Remoting</Servlet-name> <Url-pattern>/remoting/*</Url-pattern></servlet-mapping>
Ou ' re probably familiar with Spring's dispatcherservlet principles and if so, your know that's now you'll have the to create a Sp Ring container Configuration resource named ' Remoting-servlet.xml ' (after the name of your servlets) in the ' Web-inf ' Direc Tory.
Alternatively, consider the use of Spring ' s simpler httprequesthandlerservlet. This allows-embed the remote exporter definitions in your root application context (by default in ' Web-inf/applicat Ioncontext.xml '), with individual servlets definitions pointing to specific exporter beans. Each servlet name needs to match the Bean is the name of its target exporter in this case.
In the newly created application context called remoting-servlet.xml
, we ll create a HessianServiceExporter
exporting your services:
<BeanID= "Accountservice"class= "example." Accountserviceimpl "> <!--Any additional properties, maybe a DAO? -</Bean><Beanname= "/accountservice"class= "Org.springframework.remoting.caucho.HessianServiceExporter"> <!--construct the required input parameters - < Propertyname= "Service"ref= "Accountservice"/> <!--interfaces used by server-side clients - < Propertyname= "Serviceinterface"value= "example." Accountservice "/></Bean>
In the latter case, define a corresponding servlets for this exporter ‘web.xml‘
in, with the same end result:the exporter get Ting mapped to the request path /remoting/AccountService
. Note the servlet name needs to match the bean name of the the target exporter.
<servlet> <Servlet-name>Accountexporter</Servlet-name> <Servlet-class>Org.springframework.web.context.support.HttpRequestHandlerServlet</Servlet-class></servlet><servlet-mapping> <Servlet-name>Accountexporter</Servlet-name> <Url-pattern>/remoting/accountservice</Url-pattern></servlet-mapping>
To link in the service on the client, we'll create a separate Spring container, containing the simple object and the servi Ce linking configuration bits:
<Beanclass= "example." Simpleobject "> < Propertyname= "Accountservice"ref= "Accountservice"/></Bean><BeanID= "Accountservice"class= "Org.springframework.remoting.caucho.HessianProxyFactoryBean"> < Propertyname= "serviceurl"value= "Http://remotehost:8080/remoting/AccountService"/> < Propertyname= "Serviceinterface"value= "example." Accountservice "/></Bean>
// Assuming that simpleobject is undefined // the configuration file is named Spring-config-client.xml // the client can use such code to call New Classpathxmlapplicationcontext ("Spring-config-client.xml"= (accountservice) Context.getbean (" Accountservice ");
////POJO for Transport// Public classAccountImplementsserializable{PrivateString name; PublicString GetName () {returnname; } Public voidsetName (String name) { This. Name =name; }}////Server and Client// Public InterfaceAccountservice { Public voidInsertaccount (account account); PublicList<account>getaccounts (String name);}////Server//The implementation doing nothing at the moment Public classAccountserviceimplImplementsAccountservice { Public voidInsertaccount (account ACC) {//Do something ... } PublicList<account>getaccounts (String name) {//Do something ... }}////Client// Public classSimpleobject {PrivateAccountservice Accountservice; Public voidSetaccountservice (Accountservice accountservice) { This. Accountservice =Accountservice; } //additional methods using the Accountservice}
Org.springframework.remoting.caucho.hessianserviceexporter-this exports the specified service as a servlet based HTTP re Quest handler. Hessian services exported by the This class can is accessed by any Hessian client.
Org.springframework.remoting.caucho.hessianproxyfactorybean-this is the factory beans for Hessian clients. The exposed service is configured as a spring bean. The Serviceurl property specifies the service and the Serviceinterface property specifies the interface of the Implemented service.
1.Client sends a message call
2.This message call was handled by a Hessian Proxy created by Hessianproxyfactorybean
3.The Hessian Proxy Converts the call to a remote call over HTTP
4.The Hessian Service Adapter created by Hessianserviceexporter intercepts the remote call over HTTP
5.It forwards the method call to Service
Remoting and Web Services using spring[excerpted from official website]