import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.params.HttpClientParams;
import org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor;
import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
import org.springframework.stereotype.Component;
/**
* 作业调度HttpInvoker的FactoryBean
* @author lihaoquan
*
*/
@Component("JobHttpInvokeFactoryBean")
public class JobHttpInvokeFactoryBean {
/**
* 获取FactoryBean代理
* @param serviceInterface
* @param serviceUrl
* @param timeout
* @return
* @throws Exception
*/
public Object getProxy(Class<?> serviceInterface, String serviceUrl,int timeout)
throws Exception {
CommonsHttpInvokerRequestExecutor executor = new CommonsHttpInvokerRequestExecutor();
HttpClient client = executor.getHttpClient();
HttpClientParams params = client.getParams();
params.setConnectionManagerTimeout(timeout);
params.setSoTimeout(timeout);
HttpInvokerProxyFactoryBean factoryBean = new HttpInvokerProxyFactoryBean();
factoryBean.setServiceInterface(serviceInterface);
factoryBean.setServiceUrl(serviceUrl);
factoryBean.setHttpInvokerRequestExecutor(executor);
factoryBean.afterPropertiesSet();
return factoryBean.getObject();
}
}