[typica] r320 committed - added javadoc, test code for SNS. Also use delegate model for connecti...

1 view
Skip to first unread message

typ...@googlecode.com

unread,
Apr 12, 2010, 8:57:13 AM4/12/10
to typic...@googlegroups.com
Revision: 320
Author: dkavanagh
Date: Mon Apr 12 05:56:46 2010
Log: added javadoc, test code for SNS. Also use delegate model for
connection vs. inheritance

http://code.google.com/p/typica/source/detail?r=320

Added:
/trunk/test/java/TestSNS.java
Modified:
/trunk/java/com/xerox/amazonws/common/AWSQueryConnection.java
/trunk/java/com/xerox/amazonws/sns/NotificationService.java

=======================================
--- /dev/null
+++ /trunk/test/java/TestSNS.java Mon Apr 12 05:56:46 2010
@@ -0,0 +1,33 @@
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import com.xerox.amazonws.common.Result;
+import com.xerox.amazonws.sns.NotificationService;
+
+// args :
+
+public class TestSNS {
+ private static Log logger = LogFactory.getLog(TestSNS.class);
+
+ public static void main(String [] args) throws Exception {
+ Properties props = new Properties();
+
props.load(TestSNS.class.getClassLoader().getResourceAsStream("aws.properties"));
+
+ NotificationService sns = new
NotificationService(props.getProperty("aws.accessId"),
props.getProperty("aws.secretKey"));
+ Result<String> ret = sns.createTopic("TestTopic");
+ String topicArn = ret.getResult();
+ System.err.println("topicArn: "+topicArn);
+
+ sns.deleteTopic(topicArn);
+ }
+}
+
=======================================
--- /trunk/java/com/xerox/amazonws/common/AWSQueryConnection.java Sat Apr
10 06:39:58 2010
+++ /trunk/java/com/xerox/amazonws/common/AWSQueryConnection.java Mon Apr
12 05:56:46 2010
@@ -341,7 +341,7 @@
* @param params map of request params
* @param respType the class that represents the desired/expected
return type
*/
- protected <T> T makeRequest(HttpRequestBase method, String action,
Map<String, String> params, Class<T> respType)
+ public <T> T makeRequest(HttpRequestBase method, String action,
Map<String, String> params, Class<T> respType)
throws HttpException, IOException, JAXBException, AWSException {

// add auth params, and protocol specific headers
=======================================
--- /trunk/java/com/xerox/amazonws/sns/NotificationService.java Sat Apr 10
06:39:58 2010
+++ /trunk/java/com/xerox/amazonws/sns/NotificationService.java Mon Apr 12
05:56:46 2010
@@ -64,10 +64,12 @@
* @author D. Kavanagh
* @author deve...@dotech.com
*/
-public class NotificationService extends AWSQueryConnection {
+public class NotificationService {

private static Log logger =
LogFactory.getLog(NotificationService.class);

+ private AWSQueryConnection connection; // connection delegate
+
/**
* Initializes the Simple Notification service with your AWS login
information.
*
@@ -100,8 +102,7 @@
public NotificationService(String awsAccessId, String awsSecretKey,
boolean isSecure,
String server)
{
- this(awsAccessId, awsSecretKey, isSecure, server,
- isSecure ? 443 : 80);
+ this(awsAccessId, awsSecretKey, isSecure, server, isSecure ? 443 :
80);
}

/**
@@ -116,16 +117,24 @@
public NotificationService(String awsAccessId, String awsSecretKey,
boolean isSecure,
String server, int port)
{
- super(awsAccessId, awsSecretKey, isSecure, server, port);
- setVersionHeader(this);
+ connection = new AWSQueryConnection(awsAccessId, awsSecretKey, isSecure,
server, port);
+ setVersionHeader(connection);
}

/**
- * Activates a desktop product.
+ * Returns connection object, so connection params can be tweaked
+ */
+ public AWSQueryConnection getConnectionDelegate() {
+ return connection;
+ }
+
+ /**
+ * Adds to the topic's access control policy.
*
- * @param activationKey key obtained from the customer
- * @param productToken token for your product
- * @return the product info
+ * @param topicArn the ARN for the topic
+ * @param label the unique identifier for the new policy statement
+ * @param accountIds users being given access
+ * @param actionNames actions you are allowing
* @throws SNSException wraps checked exceptions
*/
public void addPermission(String topicArn, String label, List<String>
accountIds, List<String> actionNames) throws SNSException {
@@ -144,11 +153,12 @@
}

/**
- * Activates a hosted product.
+ * Verifies an endpoint intends to receive messages
*
- * @param activationKey key obtained from the customer
- * @param productToken token for your product
- * @return the product info
+ * @param topicArn the ARN for the topic
+ * @param token subscription token
+ * @param authenticateOnUnsubscribe requires authenticated unsubscribe
from the topic
+ * @return the subscription ARN
* @throws SNSException wraps checked exceptions
*/
public Result<String> confirmSubscription(String topicArn, String token,
boolean authenticateOnUnsubscribe) throws SNSException {
@@ -166,10 +176,10 @@
}

/**
- * Gets list of active subscriptions by persistent identifier
+ * Creates a topic
*
- * @param persistentIdentifier customers's PID
- * @return true if product is subscribed
+ * @param name name of the new topic
+ * @return the topic ARN
* @throws SNSException wraps checked exceptions
*/
public Result<String> createTopic(String name) throws SNSException {
@@ -184,10 +194,9 @@
}

/**
- * Gets list of active subscriptions by persistent identifier
+ * Deletes a topic
*
- * @param persistentIdentifier customers's PID
- * @return true if product is subscribed
+ * @param topicArn the ARN for the topic
* @throws SNSException wraps checked exceptions
*/
public void deleteTopic(String topicArn) throws SNSException {
@@ -198,11 +207,10 @@
}

/**
- * Gets the most up-to-date version of the user token.
+ * Gets attributes for the topic
*
- * @param userToken the user token
- * @param additionalTokens optional token (see dev guide), null if not
used
- * @return the list of product codes
+ * @param topicArn the ARN for the topic
+ * @return a map of attributes
* @throws SNSException wraps checked exceptions
*/
public Map<String, String> getTopicAttributes(String topicArn) throws
SNSException {
@@ -221,11 +229,10 @@
}

/**
- * Gets the most up-to-date version of the user token.
+ * Lists the subscriptions
*
- * @param userToken the user token
- * @param additionalTokens optional token (see dev guide), null if not
used
- * @return the list of product codes
+ * @param nextToken the user token
+ * @return the list of subscriptions
* @throws SNSException wraps checked exceptions
*/
public ListResult<SubscriptionInfo> listSubscriptions(String nextToken)
throws SNSException {
@@ -249,11 +256,10 @@
}

/**
- * Gets the most up-to-date version of the user token.
+ * Lists subscriptions for a topic
*
- * @param userToken the user token
- * @param additionalTokens optional token (see dev guide), null if not
used
- * @return the list of product codes
+ * @param nextToken the user token
+ * @return the list of subscriptions
* @throws SNSException wraps checked exceptions
*/
public ListResult<SubscriptionInfo> listSubscriptionsByTopic(String
topicArn, String nextToken) throws SNSException {
@@ -278,11 +284,10 @@
}

/**
- * Gets the most up-to-date version of the user token.
+ * Lists topics for this account
*
- * @param userToken the user token
- * @param additionalTokens optional token (see dev guide), null if not
used
- * @return the list of product codes
+ * @param nextToken the user token
+ * @return the list of topics
* @throws SNSException wraps checked exceptions
*/
public ListResult<String> listTopics(String nextToken) throws
SNSException {
@@ -305,9 +310,11 @@
}

/**
- * Gets list of active subscriptions by persistent identifier
+ * Publishes a message to a topic's subscribed endpoints
*
- * @param persistentIdentifier customers's PID
+ * @param topicArn the ARN for the topic
+ * @param message the message to be sent
+ * @param subject the optional subject for the message
* @return true if product is subscribed
* @throws SNSException wraps checked exceptions
*/
@@ -327,10 +334,10 @@
}

/**
- * Gets list of active subscriptions by persistent identifier
+ * Removes permissions from a topic
*
- * @param persistentIdentifier customers's PID
- * @return true if product is subscribed
+ * @param topicArn the ARN for the topic
+ * @param label the label for the permission statement
* @throws SNSException wraps checked exceptions
*/
public void removePermission(String topicArn, String label) throws
SNSException {
@@ -342,10 +349,11 @@
}

/**
- * Gets list of active subscriptions by persistent identifier
+ * Set a topic attribute.
*
- * @param persistentIdentifier customers's PID
- * @return true if product is subscribed
+ * @param topicArn the ARN for the topic
+ * @param name name of the attribute
+ * @param value value of the attribute
* @throws SNSException wraps checked exceptions
*/
public void setTopicAttributes(String topicArn, String name, String
value) throws SNSException {
@@ -358,10 +366,9 @@
}

/**
- * Gets list of active subscriptions by persistent identifier
+ * Subscribe this account to a topic
*
- * @param persistentIdentifier customers's PID
- * @return true if product is subscribed
+ * @param topicArn the ARN for the topic
* @throws SNSException wraps checked exceptions
*/
public Result<String> subscribe(String topicArn, String protocol, String
endpoint) throws SNSException {
@@ -378,10 +385,9 @@
}

/**
- * Gets list of active subscriptions by persistent identifier
+ * Unsubscribe this account from a topic
*
- * @param persistentIdentifier customers's PID
- * @return true if product is subscribed
+ * @param topicArn the ARN for the topic
* @throws SNSException wraps checked exceptions
*/
public void unsubscribe(String subscriptionArn) throws SNSException {
@@ -394,7 +400,7 @@
protected <T> T makeRequestInt(HttpRequestBase method, String action,
Map<String, String> params, Class<T> respType)
throws SNSException {
try {
- return makeRequest(method, action, params, respType);
+ return connection.makeRequest(method, action, params, respType);
} catch (AWSException ex) {
throw new SNSException(ex);
} catch (JAXBException ex) {

Reply all
Reply to author
Forward
0 new messages