2007-03-23
Spring发布多协议的远程服务最简单办法
Spring发布多协议的远程服务其实比较简单,感觉Spring这方面已经做的好了,自己没必要再去搞些什么服务池。
1.ServiceExporter
2.把接口发布为多协议远程服务
1.ServiceExporter
public class ServiceExporter extends RemoteExporter
implements Controller, InitializingBean {
/**
*访问协议属性
*/
public static final String REMOTE_EXPORTER = "RemoteExporter";
/**
*访问协议hession
*/
public static final String HESSIAN_SERVICE_EXPORTER = "HessianServiceExporter";
HessianServiceExporter hessian=new HessianServiceExporter();
/**
*访问协议HttpInvoker
*/
public static final String HTTP_INVOKER_SERVICE_EXPORTER = "HttpInvokerServiceExporter";
HttpInvokerServiceExporter httpInvoker=new HttpInvokerServiceExporter();
/**
*访问协议Burlap
*/
public static final String BURLAP_SERVICE_EXPORTER = "BurlapServiceExporter";
BurlapServiceExporter burlap=new BurlapServiceExporter();
public void setService(Object service) {
super.setService(service);
hessian.setService(service);
httpInvoker.setService(service);
burlap.setService(service);
}
public void setServiceInterface(Class serviceInterface) {
super.setServiceInterface(serviceInterface);
hessian.setServiceInterface(serviceInterface);
httpInvoker.setServiceInterface(serviceInterface);
burlap.setServiceInterface(serviceInterface);
}
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception{
//检查访问协议属性
String remoteExporter = request.getHeader(ServiceExporter.REMOTE_EXPORTER);
// 访问协议Hessian
if(remoteExporter==null) {
hessian.handleRequest(request,response);
return null;
}
//访问协议HttpInvoker
if(remoteExporter.equalsIgnoreCase(ServiceExporter.HTTP_INVOKER_SERVICE_EXPORTER))
httpInvoker.handleRequest(request,response);
//访问协议Burlap
else if(remoteExporter.equalsIgnoreCase(ServiceExporter.BURLAP_SERVICE_EXPORTER))
burlap.handleRequest(request,response);
//访问协议Hessian
else
hessian.handleRequest(request,response);
return null;
}
public void afterPropertiesSet() throws Exception {
hessian.afterPropertiesSet();
burlap.afterPropertiesSet();
httpInvoker.afterPropertiesSet();
}
2.把接口发布为多协议远程服务
<bean name="/log/BusinessLogMessageService" class="bpo.ServiceExporter"> <property name="service" ref="log.BusinessLogMessageBPOTx"/> <property name="serviceInterface" value="log.ILogMessageService"/> </bean>
- 浏览: 21372 次
- 性别:

- 来自: 深圳

- 详细资料
搜索本博客
最近加入圈子
最新评论
-
对 Wicket 的新认识
wicket确实令人着迷
-- by deadlock -
Web框架对比: Wicket vs ...
struts 没spring mvc好使 :idea:
-- by hqman -
Web框架对比: Wicket vs ...
struts没有活路了吗? 苦于没有WICKET站收录,如果有的话请登记到 h ...
-- by eltonto -
Web框架对比: Wicket vs ...
简单的试了一下,wicket真是不错啊。看来struts真的可以安心的去了。
-- by blueclothes -
Web框架对比: Wicket vs ...
JSF的View还是完全基于标签的 这个我觉得很难和美工协作 Tapestry ...
-- by wl95421






评论排行榜