2929import java .io .IOException ;
3030
3131import org .apache .hc .client5 .http .HttpRequestRetryStrategy ;
32- import org .apache .hc .client5 .http .HttpRoute ;
3332import org .apache .hc .client5 .http .async .AsyncExecCallback ;
3433import org .apache .hc .client5 .http .async .AsyncExecChain ;
3534import org .apache .hc .client5 .http .async .AsyncExecChainHandler ;
4039import org .apache .hc .core5 .annotation .ThreadingBehavior ;
4140import org .apache .hc .core5 .http .EntityDetails ;
4241import org .apache .hc .core5 .http .HttpException ;
42+ import org .apache .hc .core5 .http .HttpHost ;
4343import org .apache .hc .core5 .http .HttpRequest ;
4444import org .apache .hc .core5 .http .HttpResponse ;
4545import org .apache .hc .core5 .http .nio .AsyncDataConsumer ;
@@ -96,6 +96,7 @@ public AsyncHttpRequestRetryExec(final HttpRequestRetryStrategy retryStrategy) {
9696 private static class State {
9797
9898 volatile boolean retrying ;
99+ volatile int status ;
99100 volatile TimeValue delay ;
100101
101102 }
@@ -125,6 +126,7 @@ public AsyncDataConsumer handleResponse(
125126 }
126127 state .retrying = retryStrategy .retryRequest (response , scope .execCount .get (), clientContext );
127128 if (state .retrying ) {
129+ state .status = response .getCode ();
128130 state .delay = retryStrategy .getRetryInterval (response , scope .execCount .get (), clientContext );
129131 return new DiscardingEntityConsumer <>();
130132 }
@@ -143,9 +145,11 @@ public void completed() {
143145 if (entityProducer != null ) {
144146 entityProducer .releaseResources ();
145147 }
148+ final HttpHost target = scope .route .getTargetHost ();
146149 final TimeValue delay = TimeValue .isPositive (state .delay ) ? state .delay : TimeValue .ZERO_MILLISECONDS ;
147- if (LOG .isDebugEnabled ()) {
148- LOG .debug ("{} wait for {}" , exchangeId , delay );
150+ if (LOG .isInfoEnabled ()) {
151+ LOG .info ("{} {} responded with status {}; request will be automatically re-executed in {}" ,
152+ exchangeId , target , state .status , delay );
149153 }
150154 scope .scheduler .scheduleExecution (
151155 request ,
@@ -162,7 +166,7 @@ public void completed() {
162166 @ Override
163167 public void failed (final Exception cause ) {
164168 if (cause instanceof IOException ) {
165- final HttpRoute route = scope .route ;
169+ final HttpHost target = scope .route . getTargetHost () ;
166170 final HttpClientContext clientContext = scope .clientContext ;
167171 if (entityProducer != null && !entityProducer .isRepeatable ()) {
168172 if (LOG .isDebugEnabled ()) {
@@ -172,10 +176,6 @@ public void failed(final Exception cause) {
172176 if (LOG .isDebugEnabled ()) {
173177 LOG .debug ("{} {}" , exchangeId , cause .getMessage (), cause );
174178 }
175- if (LOG .isInfoEnabled ()) {
176- LOG .info ("Recoverable I/O exception ({}) caught when processing request to {}" ,
177- cause .getClass ().getName (), route );
178- }
179179 scope .execRuntime .discardEndpoint ();
180180 if (entityProducer != null ) {
181181 entityProducer .releaseResources ();
@@ -184,8 +184,10 @@ public void failed(final Exception cause) {
184184 final int execCount = scope .execCount .incrementAndGet ();
185185 state .delay = retryStrategy .getRetryInterval (request , (IOException ) cause , execCount - 1 , clientContext );
186186 final TimeValue delay = TimeValue .isPositive (state .delay ) ? state .delay : TimeValue .ZERO_MILLISECONDS ;
187- if (LOG .isDebugEnabled ()) {
188- LOG .debug ("{} wait for {}" , exchangeId , delay );
187+ if (LOG .isInfoEnabled ()) {
188+ LOG .info ("{} recoverable I/O exception ({}) caught when sending request to {};" +
189+ "request will be automatically re-executed in {}" ,
190+ exchangeId , cause .getClass ().getName (), target , delay );
189191 }
190192 scope .scheduler .scheduleExecution (
191193 request ,
0 commit comments