Springマルチプロトコルを発表する遠隔サービスは最も簡単な方法です.

2923 ワード

Springがマルチ契約を発表するリモートサービスは実は比較的に簡単で、Springのこの方面はすでにしたのがよくなったと感じて、自分で更に何かのサービスエリアをする必要はありません.
1.ServiceExport
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>