Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.apache.hc.client5.http.classic.HttpClient;
import org.apache.hc.client5.http.config.ConnectionConfig;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.DefaultHttpRequestRetryStrategy;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.client5.http.impl.classic.HttpClients;
Expand All @@ -24,8 +25,11 @@
import org.apache.hc.client5.http.ssl.NoopHostnameVerifier;
import org.apache.hc.client5.http.ssl.TlsSocketStrategy;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpRequestInterceptor;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.io.SocketConfig;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.util.Timeout;

import com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationAccessException;
Expand Down Expand Up @@ -92,6 +96,7 @@ private CloseableHttpClient buildHttpClient(
.custom()
.setConnectionManager(getConnectionManager(destination))
.setDefaultRequestConfig(requestConfig)
.setRetryStrategy(new LoggingHttpRequestRetryStrategy(destination))
.setProxy(getProxy(destination));

if( requestInterceptor != null ) {
Expand Down Expand Up @@ -233,4 +238,42 @@ private boolean isValidProxyConfigurationUriInDestination( @Nullable final HttpD
}
return true;
}

private static class LoggingHttpRequestRetryStrategy extends DefaultHttpRequestRetryStrategy
{
final @Nullable HttpDestinationProperties destination;

public LoggingHttpRequestRetryStrategy( final @Nullable HttpDestinationProperties destination )
{
super();
this.destination = destination;
}

@Override
public boolean retryRequest( final HttpResponse response, final int execCount, final HttpContext context )
{
final boolean retry = super.retryRequest(response, execCount, context);
if( retry ) {
final String msg = "Retrying request for destination {} due to response {}. Retry attempt #{}.";
log.debug(msg, destination, response.getCode(), execCount);
}
return retry;
}

@Override
public boolean retryRequest(
final HttpRequest req,
final IOException exception,
final int execCount,
final HttpContext context )
{
final boolean retry = super.retryRequest(req, exception, execCount, context);
if( retry ) {
final String msg =
"Retrying {} request for destination {} to {} due to exception \"{}\". Retry attempt #{}.";
Comment thread
newtork marked this conversation as resolved.
Outdated
log.debug(msg, req.getMethod(), destination, req.getRequestUri(), exception.getMessage(), execCount);
Comment thread
newtork marked this conversation as resolved.
Outdated
}
return retry;
}
}
}