spring document url:

http://docs.spring.io/spring/docs/

Using Hessian

First we’ll have to create a new servlet in your application (this is 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, you know that now you’ll have to create a Spring container configuration resource named 'remoting-servlet.xml' (after the name of your servlet) in the 'WEB-INF' directory.

Alternatively, consider the use of Spring’s simpler HttpRequestHandlerServlet. This allows you to embed the remote exporter definitions in your root application context (by default in 'WEB-INF/applicationContext.xml'), with individual servlet definitions pointing to specific exporter beans. Each servlet name needs to match the bean 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:

<bean id="accountService" class="example.AccountServiceImpl">
<!-- any additional properties, maybe a DAO? -->
</bean> <bean name="/AccountService" class="org.springframework.remoting.caucho.HessianServiceExporter">
  <!-- 构造需要的输入参数 -->
  <property name="service" ref="accountService"/>
<!-- 服务端客户端使用的接口 -->
<property name="serviceInterface" value="example.AccountService"/>
</bean>

In the latter case, define a corresponding servlet for this exporter in 'web.xml', with the same end result: The exporter getting mapped to the request path/remoting/AccountService. Note that the servlet name needs to match the bean name of 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 service linking configuration bits:

<bean class="example.SimpleObject">
<property name="accountService" ref="accountService"/>
</bean> <bean id="accountService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl" value="http://remotehost:8080/remoting/AccountService"/>
<property name="serviceInterface" value="example.AccountService"/>
</bean>
//假设不定义SimpleObject
//配置文件名为spring-config-client.xml
//client可以使用这样的代码调用
ApplicationContext context = new ClassPathXmlApplicationContext("spring-config-client.xml");
AccountService accountService = (AccountService)context.getBean("accountService");
//
//POJO for transport
//
public class Account implements Serializable{ private String name; public String getName(){
return name;
} public void setName(String name) {
this.name = name;
} }
//
//server and client
//
public interface AccountService { public void insertAccount(Account account); public List<Account> getAccounts(String name); }
//
//server
// the implementation doing nothing at the moment
public class AccountServiceImpl implements AccountService { public void insertAccount(Account acc) {
// do something...
} public List<Account> getAccounts(String name) {
// do something...
} }
//
//client
//
public class SimpleObject { private AccountService accountService; public void setAccountService(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 request handler. Hessian services exported by this class can be accessed by any hessian client.
org.springframework.remoting.caucho.HessianProxyFactoryBean - This is the factory bean for Hessian clients. The exposed service is configured as a spring bean. The ServiceUrl property specifies the URL of the service and the ServiceInterface property specifies the interface of the implemented service.

1.Client sends a message call
2.This message call is handled by a Hessian Proxy created by HessianProxyFactoryBean
3.The Hessian Proxy converts the call into 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

最新文章

  1. 简述linux同步与异步、阻塞与非阻塞概念以及五种IO模型
  2. SpringBoot常用配置简介
  3. JavaScript中清空数组的三种方式
  4. bash中不可以用字符串做数组下标
  5. C/C++在Java项目、Android和Objective-C三大平台下实现混合编程
  6. Linux 系统裁剪
  7. 从网站上复制代码到MyEclipse后每行都是字符编码错误的解决办法
  8. 从Keil 4升级到Keil 5的工程,想返回来用Keil 4打开
  9. MySQL支持Emoji表情
  10. 手机金属外壳加工工艺:铸造、锻造、冲压、CNC
  11. Android 的开源电话/通讯/IM聊天项目全集
  12. HDU 4649 Professor Tian
  13. Python 中的用户自定义类型
  14. QT5静态编译教程,主要针对vs2012(渡世白玉)
  15. electron打包vue项目
  16. Jenkins构建自动化脚本执行无界面解决方法
  17. vue 构建项目遇到的请求本地json问题
  18. 《Java大学教程》—第23章 Java网络编程
  19. 《DSP using MATLAB》Problem 5.10
  20. web api 本地测试

热门文章

  1. 利用PHP的register_shutdown_function来记录PHP的输出日志,模拟析构函数
  2. .htaccess 基础教程(四)Apache RewriteCond 规则参数
  3. MongoDB Windows环境安装及配置
  4. MySQL 事物控制和锁定语句
  5. WebService -- Java 实现之 CXF ( 使用CXF工具生成client 程序)
  6. 我与A协
  7. c# 创建xml
  8. 解决NetBeans 8.x的字体问题
  9. Python~recursive function递归函数
  10. asp.net MVC excel数据导出