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

Commit

Permalink
Add proxy support
Browse files Browse the repository at this point in the history
  • Loading branch information
avandendaele authored and hanshuo-aws committed Jan 29, 2015
1 parent 98e60db commit 2cb1767
Showing 1 changed file with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.juli.logging.Log;

import com.amazonaws.AmazonClientException;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
Expand Down Expand Up @@ -50,6 +51,8 @@ public class DynamoDBSessionManager extends PersistentManagerBase {
private long writeCapacityUnits = 5;
private boolean createIfNotExist = true;
private String tableName = DEFAULT_TABLE_NAME;
private String proxyHost;
private Integer proxyPort;

private final DynamoDBSessionStore dynamoSessionStore;

Expand Down Expand Up @@ -120,6 +123,13 @@ public void setCreateIfNotExist(boolean createIfNotExist) {
this.createIfNotExist = createIfNotExist;
}

public void setProxyHost(String proxyHost) {
this.proxyHost = proxyHost;
}

public void setProxyPort(Integer proxyPort) {
this.proxyPort = proxyPort;
}

//
// Private Interface
Expand All @@ -133,7 +143,9 @@ protected void initInternal() throws LifecycleException {
logger = getContainer().getLogger();

AWSCredentialsProvider credentialsProvider = initCredentials();
AmazonDynamoDBClient dynamo = new AmazonDynamoDBClient(credentialsProvider);
ClientConfiguration clientConfiguration = initClientConfiguration();

AmazonDynamoDBClient dynamo = new AmazonDynamoDBClient(credentialsProvider, clientConfiguration);
if (this.regionId != null) dynamo.setRegion(RegionUtils.getRegion(this.regionId));
if (this.endpoint != null) dynamo.setEndpoint(this.endpoint);

Expand Down Expand Up @@ -203,6 +215,24 @@ private AWSCredentialsProvider initCredentials() {
return defaultChainProvider;
}

private ClientConfiguration initClientConfiguration() {
ClientConfiguration clientConfiguration = new ClientConfiguration();

// Attempt to use an explicit proxy configuration
if (proxyHost != null || proxyPort != null) {
getContainer().getLogger().debug("Reading proxy settings from context.xml");
if (proxyHost == null || proxyPort == null) {
throw new AmazonClientException("Incomplete proxy settings specified in context.xml.");
}
getContainer().getLogger().debug("Using proxy host and port from context.xml");
clientConfiguration
.withProxyHost(proxyHost)
.withProxyPort(proxyPort);
}

return clientConfiguration;
}


//
// Logger Utility Functions
Expand Down

1 comment on commit 2cb1767

@zsustar
Copy link

@zsustar zsustar commented on 2cb1767 Feb 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the code.

  1. how to set the proxy information in context.xml?
    this is my setting, is that make sense?
    192.168.1.8:3128 is my proxy
    Thanks!

< WatchedResource>WEB-INF/web.xml

< Manager className="com.amazonaws.services.dynamodb.sessionmanager.DynamoDBSessionManager"
Table="Test-DynamoDB001"
proxyHost="192.168.1.8"
proxyPort="3128"
createIfNotExist="true" / >

Please sign in to comment.