论坛首页 Java企业应用论坛

Spring发布多协议的远程服务最简单办法

浏览 4510 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-03-23  
Spring发布多协议的远程服务其实比较简单,感觉Spring这方面已经做的好了,自己没必要再去搞些什么服务池。
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>	
   发表时间:2007-03-23  
无所谓了,轻巧的有轻巧的用处,多功能也有多功能的用处.
0 请登录后投票
   发表时间:2007-04-12  
你好,想问你一个问题,有没有什么办法可以获得hessian和burlap传输过程中压缩数据的大小,然后对这两者做个比较好进行选择?
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics