Package com.amazonaws.services.sns.model

Examples of com.amazonaws.services.sns.model.SubscribeRequest


    String id = rand.nextLong() + "";
   
    String rawEndPointUrl = CMBTestingConstants.HTTP_ENDPOINT_BASE_URL + "recv/" + id;
    String rawEndPointLastMessageUrl = CMBTestingConstants.HTTP_ENDPOINT_BASE_URL + "info/" + id + "?showLast=true";
   
    SubscribeRequest rawEndPointSubscribeRequest = new SubscribeRequest();
    rawEndPointSubscribeRequest.setEndpoint(rawEndPointUrl);
    rawEndPointSubscribeRequest.setProtocol("http");
    rawEndPointSubscribeRequest.setTopicArn(topicArn);
    SubscribeResult subscribeResult = cns1.subscribe(rawEndPointSubscribeRequest);
    String rawEndPointsubscriptionArn = subscribeResult.getSubscriptionArn();
   
    if (rawEndPointsubscriptionArn.equals("pending confirmation")) {
     
      Thread.sleep(500);       
      String response = CNSTestingUtils.sendHttpMessage(rawEndPointLastMessageUrl, "");
      logger.info(response);
      JSONObject o = new JSONObject(response);
      if (!o.has("SubscribeURL")) {
        throw new Exception("message is not a confirmation messsage");
      }
      String subscriptionUrl = o.getString("SubscribeURL");
      response = CNSTestingUtils.sendHttpMessage(subscriptionUrl, "");
     
      String startTag = "<SubscriptionArn>";
      String endTag = "</SubscriptionArn>";
      int startIndex = response.indexOf(startTag);
      int endIndex = response.indexOf(endTag);
      String subArn = response.substring(startIndex + startTag.length(), endIndex);
      if (subArn != null && !subArn.isEmpty()) {
        rawEndPointsubscriptionArn = subArn;
      }
      logger.info("Raw-message EndPoint subscription Arn after confirmation: " + rawEndPointsubscriptionArn);
    }
   
    // set subscription attribute for raw message delivery
   
    Boolean rawMessageDelivery = true;
    try {
      SetSubscriptionAttributesRequest setSubscriptionAttributesRequest = new SetSubscriptionAttributesRequest(rawEndPointsubscriptionArn, "RawMessageDelivery", rawMessageDelivery.toString());
      cns1.setSubscriptionAttributes(setSubscriptionAttributesRequest);
     
      Map<String, String> attributes = null;
      GetSubscriptionAttributesRequest getSubscriptionAttributesRequest = new GetSubscriptionAttributesRequest(rawEndPointsubscriptionArn);
      GetSubscriptionAttributesResult getSubscriptionAttributesResult = cns1.getSubscriptionAttributes(getSubscriptionAttributesRequest);
      attributes = getSubscriptionAttributesResult.getAttributes();
      String rawMessageDeliveryStr = attributes.get("RawMessageDelivery");
      if (rawMessageDeliveryStr != null && !rawMessageDeliveryStr.isEmpty()) {
        rawMessageDelivery = Boolean.parseBoolean(rawMessageDeliveryStr);
        assertTrue("Set raw message delivery successful", rawMessageDelivery);
      } else {
        fail("no raw message delivery flag found");
      }
      logger.info("Raw Message Delivery attribute:" + rawMessageDeliveryStr);
    } catch (Exception ex) {
      throw new Exception("Can't set raw message delivery attribute to subscription arn " + rawEndPointsubscriptionArn);
    }
   
    // subscribe and confirm http endpoint to receive JSON message
    id = rand.nextLong() + "";
    String jsonEndPointUrl = CMBTestingConstants.HTTP_ENDPOINT_BASE_URL + "recv/" + id;
    String jsonEndPointLastMessageUrl = CMBTestingConstants.HTTP_ENDPOINT_BASE_URL + "info/" + id + "?showLast=true";
   
    SubscribeRequest jsonEndPointSubscribeRequest = new SubscribeRequest();
    jsonEndPointSubscribeRequest.setEndpoint(jsonEndPointUrl);
    jsonEndPointSubscribeRequest.setProtocol("http");
    jsonEndPointSubscribeRequest.setTopicArn(topicArn);
    SubscribeResult jsonSubscribeResult = cns1.subscribe(jsonEndPointSubscribeRequest);
    String jsonEndPointsubscriptionArn = jsonSubscribeResult.getSubscriptionArn();
    logger.info("JSON EndPoint subscription arn:" + jsonEndPointsubscriptionArn);
   
    if (jsonEndPointsubscriptionArn.equals("pending confirmation")) {
View Full Code Here


        }
      }
    }
    if (snsUrlSubscriptionArn == null) {

      SubscribeRequest request = new SubscribeRequest(topicArn,
          urlSubscription.getProtocol(),
          urlSubscription.getEndpoint());
      SubscribeResult result = client.subscribe(request);
      snsUrlSubscriptionArn = result.getSubscriptionArn();
      log.info("Subscribed URL to SNS with subscription ARN: "
View Full Code Here

        snsSqsSubscriptionArn = subscription.getSubscriptionArn();
        break;
      }
    }
    if (snsSqsSubscriptionArn == null) {
      SubscribeRequest request = new SubscribeRequest(topicArn,
          sqsSubscription.getProtocol(),
          sqsSubscription.getEndpoint());
      SubscribeResult result = client.subscribe(request);
      snsSqsSubscriptionArn = result.getSubscriptionArn();
      log.info("Subscribed SQS to SNS with subscription ARN: "
View Full Code Here

                    .withActions(SQSActions.SendMessage)
                    .withResources(new Resource(queueARN))
                    .withConditions(ConditionFactory.newSourceArnCondition(topicArn)));
        sqs.setQueueAttributes(new SetQueueAttributesRequest(queueUrl, newAttributes("Policy", sqsPolicy.toJson())));

        sns.subscribe(new SubscribeRequest(topicArn, "sqs", queueARN));
    }
View Full Code Here

TOP

Related Classes of com.amazonaws.services.sns.model.SubscribeRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.