List of usage examples for com.amazonaws.services.sns.model CreatePlatformApplicationResult getPlatformApplicationArn
public String getPlatformApplicationArn()
PlatformApplicationArn is returned.
From source file:AmazonSNSClientWrapper.java
License:Open Source License
public void demoNotification(SampleMessageGenerator.Platform platform, String principal, String credential, String platformToken, String applicationName, Map<SampleMessageGenerator.Platform, Map<String, MessageAttributeValue>> attrsMap) { // Create Platform Application. This corresponds to an app on a // platform./* w ww .j av a 2 s.c om*/ CreatePlatformApplicationResult platformApplicationResult = createPlatformApplication(applicationName, platform, principal, credential); System.out.println(platformApplicationResult); // The Platform Application Arn can be used to uniquely identify the // Platform Application. String platformApplicationArn = platformApplicationResult.getPlatformApplicationArn(); // Create an Endpoint. This corresponds to an app on a device. CreatePlatformEndpointResult platformEndpointResult = createPlatformEndpoint(platform, "CustomData - Useful to store endpoint specific data", platformToken, platformApplicationArn); System.out.println(platformEndpointResult); // Publish a push notification to an Endpoint. PublishResult publishResult = publish(platformEndpointResult.getEndpointArn(), platform, attrsMap); System.out.println("Published! \n{MessageId=" + publishResult.getMessageId() + "}"); // Delete the Platform Application since we will no longer be using it. deletePlatformApplication(platformApplicationArn); }
From source file:com.aws.sns.service.notifications.sns.AmazonSNSClientWrapper.java
License:Open Source License
public void demoNotification(Platform platform, String principal, String credential, String platformToken, String applicationName, Map<Platform, Map<String, MessageAttributeValue>> attrsMap, String messageText, String payloadAction, String collapseKey) { // Create Platform Application. This corresponds to an app on a // platform.//from www.j ava 2 s. co m CreatePlatformApplicationResult platformApplicationResult = createPlatformApplication(applicationName, platform, principal, credential); System.out.println(platformApplicationResult); // The Platform Application Arn can be used to uniquely identify the // Platform Application. String platformApplicationArn = platformApplicationResult.getPlatformApplicationArn(); // Create an Endpoint. This corresponds to an app on a device. CreatePlatformEndpointResult platformEndpointResult = createPlatformEndpoint(platform, "CustomData - Useful to store endpoint specific data", platformToken, platformApplicationArn); System.out.println(platformEndpointResult); // Publish a push notification to an Endpoint. PublishResult publishResult = publish(platformEndpointResult.getEndpointArn(), platform, attrsMap, messageText, payloadAction, collapseKey); System.out.println("Published! \n{MessageId=" + publishResult.getMessageId() + "}"); // Delete the Platform Application since we will no longer be using it. deletePlatformApplication(platformApplicationArn); }
From source file:com.cloudbees.gasp.services.SNSMobile.java
License:Open Source License
public String getPlatformArn(Platform platform, String principal, String credential, String applicationName) { switch (platform) { case APNS_SANDBOX: case GCM:/*from w ww . j a va2 s. c o m*/ // Create Platform Application. This corresponds to an app on a platform. CreatePlatformApplicationResult platformApplicationResult = createPlatformApplication(applicationName, platform, principal, credential); // The Platform Application Arn can be used to uniquely identify the Platform Application. String platformApplicationArn = platformApplicationResult.getPlatformApplicationArn(); LOGGER.debug("Created Platform Application Arn: " + platformApplicationArn); return platformApplicationArn; default: throw new IllegalArgumentException("Platform Not supported : " + platform.name()); } }
From source file:com.dev.appx.sns.tools.AmazonSNSClientWrapper.java
License:Open Source License
public void demoNotification(Platform platform, String principal, String credential, String platformToken, String applicationName, Map<Platform, Map<String, MessageAttributeValue>> attrsMap) { // Create Platform Application. This corresponds to an app on a // platform./*from w ww .jav a 2 s .co m*/ CreatePlatformApplicationResult platformApplicationResult = createPlatformApplication(applicationName, platform, principal, credential); System.out.println(platformApplicationResult); // The Platform Application Arn can be used to uniquely identify the // Platform Application. String platformApplicationArn = platformApplicationResult.getPlatformApplicationArn(); // Create an Endpoint. This corresponds to an app on a device. CreatePlatformEndpointResult platformEndpointResult = createPlatformEndpoint(platform, "CustomData - Useful to store endpoint specific data", platformToken, platformApplicationArn); System.out.println(platformEndpointResult); // Publish a push notification to an Endpoint. PublishResult publishResult = publish(platformEndpointResult.getEndpointArn(), platform, attrsMap); System.out.println("Published! \n{MessageId=" + publishResult.getMessageId() + "}"); // Delete the Platform Application since we will no longer be using it. deletePlatformApplication(platformApplicationArn); }
From source file:com.hrt.modules.aws.sns.AmazonSnsClientWrapper.java
License:Open Source License
public void demoNotification(Platform platform, String principal, String credential, String platformToken, String applicationName, Map<Platform, Map<String, MessageAttributeValue>> attrsMap) { // Create Platform Application. This corresponds to an app on a // platform./*from w ww.ja v a2 s. c om*/ CreatePlatformApplicationResult platformApplicationResult = createPlatformApplication(applicationName, platform, principal, credential); System.out.println(platformApplicationResult); // The Platform Application Arn can be used to uniquely identify the // Platform Application. String platformApplicationArn = platformApplicationResult.getPlatformApplicationArn(); // Create an Endpoint. This corresponds to an app on a device. CreatePlatformEndpointResult platformEndpointResult = createPlatformEndpoint(platform, "CustomData - Useful to store endpoint specific data", platformToken, platformApplicationArn); System.out.println(platformEndpointResult); System.out.println("\n\n>>>>>> platformEndpointResult.getEndpointArn() = " + platformEndpointResult.getEndpointArn() + "\n\n"); // String ARN = "arn:aws:sns:us-west-2:043482212558:endpoint/APNS_SANDBOX/Homeroom-Notifications/6c6c1c8e-19be-3a9c-82e4-b5fab2e2a603"; // PublishResult publishResult = publish( ARN, platform, attrsMap); // Publish a push notification to an Endpoint. PublishResult publishResult = publish(platformEndpointResult.getEndpointArn(), platform, attrsMap); System.out.println("Published! \n{MessageId=" + publishResult.getMessageId() + "}"); // Delete the Platform Application since we will no longer be using it. deletePlatformApplication(platformApplicationArn); }
From source file:com.mistminds.service.AmazonSNSClientWrapper.java
License:Open Source License
public void demoNotification(Platform platform, String principal, String credential, String platformToken, String applicationName, Map<Platform, Map<String, MessageAttributeValue>> attrsMap, Map<String, String> pushData) { // Create Platform Application. This corresponds to an app on a // platform.// ww w. jav a 2 s. c o m pushData.remove("installationId"); CreatePlatformApplicationResult platformApplicationResult = createPlatformApplication(applicationName, platform, principal, credential); System.out.println(platformApplicationResult); // The Platform Application Arn can be used to uniquely identify the // Platform Application. String platformApplicationArn = platformApplicationResult.getPlatformApplicationArn(); // Create an Endpoint. This corresponds to an app on a device. CreatePlatformEndpointResult platformEndpointResult = createPlatformEndpoint(platform, "CustomData - Useful to store endpoint specific data", platformToken, platformApplicationArn); System.out.println(platformEndpointResult); // Publish a push notification to an Endpoint. PublishResult publishResult = publish(platformEndpointResult.getEndpointArn(), platform, attrsMap, pushData); System.out.println("Published! \n{MessageId=" + publishResult.getMessageId() + "}"); // Delete the Platform Application since we will no longer be using it. deletePlatformApplication(platformApplicationArn); }
From source file:com.onemenu.server.util.awsnotification.tools.AmazonSNSClientWrapper.java
License:Open Source License
public void notification(Platform platform, String principal, String credential, String platformToken, String applicationName, Map<Platform, Map<String, MessageAttributeValue>> attrsMap, String message) { // Create Platform Application. This corresponds to an app on a // platform./* w ww . j a v a2 s . c o m*/ CreatePlatformApplicationResult platformApplicationResult = createPlatformApplication(applicationName, platform, principal, credential); System.out.println(platformApplicationResult); // The Platform Application Arn can be used to uniquely identify the // Platform Application. String platformApplicationArn = platformApplicationResult.getPlatformApplicationArn(); // Create an Endpoint. This corresponds to an app on a device. CreatePlatformEndpointResult platformEndpointResult = createPlatformEndpoint(platform, "CustomData - Useful to store endpoint specific data", platformToken, platformApplicationArn); System.out.println(platformEndpointResult); // Publish a push notification to an Endpoint. PublishResult publishResult = publish(platformEndpointResult.getEndpointArn(), platform, attrsMap, message); System.out.println("Published! \n{MessageId=" + publishResult.getMessageId() + "}"); // Delete the Platform Application since we will no longer be using it. deletePlatformApplication(platformApplicationArn); }
From source file:com.screensaver.util.AmazonSNSClientWrapper.java
License:Open Source License
public void demoNotification(Platform platform, String principal, String credential, String platformToken, String applicationName, Map<Platform, Map<String, MessageAttributeValue>> attrsMap) { String prefEndpointArn = PrefUtils.getString(context, Constants.PREF_END_POINT_ARN, ""); boolean updateNeeded = false; boolean createNeeded = false; if (prefEndpointArn != null && !prefEndpointArn.equalsIgnoreCase("")) { createNeeded = false;/* w w w . j ava2 s .c om*/ } else { createNeeded = true; } if (createNeeded) { // Create Platform Application. This corresponds to an app on a // platform. try { CreatePlatformApplicationResult platformApplicationResult = createPlatformApplication( applicationName, platform, principal, credential); // The Platform Application Arn can be used to uniquely identify the // Platform Application. String platformApplicationArn = platformApplicationResult.getPlatformApplicationArn(); // Create an Endpoint. This corresponds to an app on a device. CreatePlatformEndpointResult platformEndpointResult = createPlatformEndpoint(platform, "CustomData - Useful to store endpoint specific data", platformToken, platformApplicationArn); System.out.println(platformEndpointResult); prefEndpointArn = platformEndpointResult.getEndpointArn(); PrefUtils.saveString(context, Constants.PREF_END_POINT_ARN, prefEndpointArn); // Publish a push notification to an Endpoint. CreateTopicResult createTopicResult = createTopic(platform, "CustomData - Useful to store endpoint specific data", platformToken, platformApplicationArn); SubscribeRequest subscribeRequest = new SubscribeRequest(createTopicResult.getTopicArn(), "application", platformEndpointResult.getEndpointArn()); snsClient.subscribe(subscribeRequest); createNeeded = false; } catch (Exception e) { String message = e.getMessage(); System.out.println("Exception message: " + message); Pattern p = Pattern .compile(".*Endpoint (arn:aws:sns[^ ]+) already exists " + "with the same token.*"); Matcher m = p.matcher(message); if (m.matches()) { // The platform endpoint already exists for this token, but with // additional custom data that // createEndpoint doesn't want to overwrite. Just use the // existing platform endpoint. prefEndpointArn = m.group(1); PrefUtils.saveString(context, Constants.PREF_END_POINT_ARN, prefEndpointArn); } else { // Rethrow the exception, the input is actually bad. throw e; } } } try { GetEndpointAttributesRequest geaReq = new GetEndpointAttributesRequest() .withEndpointArn(prefEndpointArn); GetEndpointAttributesResult geaRes = snsClient.getEndpointAttributes(geaReq); updateNeeded = !geaRes.getAttributes().get("Token").equals(platformToken) || !geaRes.getAttributes().get("Enabled").equalsIgnoreCase("true"); } catch (Exception nfe) { // We had a stored ARN, but the platform endpoint associated with it // disappeared. Recreate it. createNeeded = true; } if (createNeeded) { // Create Platform Application. This corresponds to an app on a // platform. try { CreatePlatformApplicationResult platformApplicationResult = createPlatformApplication( applicationName, platform, principal, credential); // The Platform Application Arn can be used to uniquely identify the // Platform Application. String platformApplicationArn = platformApplicationResult.getPlatformApplicationArn(); // Create an Endpoint. This corresponds to an app on a device. CreatePlatformEndpointResult platformEndpointResult = createPlatformEndpoint(platform, "", platformToken, platformApplicationArn); System.out.println(platformEndpointResult); prefEndpointArn = platformEndpointResult.getEndpointArn(); PrefUtils.saveString(context, Constants.PREF_END_POINT_ARN, prefEndpointArn); // Publish a push notification to an Endpoint. CreateTopicResult createTopicResult = createTopic(platform, "", platformToken, platformApplicationArn); SubscribeRequest subscribeRequest = new SubscribeRequest(createTopicResult.getTopicArn(), "application", platformEndpointResult.getEndpointArn()); snsClient.subscribe(subscribeRequest); createNeeded = false; } catch (Exception e) { String message = e.getMessage(); System.out.println("Exception message: " + message); Pattern p = Pattern .compile(".*Endpoint (arn:aws:sns[^ ]+) already exists " + "with the same token.*"); Matcher m = p.matcher(message); if (m.matches()) { // The platform endpoint already exists for this token, but with // additional custom data that // createEndpoint doesn't want to overwrite. Just use the // existing platform endpoint. prefEndpointArn = m.group(1); PrefUtils.saveString(context, Constants.PREF_END_POINT_ARN, prefEndpointArn); } else { // Rethrow the exception, the input is actually bad. throw e; } } } if (updateNeeded) { Map attribs = new HashMap(); attribs.put("Token", platformToken); attribs.put("Enabled", "true"); SetEndpointAttributesRequest saeReq = new SetEndpointAttributesRequest() .withEndpointArn(prefEndpointArn).withAttributes(attribs); snsClient.setEndpointAttributes(saeReq); } // PublishResult publishResult = publish(subscribeRequest.getEndpoint(), platform, attrsMap); // Delete the Platform Application since we will no longer be using it. // deletePlatformApplication(platformApplicationArn); }
From source file:edu.utn.frba.grupo5303.serverenviolibre.services.NotificacionesPushService.java
@Override public void enviarNotificacion(NotificacionPush notificacion) { try {//w ww .j a va 2s.c o m logger.log(Level.INFO, "Enviando notificacion al snsId: {0}", notificacion.getGcmIdDestino()); logger.log(Level.INFO, "Enviando notificacion de tipo: {0}", notificacion.getCodigo()); PublishRequest publishRequest = new PublishRequest(); Map<String, MessageAttributeValue> notificationAttributes = getValidNotificationAttributes( attributesMap.get(plataforma)); if (notificationAttributes != null && !notificationAttributes.isEmpty()) { publishRequest.setMessageAttributes(notificationAttributes); } publishRequest.setMessageStructure("json"); // If the message attributes are not set in the requisite method, // notification is sent with default attributes Map<String, String> messageMap = new HashMap<>(); messageMap.put(plataforma.name(), notificacion.getMensajeDeNotificacion()); String message = SampleMessageGenerator.jsonify(messageMap); // Create Platform Application. This corresponds to an app on a // platform. CreatePlatformApplicationResult platformApplicationResult = createPlatformApplication(); // The Platform Application Arn can be used to uniquely identify the // Platform Application. String platformApplicationArn = platformApplicationResult.getPlatformApplicationArn(); // Create an Endpoint. This corresponds to an app on a device. CreatePlatformEndpointResult platformEndpointResult = createPlatformEndpoint("CustomData", notificacion.getGcmIdDestino(), platformApplicationArn); // For direct publish to mobile end points, topicArn is not relevant. publishRequest.setTargetArn(platformEndpointResult.getEndpointArn()); publishRequest.setMessage(message); snsClient.publish(publishRequest); } catch (AmazonServiceException ase) { logger.log(Level.SEVERE, "Caught an AmazonServiceException, which means your request made it " + "to Amazon SNS, but was rejected with an error response for some reason."); logger.log(Level.SEVERE, "Error Message: {0}", ase.getMessage()); logger.log(Level.SEVERE, "HTTP Status Code: {0}", ase.getStatusCode()); logger.log(Level.SEVERE, "AWS Error Code: {0}", ase.getErrorCode()); logger.log(Level.SEVERE, "Error Type: {0}", ase.getErrorType()); logger.log(Level.SEVERE, "Request ID: {0}", ase.getRequestId()); } catch (AmazonClientException ace) { logger.log(Level.SEVERE, "Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with SNS, such as not " + "being able to access the network."); logger.log(Level.SEVERE, "Error Message: {0}", ace.getMessage()); } }
From source file:io.starter.messaging.tools.AmazonSNSClientWrapper.java
License:Open Source License
public void starterNotification(Platform platform, String principal, String credential, String platformToken, String applicationName, Map<Platform, Map<String, MessageAttributeValue>> attrsMap, String message) { // Create Platform Application. This corresponds to an app on a // platform.//from w w w . j ava 2 s . c o m CreatePlatformApplicationResult platformApplicationResult = createPlatformApplication(applicationName, platform, principal, credential); System.out.println(platformApplicationResult); // The Platform Application Arn can be used to uniquely identify the // Platform Application. String platformApplicationArn = platformApplicationResult.getPlatformApplicationArn(); // Create an Endpoint. This corresponds to an app on a device. CreatePlatformEndpointResult platformEndpointResult = createPlatformEndpoint(platform, "CustomData - Useful to store endpoint specific data", platformToken, platformApplicationArn); System.out.println(platformEndpointResult); // Publish a push notification to an Endpoint. PublishResult publishResult = publish(platformEndpointResult.getEndpointArn(), platform, attrsMap, message); System.out.println("Published! \n{MessageId=" + publishResult.getMessageId() + "}"); // Delete the Platform Application since we will no longer be using it. deletePlatformApplication(platformApplicationArn); }