-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostBrmsStatus.java
More file actions
118 lines (95 loc) · 4.47 KB
/
Copy pathPostBrmsStatus.java
File metadata and controls
118 lines (95 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package com.app;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import com.app.PostIOSNotification;
/**
* Servlet implementation class PostBrmsStatus
*/
@WebServlet("/PostBrmsStatus")
public class PostBrmsStatus extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public PostBrmsStatus() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//response.getWriter().append("Served at: ").append(request.getContextPath());
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
// PrintWriter out = response.getWriter();
response.setContentType("application/json");
String downDomains = request.getParameter("down_domains");
String downDomainsLifecycle = request.getParameter("lc");
String postdata = null;
PostIOSNotification postIOSNotification = new PostIOSNotification();
if (downDomainsLifecycle.equalsIgnoreCase("prod")) {
postdata = "{" + "\"notification\": {" + "\"title\": \"Testing Ignore:: Cisco iBPM Notification\",\"body\" : \"Domain(s):"
+ downDomains + "are down\"," + "\"icon\" : \"ic_add_alert_black_24dp.png\"," + "}," + "\"data\": {"
+ "\"url\": \"https://ibpm.cisco.com/prd2/brmsadmin/status\","
+ "\"domainUrl\": \"https://ibpm.cisco.com/ea/brmsadmin\"," + "}," + "\"to\":\"/topics/myTopic\""
+ "}";
//postIOSNotification.sendNotification("mon",downDomainsLifecycle,downDomains,null);
} else {
postdata = "{" + "\"notification\": {" + "\"title\": \"" + downDomainsLifecycle.toUpperCase()
+ ": Testing Ignore::Cisco iBPM Notification\"," + "\"body\" : \"Domain(s):" + downDomains + "are down\","
+ "\"icon\" : \"ic_add_alert_black_24dp.png\"," + "}," + "\"data\": {"
+ "\"url\": \"https://ibpm.cisco.com/prd2/brmsadmin/status\","
+ "\"domainUrl\": \"https://ibpm.cisco.com/ea/brmsadmin\"," + "}," + "\"to\":\"/topics/myTopic\""
+ "}";
//postIOSNotification.sendNotification("mon",downDomainsLifecycle,downDomains,null);
}
String postUrl = "https://gcm-http.googleapis.com/gcm/send";
//System.out.println(" POST DATA ::" + postdata);
postJson(postdata,postUrl);
}
private void postJson(String jsonData, String postUrl) throws ClientProtocolException, IOException {
// TODO Auto-generated method stub
final String USER_AGENT = "Mozilla/5.0";
@SuppressWarnings({ "deprecation", "resource" })
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(postUrl);
// add header
post.setHeader("User-Agent", USER_AGENT);
post.setHeader("Content-Type", "application/json");
post.setHeader("Accept", "application/json");
post.setHeader("Authorization", "key=AIzaSyBTXdvWyrcRfyTS7sfZ100Wp7IfLkSMaxY");
StringEntity se = new StringEntity(jsonData);
post.setEntity(se);
HttpResponse response = client.execute(post);
System.out.println("\n Sending 'POST' request to URL : " + postUrl);
System.out.println("Post parameters : " + post.getEntity());
System.out.println("Response Code : " + response.getStatusLine().getStatusCode());
InputStreamReader isr = new InputStreamReader(response.getEntity().getContent());
int numCharsRead;
char[] charArray = new char[1024];
StringBuffer sb = new StringBuffer();
while ((numCharsRead = isr.read(charArray)) > 0) {
sb.append(charArray, 0, numCharsRead);
}
System.out.println("**RESPONSE AFTER SENDING ANDROID NOTIFICATION:"+sb.toString());
}
}