我的应用正在使用cxf 2.7.11服务。只要主机服务器在readtimeout客户端内断开/重置连接,客户端就会重试该请求。
我遇到的一个博客说:“ HTTP仍然将HTTP请求传输到目标服务器时,HttpClient会自动重试那些因传输异常而失败的方法的5倍”
我的目的是停止重试。以下是我的客户端配置代码。请让我知道如何停止重试。
Client clientPort = ClientProxy.getClient(binder);
//Added to test stop retry but not working--start
HttpMethodRetryHandler retryhandler = new DefaultHttpMethodRetryHandler(0,false);
client.getRequestContext().put(HttpMethodParams.RETRY_HANDLER,retryhandler);
//Added to test stop retry but not working--END
client.getRequestContext().put(Message.ENDPOINT_ADDRESS,url);
client.getRequestContext().put("soap.no.validate.parts", "true");
client.getRequestContext().put("set-jaxb-validation-event-handler", "false");
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(3000);
httpClientPolicy.setReceiveTimeout(100000);
httpClientPolicy.setAllowChunking(false);
http.setClient(httpClientPolicy);
我也尝试过FailoverFeature,但是没有运气。
FailoverFeature failoverFeature = new FailoverFeature();
RetryStrategy failoverStrategy = new RetryStrategy();
List<String> alternateAddress=new ArrayList<String>();
alternateAddress.add(url);
failoverStrategy.setAlternateAddresses(alternateAddress);
failoverStrategy.setMaxNumberOfRetries(0);
failoverStrategy.setDelayBetweenRetries(2000);
failoverFeature.setStrategy(failoverStrategy);
failoverFeature.initialize(client,client.getBus());