Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implementation for #74 #75

Open
wants to merge 3 commits 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
2 changes: 1 addition & 1 deletion nevado-jms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1</version>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class NevadoConnectionFactory implements ConnectionFactory, QueueConnecti
private SQSConnectorFactory _sqsConnectorFactory;
private volatile String _awsAccessKey;
private volatile String _awsSecretKey;
private volatile String _awsSessionToken;
private volatile String _awsSQSEndpoint = null;
private volatile String _awsSNSEndpoint = null;
private volatile String _clientID;
Expand All @@ -55,43 +56,43 @@ public NevadoConnectionFactory(SQSConnectorFactory sqsConnectorFactory) {

public NevadoQueueConnection createQueueConnection() throws JMSException {
checkSQSConnectorFactory();
NevadoQueueConnection connection = new NevadoQueueConnection(_sqsConnectorFactory.getInstance(_awsAccessKey, _awsSecretKey, _awsSQSEndpoint, _awsSNSEndpoint));
NevadoQueueConnection connection = new NevadoQueueConnection(_sqsConnectorFactory.getInstance(_awsAccessKey, _awsSecretKey, _awsSessionToken, _awsSQSEndpoint, _awsSNSEndpoint));
initializeConnection(connection);
return connection;
}

public NevadoQueueConnection createQueueConnection(String awsAccessKey, String awsSecretKey) throws JMSException {
checkSQSConnectorFactory();
NevadoQueueConnection connection
= new NevadoQueueConnection(_sqsConnectorFactory.getInstance(awsAccessKey, awsSecretKey, _awsSQSEndpoint, _awsSNSEndpoint));
= new NevadoQueueConnection(_sqsConnectorFactory.getInstance(awsAccessKey, awsSecretKey, _awsSessionToken, _awsSQSEndpoint, _awsSNSEndpoint));
initializeConnection(connection);
return connection;
}

public NevadoConnection createConnection() throws JMSException {
checkSQSConnectorFactory();
NevadoConnection connection = new NevadoConnection(_sqsConnectorFactory.getInstance(_awsAccessKey, _awsSecretKey, _awsSQSEndpoint, _awsSNSEndpoint));
NevadoConnection connection = new NevadoConnection(_sqsConnectorFactory.getInstance(_awsAccessKey, _awsSecretKey, _awsSessionToken, _awsSQSEndpoint, _awsSNSEndpoint));
initializeConnection(connection);
return connection;
}

public NevadoConnection createConnection(String awsAccessKey, String awsSecretKey) throws JMSException {
checkSQSConnectorFactory();
NevadoConnection connection = new NevadoConnection(_sqsConnectorFactory.getInstance(awsAccessKey, awsSecretKey, _awsSQSEndpoint, _awsSNSEndpoint));
NevadoConnection connection = new NevadoConnection(_sqsConnectorFactory.getInstance(awsAccessKey, awsSecretKey, _awsSessionToken, _awsSQSEndpoint, _awsSNSEndpoint));
initializeConnection(connection);
return connection;
}

public NevadoTopicConnection createTopicConnection() throws JMSException {
checkSQSConnectorFactory();
NevadoTopicConnection connection = new NevadoTopicConnection(_sqsConnectorFactory.getInstance(_awsAccessKey, _awsSecretKey, _awsSQSEndpoint, _awsSNSEndpoint));
NevadoTopicConnection connection = new NevadoTopicConnection(_sqsConnectorFactory.getInstance(_awsAccessKey, _awsSecretKey, _awsSessionToken, _awsSQSEndpoint, _awsSNSEndpoint));
initializeConnection(connection);
return connection;
}

public TopicConnection createTopicConnection(String awsAccessKey, String awsSecretKey) throws JMSException {
checkSQSConnectorFactory();
NevadoTopicConnection connection = new NevadoTopicConnection(_sqsConnectorFactory.getInstance(awsAccessKey, awsSecretKey, _awsSQSEndpoint, _awsSNSEndpoint));
NevadoTopicConnection connection = new NevadoTopicConnection(_sqsConnectorFactory.getInstance(awsAccessKey, awsSecretKey, _awsSessionToken, _awsSQSEndpoint, _awsSNSEndpoint));
initializeConnection(connection);
return connection;
}
Expand Down Expand Up @@ -127,6 +128,10 @@ public void setAwsSecretKey(String awsSecretKey) {
_awsSecretKey = awsSecretKey;
}

public void setAwsSessionToken(String awsSessionToken) {
this._awsSessionToken = awsSessionToken;
}

public void setAwsSQSEndpoint(String awsSQSEndpoint) {
_awsSQSEndpoint = awsSQSEndpoint;
}
Expand Down Expand Up @@ -159,6 +164,10 @@ public String getAwsSecretKey() {
return _awsSecretKey;
}

public String get_awsSessionToken() {
return _awsSessionToken;
}

public String getClientID() {
return _clientID;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public abstract class AbstractSQSConnectorFactory implements SQSConnectorFactory
protected long _receiveCheckIntervalMs = DEFAULT_RECEIVE_CHECK_INTERVAL_MS;

@Override
public abstract SQSConnector getInstance(String awsAccessKey, String awsSecretKey, String awsSQSEndpoint,
public abstract SQSConnector getInstance(String awsAccessKey, String awsSecretKey, String awsSessionToken, String awsSQSEndpoint,
String awsSNSEndpoint) throws JMSException;

@Override
public SQSConnector getInstance(String awsAccessKey, String awsSecretKey) throws JMSException {
return getInstance(awsAccessKey, awsSecretKey, null, null);
public SQSConnector getInstance(String awsAccessKey, String awsSecretKey, String awsSessionToken) throws JMSException {
return getInstance(awsAccessKey, awsSecretKey, awsSessionToken, null, null);
}

public void setSecure(boolean secure) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
* @author Carter Page <[email protected]>
*/
public interface SQSConnectorFactory {
SQSConnector getInstance(String awsAccessKey, String awsSecretKey) throws JMSException;
SQSConnector getInstance(String awsAccessKey, String awsSecretKey, String awsSQSEndpoint, String awsSNSEndpoint) throws JMSException;
SQSConnector getInstance(String awsAccessKey, String awsSecretKey, String awsSessionToken) throws JMSException;
SQSConnector getInstance(String awsAccessKey, String awsSecretKey, String awsSessionToken, String awsSQSEndpoint, String awsSNSEndpoint) throws JMSException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.amazonaws.Protocol;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.auth.BasicSessionCredentials;
import com.amazonaws.services.sns.AmazonSNS;
import com.amazonaws.services.sns.AmazonSNSAsync;
import com.amazonaws.services.sns.AmazonSNSAsyncClient;
Expand Down Expand Up @@ -50,13 +51,13 @@ public class AmazonAwsSQSConnector extends AbstractSQSConnector {
private final AmazonSQS _amazonSQS;
private final AmazonSNS _amazonSNS;

public AmazonAwsSQSConnector(String awsAccessKey, String awsSecretKey, boolean isSecure, long receiveCheckIntervalMs) {
this(awsAccessKey, awsSecretKey, isSecure, receiveCheckIntervalMs, false);
public AmazonAwsSQSConnector(String awsAccessKey, String awsSecretKey, String awsSessionToken, boolean isSecure, long receiveCheckIntervalMs) {
this(awsAccessKey, awsSecretKey, awsSessionToken, isSecure, receiveCheckIntervalMs, false);
}

public AmazonAwsSQSConnector(String awsAccessKey, String awsSecretKey, boolean isSecure, long receiveCheckIntervalMs, boolean isAsync) {
public AmazonAwsSQSConnector(String awsAccessKey, String awsSecretKey, String awsSessionToken, boolean isSecure, long receiveCheckIntervalMs, boolean isAsync) {
super(receiveCheckIntervalMs, isAsync);
AWSCredentials awsCredentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
AWSCredentials awsCredentials = (awsSessionToken == null)? new BasicAWSCredentials(awsAccessKey, awsSecretKey) : new BasicSessionCredentials(awsAccessKey, awsSecretKey, awsSessionToken);
ClientConfiguration clientConfiguration = new ClientConfiguration();
String proxyHost = System.getProperty("http.proxyHost");
String proxyPort = System.getProperty("http.proxyPort");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class AmazonAwsSQSConnectorFactory extends AbstractSQSConnectorFactory {
protected boolean _useAsyncSend = false;

@Override
public AmazonAwsSQSConnector getInstance(String awsAccessKey, String awsSecretKey, String awsSQSEndpoint, String awsSNSEndpoint) {
AmazonAwsSQSConnector amazonAwsSQSConnector = new AmazonAwsSQSConnector(awsAccessKey, awsSecretKey, _isSecure,
public AmazonAwsSQSConnector getInstance(String awsAccessKey, String awsSecretKey, String awsSessionToken, String awsSQSEndpoint, String awsSNSEndpoint) {
AmazonAwsSQSConnector amazonAwsSQSConnector = new AmazonAwsSQSConnector(awsAccessKey, awsSecretKey, awsSessionToken, _isSecure,
_receiveCheckIntervalMs, _useAsyncSend);
if (StringUtils.isNotEmpty(awsSQSEndpoint)) {
amazonAwsSQSConnector.getAmazonSQS().setEndpoint(awsSQSEndpoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public class MockSQSConnectorFactory implements SQSConnectorFactory, ResettableM
private MockSQSConnector _mockSQSConnector = new MockSQSConnector();

@Override
public SQSConnector getInstance(String awsAccessKey, String awsSecretKey) throws ResourceAllocationException {
return getInstance(awsAccessKey, awsSecretKey, null, null);
public SQSConnector getInstance(String awsAccessKey, String awsSecretKey, String awsSessionToken) throws ResourceAllocationException {
return getInstance(awsAccessKey, awsSecretKey, awsSessionToken, null, null);
}

@Override
public SQSConnector getInstance(String awsAccessKey, String awsSecretKey, String awsSQSEndpoint, String awsSNSEndpoint) throws ResourceAllocationException {
public SQSConnector getInstance(String awsAccessKey, String awsSecretKey, String awsSessionToken, String awsSQSEndpoint, String awsSNSEndpoint) throws ResourceAllocationException {
if (BAD_ENDPOINT_URL.equals(awsSQSEndpoint) || BAD_ENDPOINT_URL.equals(awsSNSEndpoint)) {
throw new ResourceAllocationException("Bad endpoint");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class MockSQSConnectorFactoryTest {
@Before
public void setUp() throws Exception {
_mockSQSConnectorFactory = new MockSQSConnectorFactory();
_mockSQSConnector = (MockSQSConnector) _mockSQSConnectorFactory.getInstance(ACCESS_KEY, SECRET_KEY);
_mockSQSConnector = (MockSQSConnector) _mockSQSConnectorFactory.getInstance(ACCESS_KEY, SECRET_KEY, null);
_nevadoConnection = new NevadoConnection(_mockSQSConnector);
_nevadoConnection.start();

Expand Down