throw new ServletException(ex);
}
}
List<Subscription> subscriptions = new ArrayList<Subscription>();
ListSubscriptionsByTopicResult listSubscriptionsByTopicResult = null;
try {
listSubscriptionsByTopicResult = sns.listSubscriptionsByTopic(new ListSubscriptionsByTopicRequest(topicArn, nextToken));
subscriptions = listSubscriptionsByTopicResult.getSubscriptions();
} catch (Exception ex) {
logger.error("event=listAllSubscriptionsByTopic topic_arn=" + topicArn, ex);
throw new ServletException(ex);
}
ICNSTopicPersistence topicHandler = PersistenceFactory.getTopicPersistence();
CNSTopic topic = null;
try {
topic = topicHandler.getTopic(topicArn);
} catch (Exception ex) {
logger.error("event=getTopic topic_arn=" + topicArn, ex);
throw new ServletException(ex);
}
out.println("<html>");
out.println("<script type='text/javascript' language='javascript'>");
out.println("function changeEndpointHint(protocol){ ");
out.println(" if (protocol == 'HTTP' || protocol == 'HTTPS') { ");
out.println(" document.getElementById('endPoint').placeholder = 'e.g. http://company.com'; }");
out.println(" else if (protocol == 'EMAIL' || protocol == 'EMAIL_JSON') { ");
out.println(" document.getElementById('endPoint').placeholder = 'e.g. user@domain.com'; }");
out.println(" else if (protocol == 'CQS' || protocol == 'SQS') { ");
out.println(" document.getElementById('endPoint').placeholder = 'e.g. arn:aws:cqs:ccp:555555555555:my-queue'; } ");
out.println(" else if (protocol == 'redis') { document.getElementById('endPoint').placeholder = 'e.g. redis://server:port/channelname'; }");
out.println("}");
out.println("</script>");
header(request, out, "Subscriptions for Topic "+ ((topic != null) ? topic.getName():""));
out.println("<body>");
out.println("<h2>Subscriptions for Topic "+ ((topic != null) ? topic.getName():"") + "</h2>");
if (user != null) {
out.println("<table><tr><td><b>User Name:</b></td><td>"+ user.getUserName()+"</td></tr>");
out.println("<tr><td><b>User ID:</b></td><td>"+ user.getUserId()+"</td></tr>");
out.println("<tr><td><b>Access Key:</b></td><td>"+user.getAccessKey()+"</td></tr>");
out.println("<tr><td><b>Access Secret:</b></td><td>"+user.getAccessSecret()+"</td></tr>");
out.println("<tr><td><b>Topic Name:</b></td><td>"+ topic.getName()+"</td></tr>");
out.println("<tr><td><b>Topic Display Name:</b></td><td>" + topic.getDisplayName()+ "</td></tr>");
out.println("<tr><td><b>Topic Arn:</b></td><td>" + topic.getArn()+ "</td></tr>");
out.println("<tr><td><b>Num Subscriptions:</b></td><td>" + subscriptions.size()+ "</td></tr></table>");
}
out.println("<p><table><tr><td><b>Protocol</b></td><td><b>End Point</b></td><td> </td></tr>");
out.println("<form action=\"/webui/cnsuser/subscription/?userId="+userId+"&topicArn="+topicArn+"\" method=POST>");
out.println("<tr><td><select name='protocol' onchange='changeEndpointHint(this.value)'><option value='HTTP'>HTTP</option><option value='HTTPS'>HTTPS</option><option value='EMAIL'>EMAIL</option><option value='EMAIL_JSON'>EMAIL_JSON</option><option value='CQS'>CQS</option><option value='SQS'>SQS</option><option value='redis'>REDIS</option></select></td>");
out.println("<td><input type='text' name='endPoint' id = 'endPoint' size='65' placeholder='e.g. http://company.com'><input type='hidden' name='userId' value='"+ userId + "'></td><td><input type='submit' value='Subscribe' name='Subscribe' /></td></tr>");
out.println("</form></table>");
out.println("<p><hr width='100%' align='left' />");
out.println("<p><table class = 'alternatecolortable' border='1'>");
out.println("<tr><th>Row</th>");
out.println("<th>Arn</th>");
out.println("<th>Protocol</th>");
out.println("<th>End Point</th>");
out.println("<th>Subscription Attributes</th>");
out.println("<th>Raw Message Delivery</th>");
out.println("<th> </th></tr>");
for (int i = 0; subscriptions != null && i < subscriptions.size(); i++) {
Subscription s = subscriptions.get(i);
out.println("<tr>");
out.println("<form action=\"/webui/cnsuser/subscription/?userId="+user.getUserId()+"&arn="+s.getSubscriptionArn()+"&topicArn="+topicArn+"\" method=POST>");
out.println("<td>"+i+"</td>");
out.println("<td>"+s.getSubscriptionArn() +"<input type='hidden' name='arn' value="+s.getSubscriptionArn()+"></td>");
out.println("<td>"+s.getProtocol()+"</td>");
if(s.getProtocol().toLowerCase().equals("cqs")&&isAdmin(request)){
out.println("<td><a href='/webui/cqsuser?userId="+Util.getUserIdForQueueArn(s.getEndpoint())+"'>"+s.getEndpoint()+"</a></td>");
} else {
out.println("<td>"+s.getEndpoint()+"</td>");
}
if (s.getProtocol().toString().equals("http") && !s.getSubscriptionArn().equals("PendingConfirmation")) {
out.println("<td><a href='#' onclick=\"window.open('/webui/cnsuser/subscription/editdeliverypolicy?subscriptionArn="+ s.getSubscriptionArn() + "&userId=" + userId + "', 'EditDeliveryPolicy', 'height=630,width=580,toolbar=no')\">View/Edit Delivery Policy</a></td>");
} else {
out.println("<td> </td>");
}
if ((s.getProtocol().toString().equals("https") || s.getProtocol().toString().equals("http") || s.getProtocol().toString().equals("cqs") || s.getProtocol().toString().equals("sqs"))
&& !s.getSubscriptionArn().equals("PendingConfirmation")) {
String url = "/webui/cnsuser/subscription/rawmessagedeliverypolicy/?subscriptionArn="+ s.getSubscriptionArn() + "&userId=" + userId;
out.println("<td><a href='#' onclick=\"window.open('" + url + "', 'RawMessageDelivery', 'height=200,width=580,toolbar=no')\">Raw Message Delivery</a></td>");
} else {
out.println("<td> </td>");
}
if (s.getSubscriptionArn().equals("PendingConfirmation")) {
out.println("<td> </td>");
} else {
out.println("<td><input type='submit' value='Unsubscribe' name='Unsubscribe'/></td>");
}
out.println("</form></tr>");
}
out.println("</table></p>");
if (listSubscriptionsByTopicResult != null && listSubscriptionsByTopicResult.getNextToken() != null) {
out.println("<p><a href='/webui/cnsuser/subscription/?userId="+userId+"&topicArn="+topicArn+"&nextToken="+response.encodeURL(listSubscriptionsByTopicResult.getNextToken())+"'>next ></a></p>");
}
out.println("<h5 style='text-align:center;'><a href='/webui'>ADMIN HOME</a>");
out.println("<a href='/webui/cnsuser?userId="+userId+"&topicArn="+topicArn+"'>BACK TO TOPIC</a></h5>");