Example usage for com.amazonaws.services.sns.model PublishRequest PublishRequest

List of usage examples for com.amazonaws.services.sns.model PublishRequest PublishRequest

Introduction

In this page you can find the example usage for com.amazonaws.services.sns.model PublishRequest PublishRequest.

Prototype

public PublishRequest(String topicArn, String message, String subject) 

Source Link

Document

Constructs a new PublishRequest object.

Usage

From source file:br.com.insula.log4j.sns.SNSAppender.java

License:Open Source License

private void publishMessage(String message) {
    try {/*from   w  w  w .  ja  v  a 2 s.  com*/
        amazonSNSAsync.publishAsync(new PublishRequest(topicArn, message, subject));
    } catch (AmazonClientException ex) {
        errorHandler.error("Unable to publish log message to SNS.");
    }
}

From source file:com.carrotgarden.log4j.aws.sns.Appender.java

License:BSD License

protected void publish(final String message, final String subject) {
    try {/*from   ww w  .java2  s  .  com*/

        final PublishRequest request = new PublishRequest(//
                topicARN, message, subject);

        amazonClient.publishAsync(request);

    } catch (final Exception e) {

        LogLog.error("sns: publish failure", e);

    }
}

From source file:com.comcast.cns.controller.CNSPublishToTopicPageServlet.java

License:Apache License

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    if (redirectUnauthenticatedUser(request, response)) {
        return;//from  ww w.j  ava  2  s  .c  om
    }

    CMBControllerServlet.valueAccumulator.initializeAllCounters();
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();

    String topicArn = request.getParameter("topicArn");
    String userId = request.getParameter("userId");
    String message = request.getParameter("message");
    String subject = request.getParameter("subject");
    Map<?, ?> parameters = request.getParameterMap();

    connect(request);

    out.println("<html>");

    header(request, out, "Publish");

    out.println("<script type='text/javascript' language='javascript'>");
    out.println("function changeMsgStructure(type) { ");
    out.println(" if (type == 'same')  ");
    out.println(" document.getElementById('message').value = ''; ");
    out.println(" else ");
    out.print(" document.getElementById('message').value = '{ \\n  default: <enter your message here>,\\n' + ");
    out.print("'  email: <enter your message here>,\\n' + ");
    out.print("'  cqs: <enter your message here>,\\n' +");
    //out.print("'  sms: <enter your message here>,\\n'+");
    out.print("'  http: <enter your message here>,\\n'+");
    out.print("'  https: <enter your message here> \\n}';");
    out.println("}");
    out.println("</script>");

    out.println("<body>");

    out.println("<h2>Publish to Topic</h2>");

    if (parameters.containsKey("Publish")) {

        out.println("<table><tr><td><b>");

        try {

            PublishRequest publishRequest = new PublishRequest(topicArn, message, subject);
            sns.publish(publishRequest);
            logger.debug("event=publish topic_arn=" + topicArn + " user_id= " + userId);

        } catch (Exception ex) {
            logger.error("event=publish topic_arn=" + topicArn + " user_id= " + userId);
            throw new ServletException(ex);
        }

        out.println("</b></td></tr>");
        out.println(
                "<tr><td align=right><br/><input type='button' name='Close' value='Close' onclick='window.close()'></td></tr></table>");

    } else {

        if (topicArn != null) {

            out.print("<form action=\"/webui/cnsuser/publish?topicArn=" + topicArn + "&userId=" + userId + "\" "
                    + "method=POST>");
            out.println("<table><tr><td><b>Topic Name:</b></td><td>" + Util.getNameFromTopicArn(topicArn)
                    + "</td></tr>");
            out.println("<tr><td>&nbsp;</td><td>&nbsp;</td></tr>");
            out.println(
                    "<tr><td valign=top><b>Subject:</b></td><td valign=top><input type='text' size='90' name='subject'><br/><I><font color='grey'>Up to 100 printable ASCII characters (optional)</font></I></td></tr>");
            out.println("<tr><td>&nbsp;</td><td>&nbsp;</td></tr>");
            out.println(
                    "<tr><td valign=top><b>Message:</b></td><td valign=top><textarea name='message' cols = '70' rows='8' id='message' ></textarea><br/><I><font color='grey'>Up to 256 KB of Unicode text</font></I></td></tr>");
            out.println("<tr><td>&nbsp;</td><td>&nbsp;</td></tr>");
            out.println(
                    "<tr><td>&nbsp;</td><td><input type='radio' name='msgType' value='same' checked='checked' onclick='changeMsgStructure(this.value)'/>Use same message body for all protocols</br/>");
            out.println(
                    "<input type='radio' name='msgType' value='json' onclick='changeMsgStructure(this.value)'/>Use different message body for different protocols</td></tr>");
            out.println("</table>");

            //out.println("<p><i><font color='grey'>For SMS notifications, it is best to leave the Subject field blank and place your text in the Message field to send a maximum of 140 characters. If the Subject field is not blank, the text in the Subject field will be used as content for the SMS messages.</font></i></p>");

            out.println("<hr/>");
            out.println(
                    "<input type='button' name='Cancel' value='Cancel' style='float:right;' onclick='window.close()'><input type='submit' name='Publish' value='Publish Message' style='float:right;'>");
            out.println("</form>");
        }
    }

    out.println("</body></html>");
    CMBControllerServlet.valueAccumulator.deleteAllCounters();
}

