List of usage examples for com.amazonaws.services.sns.model PublishRequest setMessageAttributes
public void setMessageAttributes(java.util.Map<String, MessageAttributeValue> messageAttributes)
Message attributes for Publish action.
From source file:AmazonSNSClientWrapper.java
License:Open Source License
private PublishResult publish(String endpointArn, SampleMessageGenerator.Platform platform, Map<SampleMessageGenerator.Platform, Map<String, MessageAttributeValue>> attributesMap) { PublishRequest publishRequest = new PublishRequest(); Map<String, MessageAttributeValue> notificationAttributes = getValidNotificationAttributes( attributesMap.get(platform)); if (notificationAttributes != null && !notificationAttributes.isEmpty()) { publishRequest.setMessageAttributes(notificationAttributes); }/*from w w w. j a va2 s . c o m*/ publishRequest.setMessageStructure("json"); // If the message attributes are not set in the requisite method, // notification is sent with default attributes String message = getPlatformSampleMessage(platform); Map<String, String> messageMap = new HashMap<String, String>(); messageMap.put(platform.name(), message); message = SampleMessageGenerator.jsonify(messageMap); // For direct publish to mobile end points, topicArn is not relevant. publishRequest.setTargetArn(endpointArn); // Display the message that will be sent to the endpoint/ System.out.println("{Message Body: " + message + "}"); StringBuilder builder = new StringBuilder(); builder.append("{Message Attributes: "); for (Map.Entry<String, MessageAttributeValue> entry : notificationAttributes.entrySet()) { builder.append("(\"" + entry.getKey() + "\": \"" + entry.getValue().getStringValue() + "\"),"); } builder.deleteCharAt(builder.length() - 1); builder.append("}"); System.out.println(builder.toString()); publishRequest.setMessage(message); return snsClient.publish(publishRequest); }
From source file:com.aws.sns.service.notifications.sns.AmazonSNSClientWrapper.java
License:Open Source License
private PublishResult publish(String endpointArn, Platform platform, Map<Platform, Map<String, MessageAttributeValue>> attributesMap, String messageText, String payloadAction, String collapseKey) { PublishRequest publishRequest = new PublishRequest(); Map<String, MessageAttributeValue> notificationAttributes = getValidNotificationAttributes( attributesMap.get(platform)); if (notificationAttributes != null && !notificationAttributes.isEmpty()) { publishRequest.setMessageAttributes(notificationAttributes); }/*w w w . ja v a2 s . co m*/ publishRequest.setMessageStructure("json"); // If the message attributes are not set in the requisite method, // notification is sent with default attributes String message = getPlatformSampleMessage(platform, messageText, payloadAction, collapseKey); Map<String, String> messageMap = new HashMap<String, String>(); messageMap.put(platform.name(), message); message = SNSPlatformHelper.jsonify(messageMap); // For direct publish to mobile end points, topicArn is not relevant. publishRequest.setTargetArn(endpointArn); // Display the message that will be sent to the endpoint/ System.out.println("{Message Body: " + message + "}"); StringBuilder builder = new StringBuilder(); builder.append("{Message Attributes: "); for (Map.Entry<String, MessageAttributeValue> entry : notificationAttributes.entrySet()) { builder.append("(\"" + entry.getKey() + "\": \"" + entry.getValue().getStringValue() + "\"),"); } builder.deleteCharAt(builder.length() - 1); builder.append("}"); System.out.println(builder.toString()); publishRequest.setMessage(message); return snsClient.publish(publishRequest); }
From source file:com.dev.appx.sns.tools.AmazonSNSClientWrapper.java
License:Open Source License
public PublishResult publish(String endpointArn, Platform platform, Map<Platform, Map<String, MessageAttributeValue>> attributesMap) { PublishRequest publishRequest = new PublishRequest(); Map<String, MessageAttributeValue> notificationAttributes = getValidNotificationAttributes( attributesMap.get(platform)); if (notificationAttributes != null && !notificationAttributes.isEmpty()) { publishRequest.setMessageAttributes(notificationAttributes); }//from ww w . j av a 2 s .c o m publishRequest.setMessageStructure("json"); // If the message attributes are not set in the requisite method, // notification is sent with default attributes String message = getPlatformSampleMessage(platform); Map<String, String> messageMap = new HashMap<String, String>(); messageMap.put(platform.name(), message); message = SampleMessageGenerator.jsonify(messageMap); // For direct publish to mobile end points, topicArn is not relevant. publishRequest.setTargetArn(endpointArn); // Display the message that will be sent to the endpoint/ System.out.println("{Message Body: " + message + "}"); StringBuilder builder = new StringBuilder(); builder.append("{Message Attributes: "); for (Map.Entry<String, MessageAttributeValue> entry : notificationAttributes.entrySet()) { builder.append("(\"" + entry.getKey() + "\": \"" + entry.getValue().getStringValue() + "\"),"); } builder.deleteCharAt(builder.length() - 1); builder.append("}"); System.out.println(builder.toString()); publishRequest.setMessage(message); return snsClient.publish(publishRequest); }
From source file:com.gafful.AmazonSNSClientWrapper.java
License:Open Source License
private PublishResult publish(String endpointArn, Platform platform, Map<Platform, Map<String, MessageAttributeValue>> attributesMap) { PublishRequest publishRequest = new PublishRequest(); Map<String, MessageAttributeValue> notificationAttributes = getValidNotificationAttributes( attributesMap.get(platform)); if (notificationAttributes != null && !notificationAttributes.isEmpty()) { publishRequest.setMessageAttributes(notificationAttributes); }/*from ww w.j ava2 s .co m*/ publishRequest.setMessageStructure("json"); // If the message attributes are not set in the requisite method, // notification is sent with default attributes String message = getPlatformSampleMessage(platform); Map<String, String> messageMap = new HashMap<String, String>(); messageMap.put(platform.name(), message); message = SampleMessageGenerator.jsonify(messageMap); // For direct publish to mobile end points, topicArn is not relevant. publishRequest.setTargetArn(endpointArn); // Display the message that will be sent to the endpoint/ System.out.println("{Message Body: " + message + "}"); StringBuilder builder = new StringBuilder(); builder.append("{Message Attributes: "); for (Map.Entry<String, MessageAttributeValue> entry : notificationAttributes.entrySet()) { builder.append("(\"" + entry.getKey() + "\": \"" + entry.getValue().getStringValue() + "\"),"); } builder.deleteCharAt(builder.length() - 1); builder.append("}"); System.out.println(builder.toString()); publishRequest.setMessage(message); return snsClient.publish(publishRequest); }
From source file:com.mistminds.service.AmazonSNSClientWrapper.java
License:Open Source License
private PublishResult publish(String endpointArn, Platform platform, Map<Platform, Map<String, MessageAttributeValue>> attributesMap, Map<String, String> pushData) { PublishRequest publishRequest = new PublishRequest(); Map<String, MessageAttributeValue> notificationAttributes = getValidNotificationAttributes( attributesMap.get(platform)); if (notificationAttributes != null && !notificationAttributes.isEmpty()) { publishRequest.setMessageAttributes(notificationAttributes); }// w ww . j a v a 2 s . c o m publishRequest.setMessageStructure("json"); // If the message attributes are not set in the requisite method, // notification is sent with default attributes String message = SampleMessageGenerator.getSampleAndroidMessage(pushData); Map<String, String> messageMap = new HashMap<String, String>(); messageMap.put("default", message); message = SampleMessageGenerator.jsonify(messageMap); // For direct publish to mobile end points, topicArn is not relevant. publishRequest.setTargetArn(endpointArn); // Display the message that will be sent to the endpoint/ System.out.println("{Message Body: " + message + "}"); StringBuilder builder = new StringBuilder(); builder.append("{Message Attributes: "); for (Map.Entry<String, MessageAttributeValue> entry : notificationAttributes.entrySet()) { builder.append("(\"" + entry.getKey() + "\": \"" + entry.getValue().getStringValue() + "\"),"); } builder.deleteCharAt(builder.length() - 1); builder.append("}"); System.out.println(builder.toString()); publishRequest.setMessage(message); return snsClient.publish(publishRequest); }
From source file:com.onemenu.server.util.awsnotification.tools.AmazonSNSClientWrapper.java
License:Open Source License
private PublishResult publish(String endpointArn, Platform platform, Map<Platform, Map<String, MessageAttributeValue>> attributesMap, String message) { PublishRequest publishRequest = new PublishRequest(); Map<String, MessageAttributeValue> notificationAttributes = getValidNotificationAttributes( attributesMap.get(platform)); if (notificationAttributes != null && !notificationAttributes.isEmpty()) { publishRequest.setMessageAttributes(notificationAttributes); }//from w ww . ja va 2s. co m 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<String, String>(); messageMap.put(platform.name(), message); message = MessageGenerator.jsonify(messageMap); // For direct publish to mobile end points, topicArn is not relevant. publishRequest.setTargetArn(endpointArn); // Display the message that will be sent to the endpoint/ System.out.println("{Message Body: " + message + "}"); StringBuilder builder = new StringBuilder(); builder.append("{Message Attributes: "); for (Map.Entry<String, MessageAttributeValue> entry : notificationAttributes.entrySet()) { builder.append("(\"" + entry.getKey() + "\": \"" + entry.getValue().getStringValue() + "\"),"); } builder.deleteCharAt(builder.length() - 1); builder.append("}"); System.out.println(builder.toString()); publishRequest.setMessage(message); return snsClient.publish(publishRequest); }
From source file:com.screensaver.util.AmazonSNSClientWrapper.java
License:Open Source License
private PublishResult publish(String endpointArn, SampleMessageGenerator.Platform platform, Map<SampleMessageGenerator.Platform, Map<String, MessageAttributeValue>> attributesMap) { PublishRequest publishRequest = new PublishRequest(); Map<String, MessageAttributeValue> notificationAttributes = getValidNotificationAttributes( attributesMap.get(platform)); if (notificationAttributes != null && !notificationAttributes.isEmpty()) { publishRequest.setMessageAttributes(notificationAttributes); }// w w w . j av a 2 s .c o m publishRequest.setMessageStructure("json"); // If the message attributes are not set in the requisite method, // notification is sent with default attributes String message = getPlatformSampleMessage(platform); Map<String, String> messageMap = new HashMap<String, String>(); messageMap.put(platform.name(), message); message = SampleMessageGenerator.jsonify(messageMap); // For direct publish to mobile end points, topicArn is not relevant. publishRequest.setTargetArn(endpointArn); // Display the message that will be sent to the endpoint/ System.out.println("{Message Body: " + message + "}"); StringBuilder builder = new StringBuilder(); builder.append("{Message Attributes: "); for (Map.Entry<String, MessageAttributeValue> entry : notificationAttributes.entrySet()) { builder.append("(\"" + entry.getKey() + "\": \"" + entry.getValue().getStringValue() + "\"),"); } builder.deleteCharAt(builder.length() - 1); builder.append("}"); System.out.println(builder.toString()); publishRequest.setMessage(message); return snsClient.publish(publishRequest); }
From source file:edu.utn.frba.grupo5303.serverenviolibre.services.NotificacionesPushService.java
@Override public void enviarNotificacion(NotificacionPush notificacion) { try {/* w w w . j a va 2s.c om*/ 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:tools.AmazonSNSClientWrapper.java
License:Open Source License
private PublishResult publish(String endpointArn, Platform platform, Map<Platform, Map<String, MessageAttributeValue>> attributesMap) { PublishRequest publishRequest = new PublishRequest(); Map<String, MessageAttributeValue> notificationAttributes = getValidNotificationAttributes( attributesMap.get(platform)); if (notificationAttributes != null && !notificationAttributes.isEmpty()) { publishRequest.setMessageAttributes(notificationAttributes); }/*from w ww .j av a2s. c om*/ publishRequest.setMessageStructure("json"); // If the message attributes are not set in the requisite method, // notification is sent with default attributes String message = getPlatformSampleMessage(platform); Map<String, String> messageMap = new HashMap<String, String>(); messageMap.put(platform.name(), message); message = SampleMessageGenerator.jsonify(messageMap); // For direct publish to mobile end points, topicArn is not relevant. publishRequest.setTargetArn(endpointArn); // Display the message that will be sent to the endpoint/ System.out.println("{Message Body: " + message + "}"); StringBuilder builder = new StringBuilder(); builder.append("{Message Attributes: "); for (Map.Entry<String, MessageAttributeValue> entry : notificationAttributes.entrySet()) { builder.append("(\"" + entry.getKey() + "\": \"" + entry.getValue().getStringValue() + "\"),"); } builder.deleteCharAt(builder.length() - 1); builder.append("}"); System.out.println(builder.toString()); publishRequest.setMessage(message); PublishResult result = null; try { result = snsClient.publish(publishRequest); } catch (EndpointDisabledException e) { System.out.println("Endpoint disabled: TODO remove from dynamo DB"); } catch (Exception e) { log.log(Level.SEVERE, e.getMessage(), e); } return result; }