Skip to content

Commit

Permalink
Introduce timeout for driver HTTP connection
Browse files Browse the repository at this point in the history
  • Loading branch information
peacekeeper committed Aug 28, 2024
1 parent 02dc920 commit fe878b4
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions driver-http/src/main/java/uniresolver/driver/http/HttpDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import foundation.identity.did.DID;
import org.apache.http.HttpEntity;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
Expand All @@ -33,14 +34,25 @@ public class HttpDriver implements Driver {

private static final ObjectMapper objectMapper = new ObjectMapper();

private HttpClient httpClient = HttpClients.createDefault();
private static final int HTTP_CLIENT_TIMEOUT = 60;

private HttpClient httpClient;
private Pattern pattern = null;
private URI resolveUri = null;
private URI propertiesUri = null;
private Pattern pattern = null;
private List<String> testIdentifiers = Collections.emptyList();

public HttpDriver() {
this.httpClient = buildDefaultHttpClient();
}

private static HttpClient buildDefaultHttpClient() {
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(HTTP_CLIENT_TIMEOUT * 1000)
.setConnectionRequestTimeout(HTTP_CLIENT_TIMEOUT * 1000)
.setSocketTimeout(HTTP_CLIENT_TIMEOUT * 1000)
.build();
return HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();
}

@Override
Expand Down Expand Up @@ -276,6 +288,18 @@ public void setHttpClient(HttpClient httpClient) {
this.httpClient = httpClient;
}

public Pattern getPattern() {
return this.pattern;
}

public void setPattern(Pattern pattern) {
this.pattern = pattern;
}

public void setPattern(String pattern) {
this.pattern = Pattern.compile(pattern);
}

public URI getResolveUri() {
return this.resolveUri;
}
Expand All @@ -300,18 +324,6 @@ public void setPropertiesUri(String propertiesUri) {
this.propertiesUri = URI.create(propertiesUri);
}

public Pattern getPattern() {
return this.pattern;
}

public void setPattern(Pattern pattern) {
this.pattern = pattern;
}

public void setPattern(String pattern) {
this.pattern = Pattern.compile(pattern);
}

public List<String> getTestIdentifiers() {
return this.testIdentifiers;
}
Expand Down

0 comments on commit fe878b4

Please sign in to comment.