I'm trying to create a Java Application which should send a Protocol to the Firebase Cloud Messaging Servers. Now I have the problem, that I don't know how to see if my message was sent correctly. When I head to the Web-Console of Firebase/Notifications there is no message to see.
My Code (just in case):
import org.apache.http.HttpResponse;
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.HttpClientBuilder;
import org.json.JSONObject;
public class Mainclass {
public static void main(String[] args) {
// Declaration of Message Parameters
String message_url = new String("https://fcm.googleapis.com/fcm/send");
String message_sender_id = new String("XXXX-XXXX");
String message_key = new String("key=XXXX-XXXX");
// Generating a JSONObject for the content of the message
JSONObject message = new JSONObject();
message.put("message", "TEXT");
JSONObject protocol = new JSONObject();
protocol.put("to", message_sender_id);
protocol.put("data", message);
// Send Protocol
try {
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost request = new HttpPost(message_url);
request.addHeader("content-type", "application/json");
request.addHeader("Authorization", message_key);
StringEntity params = new StringEntity(protocol.toString());
request.setEntity(params);
System.out.println(params);
HttpResponse response = httpClient.execute(request);
System.out.println(response.toString());
} catch (Exception e) {
}
}
}
Output:
[Content-Type: text/plain; charset=ISO-8859-1,Content-Length: 59,Chunked: false]
HttpResponseProxy{HTTP/1.1 200 OK [Content-Type: application/json; charset=UTF-8, Date: Mon, 26 Dec 2016 12:09:13 GMT, Expires: Mon, 26 Dec 2016 12:09:13 GMT, Cache-Control: private, max-age=0, X-Content-Type-Options: nosniff, X-Frame-Options: SAMEORIGIN, X-XSS-Protection: 1; mode=block, Server: GSE, Alt-Svc: quic=":443"; ma=2592000; v="35,34", Transfer-Encoding: chunked] org.apache.http.client.entity.DecompressingEntity@32cf48b7}
Thank you!
PS There is a reference of FCM https://firebase.google.com/docs/cloud-messaging/server