Skip to content

Commit

Permalink
LDEV-5083 - add retryRequest handler
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Aug 29, 2024
1 parent be809c9 commit 680a3ae
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.apache.http.client.AuthCache;
import org.apache.http.client.CookieStore;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpDelete;
Expand Down Expand Up @@ -92,6 +93,7 @@

import lucee.commons.io.IOUtil;
import lucee.commons.io.TemporaryStream;
import lucee.commons.io.log.Log;
import lucee.commons.io.log.LogUtil;
import lucee.commons.io.res.Resource;
import lucee.commons.lang.ExceptionUtil;
Expand Down Expand Up @@ -292,20 +294,25 @@ public static HttpClientBuilder getHttpClientBuilder(boolean pooling, String cli

PoolingHttpClientConnectionManager cm = connectionManagers.get(key);
if (cm == null || isShutDown(cm, true)) {

// if (connMan == null || isShutDown(true)) {
cm = new PoolingHttpClientConnectionManager(new DefaultHttpClientConnectionOperatorImpl(reg), null, POOL_CONN_TTL_MS, TimeUnit.MILLISECONDS);
cm.setDefaultMaxPerRoute(POOL_MAX_CONN_PER_ROUTE);
cm.setMaxTotal(POOL_MAX_CONN);
cm.setDefaultSocketConfig(SocketConfig.copy(SocketConfig.DEFAULT).setTcpNoDelay(true).setSoReuseAddress(true).setSoLinger(0).build());
cm.setValidateAfterInactivity(POOL_CONN_INACTIVITY_DURATION);
// }

// cm.setValidateAfterInactivity(POOL_CONN_INACTIVITY_DURATION);
connectionManagers.put(key, cm);
}
HttpClientBuilder builder = HttpClients.custom();
builder.setConnectionManager(cm).setConnectionManagerShared(true).setConnectionTimeToLive(POOL_CONN_TTL_MS, TimeUnit.MILLISECONDS)
.setConnectionReuseStrategy(new DefaultClientConnectionReuseStrategy());
builder

.setConnectionManager(cm)

.setConnectionManagerShared(true)

.setConnectionTimeToLive(POOL_CONN_TTL_MS, TimeUnit.MILLISECONDS)

.setConnectionReuseStrategy(new DefaultClientConnectionReuseStrategy())

.setRetryHandler(new NoHttpResponseExceptionHttpRequestRetryHandler());

return builder;
}
Expand Down Expand Up @@ -568,4 +575,15 @@ public static Entity getResourceEntity(Resource res, ContentType contentType) {
return new ResourceHttpEntity(res, contentType);
}

private static class NoHttpResponseExceptionHttpRequestRetryHandler implements HttpRequestRetryHandler {
@Override
public boolean retryRequest(java.io.IOException exception, int executionCount, HttpContext context) {
if (executionCount <= 2 && exception instanceof org.apache.http.NoHttpResponseException) {
LogUtil.log(Log.LEVEL_INFO, "http-conn", ExceptionUtil.getStacktrace(exception, true));
return true;
}
return false;
}
}

}
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="6.1.1.77-BETA"/>
<property name="version" value="6.1.1.78-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>6.1.1.77-BETA</version>
<version>6.1.1.78-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit 680a3ae

Please sign in to comment.