Skip to content
This repository was archived by the owner on Feb 7, 2018. It is now read-only.

String constants improvement. #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.amazonaws.internal.StaticCredentialsProvider;
import com.amazonaws.regions.RegionUtils;
import com.amazonaws.services.dynamodb.sessionmanager.converters.SessionConverter;
import com.amazonaws.services.dynamodb.sessionmanager.util.Constants;
import com.amazonaws.services.dynamodb.sessionmanager.util.DynamoUtils;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper;
Expand Down Expand Up @@ -154,7 +155,7 @@ private AWSCredentialsProvider initCredentials() {
if (credentialsExistInContextConfig()) {
// Fail fast if credentials aren't valid as user has likely made a configuration mistake
if (credentialsInContextConfigAreValid()) {
throw new AmazonClientException("Incomplete AWS security credentials specified in context.xml.");
throw new AmazonClientException(Constants.INCOMPLETE_AWS_IN_CONTEXT);
}
logger.debug("Using AWS access key ID and secret key from context.xml");
return new StaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey));
Expand All @@ -168,20 +169,15 @@ private AWSCredentialsProvider initCredentials() {
logger.debug("Using AWS credentials from file: " + credentialsFile);
return new StaticCredentialsProvider(credentials);
} catch (Exception e) {
throw new AmazonClientException(
"Unable to read AWS security credentials from file specified in context.xml: "
+ credentialsFile,
e);
throw new AmazonClientException(Constants.UNABLE_READ_AWS_SECURUTY_CREDENTIALS_IN_CONTEXT + credentialsFile, e);
}
}

// Fall back to the default credentials chain provider if credentials weren't explicitly set
AWSCredentialsProvider defaultChainProvider = new DefaultAWSCredentialsProviderChain();
if (defaultChainProvider.getCredentials() == null) {
logger.debug("Loading security credentials from default credentials provider chain.");
throw new AmazonClientException("Unable to find AWS security credentials. "
+ "Searched JVM system properties, OS env vars, and EC2 instance roles. "
+ "Specify credentials in Tomcat's context.xml file or put them in one of the places mentioned above.");
throw new AmazonClientException(Constants.UNABLE_FIND_AWS_SECURUTY_CREDENTIALS);
}
logger.debug("Using default AWS credentials provider chain to load credentials");
return defaultChainProvider;
Expand Down Expand Up @@ -211,8 +207,7 @@ private ClientConfiguration initClientConfiguration() {
if (proxyHost != null || proxyPort != null) {
logger.debug("Reading proxy settings from context.xml");
if (proxyHost == null || proxyPort == null) {
throw new AmazonClientException("Incomplete proxy settings specified in context.xml."
+ " Both proxy hot and proxy port needs to be specified");
throw new AmazonClientException(Constants.INCOMPLETE_PROXY_SETTINGS_IN_CONTEXT);
}
logger.debug("Using proxy host and port from context.xml");
clientConfiguration.withProxyHost(proxyHost).withProxyPort(proxyPort);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.amazonaws.services.dynamodb.sessionmanager.util;

public class Constants {
public static final String INCOMPLETE_AWS_IN_CONTEXT = "Incomplete AWS security credentials specified in context.xml.";
public static final String UNABLE_READ_AWS_SECURUTY_CREDENTIALS_IN_CONTEXT= "Unable to read AWS security credentials from file specified in context.xml: ";
public static final String UNABLE_FIND_AWS_SECURUTY_CREDENTIALS = "Unable to find AWS security credentials. Searched JVM system properties, OS env vars, and EC2 instance roles. Specify credentials in Tomcat's context.xml file or put them in one of the places mentioned above.";
public static final String INCOMPLETE_PROXY_SETTINGS_IN_CONTEXT = "Incomplete proxy settings specified in context.xml. Both proxy hot and proxy port needs to be specified";
}