/
hessian-client.xml
73 lines (67 loc) · 3.67 KB
/
hessian-client.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<properties>
<description>
<![CDATA[
bboss hessian服务发布实例.
hessian属性说明:
hessian:api 服务接口
hessian:serializable xml|bin 序列化类型,默认为bin
hessian:debug default false used by serializable="bin".
hessian:sendCollectionType used by serializable="bin". default true Set whether to send the Java collection type for each serialized collection.
hessian:serializerFactory used by serializable="bin".default com.caucho.hessian.io.SerializerFactory
服务部署说明:
在web.xml文件中配置HessionDispatchServlet
<servlet>
<servlet-name>HessionRemote</servlet-name>
<servlet-class>org.frameworkset.spi.remote.hession.HessionDispatchServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HessionRemote</servlet-name>
<url-pattern>/hessian</url-pattern>
</servlet-mapping>
客户端调用示例:
String url = "http://localhost:8080/context/hessian?container=bboss.hessian.mvc&containertype=mvc&service=basicservice";//指定容器标识和容器类型及服务标识
url = "http://localhost:8080/context/hessian?service=basicservice";//默认获取mvc容器中的组件
url参数说明:
container:服务端ioc容器标识,一般是ioc容器根xml文件对应的类包路径,
例如:org/frameworkset/spi/remote/hession/server/hessian-service.xml
mvc类型容器值为bboss.hessian.mvc(也是container的默认值)
containertype: 容器类型
mvc mvc容器
simple 对应ioc容器类型为DefaultApplicationContext
其他值 对应ioc容器类型为ApplicationContext
service:服务标识,ioc组件的名称
创建bin模式客户端代理
HessianProxyFactory factory = new HessianProxyFactory();
ServiceInf basic = (ServiceInf) factory.create(org.frameworkset.spi.remote.hession.server.ServiceInf.class, url);
System.out.println("Hello: " + basic.hello("John"));
创建xml模式客户端代理
BurlapProxyFactory factory = new BurlapProxyFactory();
ServiceInf basic = (ServiceInf) factory.create(org.frameworkset.spi.remote.hession.server.ServiceInf.class, url);
System.out.println("Hello: " + basic.hello("John"));
通过bboss-ioc配置和获取客户端
<property name="clientservice" factory-class="com.caucho.hessian.client.HessianProxyFactory"
f:connectionTimeout="360000"
f:readTimeout="36000"
factory-method="create">
<construction>
<property value="org.frameworkset.spi.remote.hession.server.ServiceInf"/>
<property value="http://localhost:8080/context/hessian?service=basicservice"/>
</construction>
</property>
DefaultApplicationContext context = DefaultApplicationContext.getApplicationContext("org/frameworkset/spi/remote/hession/client/hessian-client.xml");
//获取客户端组件实例
ServiceInf basic = context.getTBeanObject("clientservice", ServiceInf.class);
]]>
</description>
<!--
使用bboss工厂模式,调用HessianProxyFactory的create方法创建hessian服务客户端调用组件
同时我们可以采用bboss ioc依赖注入特征,将hessian客户端的相关参数(connectionTimeout,readTimeout等)设置到HessianProxyFactory
中
-->
<property name="clientservice" factory-class="com.caucho.hessian.client.HessianProxyFactory" factory-method="create">
<construction>
<property value="org.frameworkset.spi.remote.hession.server.ServiceInf"/>
<property value="http://localhost:8080/test/hessian?service=basicservice"/>
</construction>
</property>
</properties>