原来作的一个项目因为页面跳转比较多,应用了Spring Web Flow 项目作视图的页面流转控制,关于Spring Web Flow的介绍可以参考我的另一篇文章:
http://lib.iteye.com/blog/299142,最近需要在项目中引用WebService 远程服务的机制供其他系统调用,比较了一些这方面的开源项目,发现Hessian配置简单,性能优异,决定集成Hessian到这个项目中。
本来Hessaion的配置是比较简单的,很多文章都有介绍,主要是在web.xml中配置Servlet,然后配置ServiceBean就可以了,这方面的文章Google一下会很多,不在这里介绍。我的项目中因为用到了Spring Web Flow,通过org.springframework.web.servlet.DispatcherServlet为 Spring Web Flow 控制器作了定义,与Hessian的servlet造成了冲突,使Hessian不能正常工作。经过研究发现需要通过Spring Web Flow的 UrlHandler 对Hessian的请求分配相应的控制器才可以正确的响应。
以下
Spring Web Flow中介绍的例子集成 Hessian 的例子:
服务端代码:
package samples.hessian;
public interface WebServiceSample {
public String say(String hello);
}
package samples.hessian;
public class WebServiceSampleImpl implements WebServiceSample{
public String say(String hello) {
return hello + " world!";
}
}
修改webmvc-config.xml文件,增加ServiceBean的定义,及 Hessian 对应的控制器:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean
id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView">
</property>
<property name="prefix" value="/WEB-INF/jsp/">
</property>
<property name="suffix" value=".jsp">
</property>
</bean>
<bean
id="viewMappings"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<!-- /shopping.do 请求由 flowController 来处理 -->
<property name="mappings">
<value> /shopping=flowController </value>
<!-- hessian 测试实例 为Hessian的Url请求分配对应的处理器 -->
<value> /webServiceHessianSample=webServiceHessianExporter </value>
</property>
<property name="defaultHandler">
<!-- UrlFilenameViewController 会将 "/index" 这样的请求映射成名为 "index" 的视图 -->
<bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
</property>
</bean>
<bean
id="flowController"
class="org.springframework.webflow.mvc.servlet.FlowController">
<property name="flowExecutor" ref="flowExecutor"/>
</bean>
<!-- hessian 测试实例 ServiceBean 的定义 -->
<bean id="webServiceHessianSample" class="samples.hessian.WebServiceSampleImpl"></bean>
<bean name="webServiceHessianExporter"
class="org.springframework.remoting.caucho.HessianServiceExporter">
<property name="service" ref="webServiceHessianSample" />
<property name="serviceInterface" value="samples.hessian.WebServiceSample" />
</bean>
</beans>
单元测试代码:
package test.sample;
import java.net.MalformedURLException;
import junit.framework.Assert;
import junit.framework.TestCase;
import cn.org.coral.sample.hessian.WebServiceSample;
import com.caucho.hessian.client.HessianProxyFactory;
public class TestHessian extends TestCase {
public void testSay() throws MalformedURLException {
String url = "http://localhost:8080/coral/spring/webServiceHessianSample";
HessianProxyFactory factory = new HessianProxyFactory();
WebServiceSample sample = (WebServiceSample) factory.create(
WebServiceSample.class, url);
//System.out.print(sample.say("hello"));
Assert.assertEquals(sample.say("hello"), "hello world!");
}
}
另外,需要注意的地方,我使用的是 hessian 版本是hessian-3.1.5.jar,使用最新的有问题,可能api发生了变化,还未仔细研究。hessian 的下载地址是:
http://hessian.caucho.com/
例子源代码见附件
分享到:
相关推荐
NULL 博文链接:https://wo-niu.iteye.com/blog/2200720
Spring集成Hessian案例
使用eclipse maven工程搭建hessian远程服务demo 分服务端的整合和客户端 建议阅读相关博客http://blog.csdn.net/heisemuyangquan/article/details/79460528
struts2+ibatis+spring+Hessian 整合项目 web项目整合,服务端用hessian协议远程调用服务端的方法,hessian是用spring代理整合,struts2+ibatis+spring的整合项目,用作学习和开发基础平台构建很有用处,工程导入...
1.名称:Spring + Hessian + Spring MVC(包括Server和Client).zip 2.来源:自己实现 3.备注:项目有两个系统,包括Server端和Client端,项目已经跑通,可以实现。 4.注意:client中pom.xml里最后的一个jar包,需要...
org.springframework.remoting.caucho.Hessian1SkeletonInvoker.class org.springframework.remoting.caucho.Hessian2SkeletonInvoker.class org.springframework.remoting.caucho.HessianClientInterceptor.class ...
Hessian是一个轻量级的remoting onhttp工具,使用简单的方法提供了RMI的功能。 相比WebService,Hessian更简单、快捷。采用的是二进制RPC协议,因为采用的是二进制协议,所以它很适合于发送二进制数据。参考文档地址...
一个Spring整合Hessian的Demo,同时包含Hessian服务端与客户端。是一个Maven工程,IDE使用的Eclipse,运行前需要安装Eclipse的Maven插件。可以结合文章一起学习,地址是...
NULL 博文链接:https://ml5858258-sina-com.iteye.com/blog/1260842
SpringMVC整合Hessian的简单案例,使用Maven管理,idea工具开发,案例中配置了两个接口的服务发布
Hessian与spring整合的dome
maven-spring-hessian 带有 Hessian 的 Hello world Spring Web 应用程序
Hessian与Spring整合需要jar包,需要的同学进行下载学习
Hessian矩阵以及在血管增强中的应用—OpenCV3和c++版本,我用的是vs2015,大家如果不是vs2015,可以直接把工程里面cpp和.h文件三个文件复制到自己新建的工程就可以使用。
这是Hessian和Spring集成的示例,具体步骤请参考本人博客: http://blog.csdn.net/jjasun/article/details/29593083
spring aop hessian 基础demo 部署即可运行
hessian与spring整合的jar包
远程方法调用的比较,Hessian方法的介绍和相关配置.Hessian是一个轻量级的remoting on http工具,采用的是Binary RPC协议,所以它很适合于发送二进制数据,同时...这个文件可以是hessian在spring项目和web项目的简单配置
Hessian协议是http://caucho.com/公司开发的一种实用的web服务技术,它采用二进制数据,传输效率比较高,简单易用,是C#.NET/IIS环境快速开发web服务应用的一种解决方案。本资源中包含Hessian协议的C#版源代码,由于...