Remoting and Web Services using spring[excerpted from official website]

Source: Internet
Author: User

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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.