Calling the Firebase API is successful from Postman but Apache Camel-Spring Boot app returns an error.
API: https://fcm.googleapis.com/fcm/notification?notification_key_name=expectedvalue
Http Method: GET
Headers:
Authorization: expectedvalue
Content-Type: application/json
project_id: expectedvalue
Response Code: 400
Response Text: Bad Request
Response: {"error":"NOT_A_JSON_REQUEST"}
Calling from the Java app with below syntax:
.toD(https://fcm.googleapis.com/fcm/notification?notification_key_name=expectedvalue)
All required headers are set. Body is empty. HttpMethod also set as GET.
Update: --Added code--
public class MyRouteBuilder extends RouteBuilder{
@Override
public void configure() throws Exception {
from("direct:notifyroute")
.bean(FirebaseNM.class, "getNotificationKey")
.setHeader("CamelHttpMethod", constant("GET"))
.toD("https://fcm.googleapis.com/fcm/notification?notification_key_name=expectedvalue").log("${body}");
//.to("https://fcm.googleapis.com/fcm/notification?notification_key_name=expectedvalue").log("${body}"); //Same error is thrown when I use 'to'
}
}
public class FirebaseNM{
public void getNotificationKey(Exchange exchange){
exchange.getIn().removeHeaders("*"); //Code throws same error with or without this
exchange.removeProperties("*"); //Code throws same error with or without this
exchange.getIn().setBody(""); //Code throws same error with or without this
exchange.getIn().setHeader("Authorization", SERVER_KEY_VALUE);
exchange.getIn().setHeader("Content-Type", "application/json");
exchange.getIn().setHeader("project_id", PROJECT_ID_VALUE);
}
}
Alternate code that doesn't work:
rest().get("/nKey").route().removeHeaders("*")
.setHeader("Authorization", constant("server-key-value"))
.setHeader("Content-Type", constant("application/json"))
.setHeader("project_id", constant("project-id-value"))
.to("https://fcm.googleapis.com/fcm/notification?notification_key_name=key-name-value")
.endRest();
Update: --Question--
Is there a way to view error/exception details on Firebase console or to get detailed response from the API?
Update: --Question 2--
Firebase cloud messaging documentation does not mention the error(in the Enums columns) I'm receiving.
https://firebase.google.com/docs/reference/fcm/rest/v1/ErrorCode
Any other documentation I should look at?