Xfire调用webservice设置连接超时

private static long TIME_OUT = 15000L;
private static int RETRY_TIMES = 1;
private static int SO_TIMEOUT = 20000;

private <T> T commonInitWebService(String serviceURL, final Class<T> clazz)
throws MalformedURLException {
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
.newInstance().getXFire());
org.codehaus.xfire.service.Service srvcModel = new ObjectServiceFactory()
.create(clazz);
T service = (T) factory.create(srvcModel, serviceURL);
HttpClientParams params = new HttpClientParams();

params.setParameter(HttpClientParams.USE_EXPECT_CONTINUE,
Boolean.FALSE);

params.setParameter(HttpClientParams.CONNECTION_MANAGER_TIMEOUT,
TIME_OUT);// 单位是毫秒

params.setParameter(HttpClientParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(RETRY_TIMES, false));
params.setParameter(HttpClientParams.SO_TIMEOUT, SO_TIMEOUT);

Client c = Client.getInstance(service);
c.setProperty(CommonsHttpMessageSender.HTTP_CLIENT_PARAMS, params);
c.setProperty(CommonsHttpMessageSender.HTTP_TIMEOUT, SO_TIMEOUT);
return service;
}

你可能感兴趣的:(webservice)