Added hooks methods for connection and read timeouts override

This commit is contained in:
Mauro Mugnaini 2024-03-06 12:09:09 +01:00
parent e41a8f9c20
commit edfe561608
Signed by: mauro.mugnaini
GPG Key ID: 2440CFD0EB321EA8
1 changed files with 18 additions and 6 deletions

View File

@ -24,6 +24,8 @@ public abstract class AbstractHTTPWithJWTTokenAuthEventSender implements EventSe
protected String clientId;
protected String clientSecret;
protected URL tokenURL;
protected int connectionTimeout;
protected int readTimeout;
public AbstractHTTPWithJWTTokenAuthEventSender(URL baseEndpointURL, String clientId, String clientSecret,
URL tokenURL) {
@ -33,6 +35,16 @@ public abstract class AbstractHTTPWithJWTTokenAuthEventSender implements EventSe
this.clientId = clientId;
this.clientSecret = clientSecret;
this.tokenURL = tokenURL;
connectionTimeout = getConnectionTimeout();
readTimeout = getReadTimeout();
}
protected int getReadTimeout() {
return HTTPVerb.DEFAULT_READ_TIMEOUT;
}
protected int getConnectionTimeout() {
return HTTPVerb.DEFAULT_CONNECTION_TIMEOUT;
}
@Override
@ -69,8 +81,8 @@ public abstract class AbstractHTTPWithJWTTokenAuthEventSender implements EventSe
public abstract class HTTPVerb {
protected static final int CONNECTION_TIMEOUT = 10000;
protected static final int READ_TIMEOUT = 5000;
protected static final int DEFAULT_CONNECTION_TIMEOUT = 10000;
protected static final int DEFAULT_READ_TIMEOUT = 5000;
protected URL baseEndpoint;
@ -118,9 +130,9 @@ public abstract class AbstractHTTPWithJWTTokenAuthEventSender implements EventSe
log.debug("Performing HTTP POST to: {}", baseEndpoint);
HttpURLConnection connection = (HttpURLConnection) eventEndpoint.openConnection();
connection.setRequestMethod("POST");
connection.setConnectTimeout(CONNECTION_TIMEOUT);
connection.setConnectTimeout(connectionTimeout);
log.trace("HTTP connection timeout set to: {}", connection.getConnectTimeout());
connection.setReadTimeout(READ_TIMEOUT);
connection.setReadTimeout(readTimeout);
log.trace("HTTP connection Read timeout set to: {}", connection.getReadTimeout());
connection.setRequestProperty("Content-Type", "application/json");
// Commented out as per the Conductor issue: https://github.com/Netflix/conductor/issues/376
@ -233,9 +245,9 @@ public abstract class AbstractHTTPWithJWTTokenAuthEventSender implements EventSe
log.debug("Performing HTTP GET to: {}", endpoint);
HttpURLConnection connection = (HttpURLConnection) endpoint.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(CONNECTION_TIMEOUT);
connection.setConnectTimeout(connectionTimeout);
log.trace("HTTP connection timeout set to: {}", connection.getConnectTimeout());
connection.setReadTimeout(READ_TIMEOUT);
connection.setReadTimeout(readTimeout);
log.trace("HTTP connection Read timeout set to: {}", connection.getReadTimeout());
if (token != null) {
log.debug("Setting authorization header as: {}", token.getAccessTokenAsBearer());