我有一个用户要求设置每个请求的超时时间,以便用户可以指定Web服务的超时时间。
Client client = ClientProxy.getClient(port);
client.getRequestContext().put("thread.local.request.context", "true");
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setAllowChunking(false);
httpClientPolicy.setAccept("text/xml");
httpClientPolicy.setAcceptEncoding("gzip,deflate,sdch");
httpClientPolicy.setCacheControl("No-Cache");
httpClientPolicy.setContentType("text/xml");
httpClientPolicy.setConnectionTimeout(2000);
httpClientPolicy.setReceiveTimeout(receiveTimeout);
HTTPConduit http = (HTTPConduit) client.getConduit();
http.setClient(httpClientPolicy);
上面的receiveTimeout是一个参数。我发现,如果端口是一个静态变量(所有线程共享),那么在第一个用户设置了receiveTimeout之后,第二个用户将受到此设置的影响。
我要实现的是,如果用户未设置receiveTimeout,它将使用CXF默认值60s,它将受到其他线程的影响。