Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 #{}.";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Retrying {} request for destination {} to {} due to exception \"{}\". Retry attempt #{}.";
"Retrying {} request to {} due to exception \"{}\". Retry attempt #{}.";

since destination can be null and may not add much information if the URL is absolute (is it?). Alternatively, explicit null check to avoid strange looking log?

log.debug(msg, req.getMethod(), destination, req.getRequestUri(), exception.getMessage(), execCount);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be at least warn, maybe even error

Suggested change
log.debug(msg, req.getMethod(), destination, req.getRequestUri(), exception.getMessage(), execCount);
log.warn(msg, req.getMethod(), destination, req.getRequestUri(), exception.getMessage(), execCount);

}
return retry;
}
}
}