Skip to content

Commit

Permalink
Address reviewed changes
Browse files Browse the repository at this point in the history
  • Loading branch information
osandamaleesha committed Sep 18, 2024
1 parent 5f6e873 commit c69ecd8
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public APIClient() {
.setRelativeRedirectsAllowed(false)
.build();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setMaxTotal(ActionExecutorConfig.getInstance().getHttpClientConnectionPoolSize());
connectionManager.setMaxTotal(ActionExecutorConfig.getInstance().getHttpConnectionPoolSize());
httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config).setConnectionManager(connectionManager)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ public class ActionExecutorConfig {
"Actions.ActionRequest.ExcludedHeaders.Header";
private static final String EXCLUDED_PARAMS_IN_ACTION_REQUEST_PROPERTY =
"Actions.ActionRequest.ExcludedParameters.Parameter";
private static final String HTTP_READ_TIMEOUT_PROPERTY = "Actions.HTTPConnections.HTTPReadTimeout";
private static final String HTTP_READ_TIMEOUT_PROPERTY = "Actions.HTTPClient.HTTPReadTimeout";
private static final String HTTP_CONNECTION_REQUEST_TIMEOUT_PROPERTY =
"Actions.HTTPConnections.HTTPConnectionRequestTimeout";
private static final String HTTP_CONNECTION_TIMEOUT_PROPERTY = "Actions.HTTPConnections.HTTPConnectionTimeout";
private static final String HTTP_CLIENT_CONNECTION_POOL_SIZE_PROPERTY = "Actions.HTTPClientConnectionPoolSize";
private static final int DEFAULT_HTTP_CLIENT_CONNECTION_POOL_SIZE_PROPERTY = 20;
"Actions.HTTPClient.HTTPConnectionRequestTimeout";
private static final String HTTP_CONNECTION_TIMEOUT_PROPERTY = "Actions.HTTPClient.HTTPConnectionTimeout";
private static final String HTTP_CONNECTION_POOL_SIZE_PROPERTY = "Actions.HTTPClient.HTTPConnectionPoolSize";
private static final int DEFAULT_HTTP_CONNECTION_POOL_SIZE = 20;
private static final int DEFAULT_HTTP_READ_TIMEOUT_IN_MILLIS = 5000;
private static final int DEFAULT_HTTP_CONNECTION_REQUEST_TIMEOUT_MILLIS = 2000;
private static final int DEFAULT_HTTP_CONNECTION_TIMEOUT_MILLIS = 2000;
private static final int DEFAULT_HTTP_CONNECTION_REQUEST_TIMEOUT_IN_MILLIS = 2000;
private static final int DEFAULT_HTTP_CONNECTION_TIMEOUT_IN_MILLIS = 2000;

private ActionExecutorConfig() {

Expand Down Expand Up @@ -83,24 +83,22 @@ public boolean isExecutionForActionTypeEnabled(ActionType actionType) {
}

/**
* Returns the HTTP client connection pool size based on the system configuration.
* Returns the HTTP connection pool size based on the system configuration.
*
* @return The HTTP client connection pool size, or the default if the property is missing or invalid.
* @return The HTTP connection pool size, or the default if the property is missing or invalid.
*/
public int getHttpClientConnectionPoolSize() {
public int getHttpConnectionPoolSize() {

int poolSizePropertyValue = DEFAULT_HTTP_CLIENT_CONNECTION_POOL_SIZE_PROPERTY;
int poolSizePropertyValue = DEFAULT_HTTP_CONNECTION_POOL_SIZE;
String poolSizeValue = (String) IdentityConfigParser.getInstance().getConfiguration().
get(HTTP_CLIENT_CONNECTION_POOL_SIZE_PROPERTY);
get(HTTP_CONNECTION_POOL_SIZE_PROPERTY);
if (StringUtils.isNotBlank(poolSizeValue)) {
try {
poolSizePropertyValue = Integer.parseInt(poolSizeValue);
} catch (NumberFormatException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Failed to read Http client connection pool size property in identity.xml." +
" Expects a number. Using the default value: " +
DEFAULT_HTTP_CLIENT_CONNECTION_POOL_SIZE_PROPERTY, e);
}
LOG.debug("Failed to read Http client connection pool size property in identity.xml." +
" Expects a number. Using the default value: " +
DEFAULT_HTTP_CONNECTION_POOL_SIZE, e);
}
}
return poolSizePropertyValue;
Expand All @@ -126,7 +124,7 @@ public int getHttpReadTimeoutInMillis() {
public int getHttpConnectionRequestTimeoutInMillis() {

return parseTimeoutConfig(HTTP_CONNECTION_REQUEST_TIMEOUT_PROPERTY,
DEFAULT_HTTP_CONNECTION_REQUEST_TIMEOUT_MILLIS);
DEFAULT_HTTP_CONNECTION_REQUEST_TIMEOUT_IN_MILLIS);
}

/**
Expand All @@ -137,7 +135,7 @@ public int getHttpConnectionRequestTimeoutInMillis() {
*/
public int getHttpConnectionTimeoutInMillis() {

return parseTimeoutConfig(HTTP_CONNECTION_TIMEOUT_PROPERTY, DEFAULT_HTTP_CONNECTION_TIMEOUT_MILLIS);
return parseTimeoutConfig(HTTP_CONNECTION_TIMEOUT_PROPERTY, DEFAULT_HTTP_CONNECTION_TIMEOUT_IN_MILLIS);
}

private int parseTimeoutConfig(String timeoutTypeName, int defaultTimeout) {
Expand All @@ -148,10 +146,8 @@ private int parseTimeoutConfig(String timeoutTypeName, int defaultTimeout) {
try {
timeoutPropertyValue = Integer.parseInt(timeoutValue);
} catch (NumberFormatException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Failed to read " + timeoutTypeName + " property in identity.xml." +
" Expects a number. Using the default value: " + defaultTimeout, e);
}
LOG.debug("Failed to read " + timeoutTypeName + " property in identity.xml." +
" Expects a number. Using the default value: " + defaultTimeout, e);
}
}
return timeoutPropertyValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public void testGetExcludedParamsInActionRequestForEmptyConfigForAllAndDefinedTy
public void testGetHttpReadTimeoutInMillis() {

Map<String, Object> configMap = new HashMap<>();
configMap.put("Actions.HTTPConnections.HTTPReadTimeout", "5000");
configMap.put("Actions.HTTPClient.HTTPReadTimeout", "5000");
when(mockIdentityConfigParser.getConfiguration()).thenReturn(configMap);
Assert.assertEquals(5000, actionExecutorConfig.getHttpReadTimeoutInMillis());
}
Expand All @@ -317,7 +317,7 @@ public void testGetHttpReadTimeoutInMillis() {
public void testGetHttpReadTimeoutInMillisWithoutNumberFormat() {

Map<String, Object> configMap = new HashMap<>();
configMap.put("Actions.HTTPConnections.HTTPReadTimeout", "value");
configMap.put("Actions.HTTPClient.HTTPReadTimeout", "value");
when(mockIdentityConfigParser.getConfiguration()).thenReturn(configMap);
Assert.assertEquals(5000, actionExecutorConfig.getHttpReadTimeoutInMillis());
}
Expand All @@ -326,7 +326,7 @@ public void testGetHttpReadTimeoutInMillisWithoutNumberFormat() {
public void testGetHttpConnectionRequestTimeoutInMillis() {

Map<String, Object> configMap = new HashMap<>();
configMap.put("Actions.HTTPConnections.HTTPConnectionRequestTimeout", "2000");
configMap.put("Actions.HTTPClient.HTTPConnectionRequestTimeout", "2000");
when(mockIdentityConfigParser.getConfiguration()).thenReturn(configMap);
Assert.assertEquals(2000, actionExecutorConfig.getHttpConnectionRequestTimeoutInMillis());
}
Expand All @@ -335,26 +335,26 @@ public void testGetHttpConnectionRequestTimeoutInMillis() {
public void testGetHttpConnectionTimeoutInMillis() {

Map<String, Object> configMap = new HashMap<>();
configMap.put("Actions.HTTPConnections.HTTPConnectionTimeout", "2000");
configMap.put("Actions.HTTPClient.HTTPConnectionTimeout", "2000");
when(mockIdentityConfigParser.getConfiguration()).thenReturn(configMap);
Assert.assertEquals(2000, actionExecutorConfig.getHttpConnectionTimeoutInMillis());
}

@Test
public void testGetHttpClientConnectionPoolSize() {
public void testGetHttpConnectionPoolSize() {

Map<String, Object> configMap = new HashMap<>();
configMap.put("Actions.HTTPClientConnectionPoolSize", "20");
configMap.put("Actions.HTTPClient.HTTPConnectionPoolSize", "20");
when(mockIdentityConfigParser.getConfiguration()).thenReturn(configMap);
Assert.assertEquals(20, actionExecutorConfig.getHttpClientConnectionPoolSize());
Assert.assertEquals(20, actionExecutorConfig.getHttpConnectionPoolSize());
}

@Test
public void testGetHttpClientConnectionPoolSizeWithoutNumberFormat() {
public void testGetHttpConnectionPoolSizeWithoutNumberFormat() {

Map<String, Object> configMap = new HashMap<>();
configMap.put("Actions.HTTPClientConnectionPoolSize", "value");
configMap.put("Actions.HTTPClient.HTTPConnectionPoolSize", "value");
when(mockIdentityConfigParser.getConfiguration()).thenReturn(configMap);
Assert.assertEquals(20, actionExecutorConfig.getHttpClientConnectionPoolSize());
Assert.assertEquals(20, actionExecutorConfig.getHttpConnectionPoolSize());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
#

# Root logger option
log4j.rootLogger=INFO, stdout
log4j.rootLogger=info, stdout

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

#log4j.logger.com.sample=debug
Original file line number Diff line number Diff line change
Expand Up @@ -2020,12 +2020,12 @@
</OutboundProvisioning>

<Actions>
<HTTPConnections>
<HTTPConnectionTimeout>{{actions.http_connections.connection_timeout}}</HTTPConnectionTimeout>
<HTTPReadTimeout>{{actions.http_connections.read_timeout}}</HTTPReadTimeout>
<HTTPConnectionRequestTimeout>{{actions.http_connections.request_timeout}}</HTTPConnectionRequestTimeout>
</HTTPConnections>
<HTTPClientConnectionPoolSize>{{actions.http_client_connection_pool_size}}</HTTPClientConnectionPoolSize>
<HTTPClient>
<HTTPConnectionTimeout>{{actions.http_client.connection_timeout}}</HTTPConnectionTimeout>
<HTTPReadTimeout>{{actions.http_client.read_timeout}}</HTTPReadTimeout>
<HTTPConnectionRequestTimeout>{{actions.http_client.request_timeout}}</HTTPConnectionRequestTimeout>
<HTTPConnectionPoolSize>{{actions.http_client.connection_pool_size}}</HTTPConnectionPoolSize>
</HTTPClient>
<MaximumActionsPerActionType>{{actions.maximum_actions_per_action_type}}</MaximumActionsPerActionType>
<ActionRequest>
<ExcludedHeaders>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1571,10 +1571,10 @@

"on_demand_config.on_initial_use.enable_sms_otp_password_recovery_if_connector_enabled": false,

"actions.http_connections.read_timeout": 5000,
"actions.http_connections.request_timeout": 2000,
"actions.http_connections.connection_timeout": 2000,
"actions.http_client_connection_pool_size": 20,
"actions.http_client.connection_timeout": 2000,
"actions.http_client.read_timeout": 5000,
"actions.http_client.request_timeout": 2000,
"actions.http_client.connection_pool_size": 20,
"actions.maximum_actions_per_action_type": 1,
"actions.action_request.excluded_headers": [
"authorization",
Expand Down

0 comments on commit c69ecd8

Please sign in to comment.