From source file:com.trsvax.tapestry.aws.services.impl.AWSAppenderImpl.java

License:Apache License

public void append(Layout layout, LoggingEvent event) {
    String arn = configuration.get(event.getLevel());

    if (arn != null) {
        String msg = String.format(format, event.getLevel(), event.getLoggerName());
        client.publish(new PublishRequest(arn, layout.format(event), msg));
    }/*from   w  w  w.  j av  a  2s  . c o m*/
}

From source file:net.smartcosmos.plugin.service.aws.notification.AwsNotificationService.java

License:Apache License

@Override
public void publish(INotificationEndpoint notificationEndpoint, String json) {
    Preconditions.checkArgument((notificationEndpoint != null), "Endpoint must not be null");

    Preconditions.checkArgument((notificationEndpoint.getTopicArn() != null),
            "Endpoint is missing a notification URL definition");

    Preconditions.checkArgument((!notificationEndpoint.isPendingConfirmation()),
            "Endpoint has not yet been confirmed");

    AmazonSNS sns = new AmazonSNSClient(credentials);
    Region usEast1 = Region.getRegion(Regions.US_EAST_1);
    sns.setRegion(usEast1);//from  w  w  w.ja  v a2s  .c o  m

    try {
        String subject = "SMART COSMOS Objects Event Notification";

        JSONObject jsonObject = null;
        try {
            jsonObject = new JSONObject(json);
            if (jsonObject.has(EVENT_TYPE)) {
                String eventType = jsonObject.getString(EVENT_TYPE);
                subject = "Objects Event: " + eventType;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        PublishRequest request = new PublishRequest(notificationEndpoint.getTopicArn(), json, subject);
        PublishResult result = sns.publish(request);

        //
        // Event
        //
        INotificationResultObject<IAccount> nro = new NotificationResultObject<>(EntityReferenceType.Account,
                notificationEndpoint.getAccount(), result.getMessageId());
        IEventService eventService = context.getServiceFactory()
                .getEventService(notificationEndpoint.getAccount());
        eventService.recordEvent(EventType.NotificationBroadcast, notificationEndpoint.getAccount(), null, nro);

    } finally {
        sns.shutdown();
    }
}

From source file:org.smap.notifications.interfaces.EmitNotifications.java

License:Open Source License

public void publish(int event, String msg, String subject) {

    //create a new SNS client
    AmazonSNS sns = AmazonSNSClient.builder().withRegion("ap-southeast-1")
            .withCredentials(new ClasspathPropertiesFileCredentialsProvider()).build();

    String topic = getTopic(event);

    if (topic != null) {
        PublishRequest publishRequest = new PublishRequest(topic, msg, subject);
        PublishResult publishResult = sns.publish(publishRequest);
        log.info("Publish: " + subject + " MessageId - " + publishResult.getMessageId());
    }//from  ww  w . jav a 2  s  .c  o m

}

From source file:org.springframework.cloud.aws.messaging.core.TopicMessageChannel.java

License:Apache License

@Override
protected boolean sendInternal(Message<?> message, long timeout) {
    PublishRequest publishRequest = new PublishRequest(this.topicArn, message.getPayload().toString(),
            findNotificationSubject(message));
    Map<String, MessageAttributeValue> messageAttributes = getMessageAttributes(message);
    if (!messageAttributes.isEmpty()) {
        publishRequest.withMessageAttributes(messageAttributes);
    }//w  w w. j av  a  2  s .co m
    this.amazonSns.publish(publishRequest);

    return true;
}