2017-02-21 6 views
0

短いバージョン: ApacheConnectorProvider + PoolingHttpClientConnectionManagerを使用しているときにカスタムリトライハンドラを設定することはできますか?もしそうなら、どうですか?Apache HTTPクライアントを使用したカスタムの再試行ハンドラ?

ロングバージョン: 私はジャージー2.25.1を使用していると私は最近、私の自動テストフレームワークのスケーリング能力を向上させるためにはApache PoolingHttpClientConnectionManagerにデフォルトのHTTP接続機構に切り替えました。

これは一般的に機能していますが、規模が拡大するにつれて、時折「接続タイムアウト」が発生します。私は、Apache HTTPClientがカスタムリトライハンドラを受け入れる能力を持っていると信じていますが、Jerseyでカスタムハンドラを設定する方法はわかりません。私は多くの検索の試みで例を見つけることができません。

何か類似のものが2年前にHereと尋ねられましたが、答えがありません。ここで

はジャージークライアントのための私の初期化コードです:

SSLContext ctx = initSSLTrustFactory(); 

    Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() 
      .register("http", PlainConnectionSocketFactory.getSocketFactory()) 
      .register("https", new SSLConnectionSocketFactory(ctx, NoopHostnameVerifier.INSTANCE)) 
      .build(); 

    ClientConfig cfg = new ClientConfig(); 

    PoolingHttpClientConnectionManager connMan = new PoolingHttpClientConnectionManager(registry); 
    connMan.setMaxTotal(200); 
    connMan.setDefaultMaxPerRoute(50); 

    if (timeout != -1) { 
     SocketConfig sc = SocketConfig.custom() 
       .setSoTimeout(timeout) 
       .setSoReuseAddress(true) 
       .setTcpNoDelay(true) 
       .setSoReuseAddress(true) 
       .build(); 
     connMan.setDefaultSocketConfig(sc); 
     cfg.property(ApacheClientProperties.REQUEST_CONFIG, RequestConfig 
       .custom() 
       .setConnectTimeout(timeout) 
       .setConnectionRequestTimeout(timeout) 
       .setSocketTimeout(timeout) 
       .build() 
     ); 
    } 
    cfg.property(ApacheClientProperties.CONNECTION_MANAGER, connMan); 

    ApacheConnectorProvider acp = new ApacheConnectorProvider(); 
    cfg.connectorProvider(acp); 

    ClientBuilder builder = JerseyClientBuilder.newBuilder(); 
    client = builder 
      .hostnameVerifier((String hostname, SSLSession session) -> true) 
      .withConfig(cfg) 
      .register(JacksonFeature.class) 
      .register(MultiPartWriter.class) 
      .build(); 

あり、実際のApache HTTPClientの上でそれを設定する1つの方法を示し例HEREがあるが、私は実行する方法が表示されませんジャージーでは同等ですが、私はまだジャージーをカスタマイズする方法を理解しようとしています。

は、私はそれがに似ClientConfigインスタンスで何かをすることによって行って思っただろう:

cfg.property(ApacheClientProperties.RETRY_HANDLER, new HttpRequestRetryHandler() { 

    public boolean retryRequest(
      IOException exception, 
      int executionCount, 
      HttpContext context) { 
     ... 
    } 
    } 
); 

しかし、リトライハンドラクライアントプロパティの設定は存在しません。

ありがとうございました!

答えて

0

RetryHandlersのサポートがバージョン2.26で導入されました。 ApacheClientProperties.RETRY_HANDLERhereを参照してください。

関連する問題