summaryrefslogtreecommitdiffstats
path: root/src/main/java/edu/kit
diff options
context:
space:
mode:
authorSimon Rettberg2024-10-02 10:51:04 +0200
committerSimon Rettberg2024-10-02 10:51:04 +0200
commit555273de41893073c64d665630ce53aac6077849 (patch)
tree0fed45193770b7954a17f5602c03317b754dbda4 /src/main/java/edu/kit
parentSilence NPE from reset call on certain JVMs (diff)
downloadecp-client-lean-555273de41893073c64d665630ce53aac6077849.tar.gz
ecp-client-lean-555273de41893073c64d665630ce53aac6077849.tar.xz
ecp-client-lean-555273de41893073c64d665630ce53aac6077849.zip
Tighter connection timeouts, fix version range in pom.xml
Diffstat (limited to 'src/main/java/edu/kit')
-rw-r--r--src/main/java/edu/kit/scc/dei/ecplean/ECPAuthenticatorBase.java19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/main/java/edu/kit/scc/dei/ecplean/ECPAuthenticatorBase.java b/src/main/java/edu/kit/scc/dei/ecplean/ECPAuthenticatorBase.java
index 454886f..9c549ea 100644
--- a/src/main/java/edu/kit/scc/dei/ecplean/ECPAuthenticatorBase.java
+++ b/src/main/java/edu/kit/scc/dei/ecplean/ECPAuthenticatorBase.java
@@ -4,6 +4,7 @@ import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.Observable;
+import java.util.concurrent.TimeUnit;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
@@ -23,10 +24,12 @@ import javax.xml.xpath.XPathFactory;
import org.apache.hc.client5.http.auth.AuthenticationException;
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
import org.apache.hc.client5.http.classic.methods.HttpPost;
+import org.apache.hc.client5.http.config.ConnectionConfig;
import org.apache.hc.client5.http.impl.auth.BasicScheme;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
-import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
+import org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.core5.http.HttpHeaders;
import org.apache.hc.core5.http.HttpHost;
@@ -55,7 +58,7 @@ public abstract class ECPAuthenticatorBase extends Observable {
protected boolean retryWithoutAt;
public ECPAuthenticatorBase(CloseableHttpClient client) {
- this.client = client == null ? HttpClients.createSystem() : client;
+ this.client = client == null ? defaultClient() : client;
documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
@@ -72,6 +75,18 @@ public abstract class ECPAuthenticatorBase extends Observable {
public ECPAuthenticatorBase() {
this(null);
}
+
+ private static CloseableHttpClient defaultClient() {
+ ConnectionConfig connConfig = ConnectionConfig.custom()
+ .setConnectTimeout(4000, TimeUnit.MILLISECONDS)
+ .setSocketTimeout(10000, TimeUnit.MILLISECONDS)
+ .build();
+ BasicHttpClientConnectionManager cm = new BasicHttpClientConnectionManager();
+ cm.setConnectionConfig(connConfig);
+ return HttpClientBuilder.create()
+ .setConnectionManager(cm)
+ .build();
+ }
private CloseableHttpResponse exec(Document idpRequest, String user, String pass)
throws ECPAuthenticationException {