From 388b3c2fabf32af391a0a9f733c32253ff04cef3 Mon Sep 17 00:00:00 2001 From: Michael Simon <michael.simon@kit.edu> Date: Mon, 5 Aug 2024 05:43:35 +0000 Subject: [PATCH] NO_STORY add deprecated setConnectionTimeout, because everything else does not work --- .../webreg/service/saml/AttributeQueryHelper.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/regapp-saml/src/main/java/edu/kit/scc/webreg/service/saml/AttributeQueryHelper.java b/regapp-saml/src/main/java/edu/kit/scc/webreg/service/saml/AttributeQueryHelper.java index 8468f1fa..5b586767 100644 --- a/regapp-saml/src/main/java/edu/kit/scc/webreg/service/saml/AttributeQueryHelper.java +++ b/regapp-saml/src/main/java/edu/kit/scc/webreg/service/saml/AttributeQueryHelper.java @@ -26,6 +26,7 @@ import java.util.Set; import javax.net.ssl.SSLContext; +import org.apache.hc.client5.http.config.ConnectionConfig; import org.apache.hc.client5.http.config.RequestConfig; import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; import org.apache.hc.client5.http.impl.classic.HttpClients; @@ -35,6 +36,7 @@ import org.apache.hc.client5.http.ssl.DefaultHostnameVerifier; import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory; import org.apache.hc.core5.http.config.Registry; import org.apache.hc.core5.http.config.RegistryBuilder; +import org.apache.hc.core5.http.io.SocketConfig; import org.apache.hc.core5.ssl.SSLContextBuilder; import org.apache.hc.core5.util.Timeout; import org.opensaml.core.criterion.EntityIdCriterion; @@ -192,13 +194,21 @@ public class AttributeQueryHelper implements Serializable { .append(samlHelper.prettyPrint((XMLObject) outbound.getMessage())).append("\n"); } + SocketConfig socketConfig = SocketConfig.custom().setSoTimeout(getRequestTimeout()).build(); + Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create() .register("https", getSSLConnectionSocketFactory(idpEntityDescriptor)).build(); BasicHttpClientConnectionManager connectionManager = new BasicHttpClientConnectionManager( socketFactoryRegistry); - + + connectionManager.setSocketConfig(socketConfig); + + // + // The .setConnectTimeout() is deprecated, but the above method with set socket timeout does not lead to the + // same result. Without the setConnectTimeout a connection timeout will take 5 minutes. + // RequestConfig requestConfig = RequestConfig.custom().setResponseTimeout(getRequestTimeout()) - .setConnectionRequestTimeout(getRequestTimeout()).build(); + .setConnectionRequestTimeout(getRequestTimeout()).setConnectTimeout(getRequestTimeout()).build(); CloseableHttpClient client = HttpClients.custom().setConnectionManager(connectionManager) .setDefaultRequestConfig(requestConfig).build(); -- GitLab