Firebase cloud messaging getting internal server error when calling “https://fcm.googleapis.com/fcm/send”












0















I wrote this code in spring boot(I am using Intellij IDE).In code androidFcmUrl= "https://fcm.googleapis.com/fcm/send". androidFcmKey=my server key. deviceToken=device id.



@RequestMapping(value = "/pushNotification", method = RequestMethod.GET)
public void pushNotification() {
try {

RestTemplate restTemplate = new RestTemplate();
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.set("Content-Type","application/json; UTF-8");
httpHeaders.set("Authorization", "key=" + androidFcmKey);

JSONObject msg = new JSONObject();
JSONObject json = new JSONObject();

msg.put("title", "Title");
msg.put("body", "Message");
msg.put("notificationType", "Test");

json.put("data", msg);
json.put("notification",msg);
json.put("to", deviceToken);

HttpEntity<String> httpEntity = new HttpEntity<>(json.toString(), httpHeaders);
String response = restTemplate.postForObject(androidFcmUrl, httpEntity, String.class);
System.out.println(response);

} catch (JSONException e) {
e.printStackTrace();
}

}


I am getting Status 500 internal server error.



2018-11-28 17:42:47.712 ERROR 15292 --- [nio-8088-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path threw exception [Request processing failed; nested exception is org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://fcm.googleapis.com/fcm/send": Connection timed out: connect; nested exception is java.net.ConnectException: Connection timed out: connect] with root cause.



But when I am hitting the api form postman with same payload I am getting a success response with message id.










share|improve this question

























  • Your application cannot reach that URL. If it's available from the same machine with other software, disable your firewall or check why your application server cannot reach the internet.

    – f1sh
    Nov 28 '18 at 12:35
















0















I wrote this code in spring boot(I am using Intellij IDE).In code androidFcmUrl= "https://fcm.googleapis.com/fcm/send". androidFcmKey=my server key. deviceToken=device id.



@RequestMapping(value = "/pushNotification", method = RequestMethod.GET)
public void pushNotification() {
try {

RestTemplate restTemplate = new RestTemplate();
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.set("Content-Type","application/json; UTF-8");
httpHeaders.set("Authorization", "key=" + androidFcmKey);

JSONObject msg = new JSONObject();
JSONObject json = new JSONObject();

msg.put("title", "Title");
msg.put("body", "Message");
msg.put("notificationType", "Test");

json.put("data", msg);
json.put("notification",msg);
json.put("to", deviceToken);

HttpEntity<String> httpEntity = new HttpEntity<>(json.toString(), httpHeaders);
String response = restTemplate.postForObject(androidFcmUrl, httpEntity, String.class);
System.out.println(response);

} catch (JSONException e) {
e.printStackTrace();
}

}


I am getting Status 500 internal server error.



2018-11-28 17:42:47.712 ERROR 15292 --- [nio-8088-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path threw exception [Request processing failed; nested exception is org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://fcm.googleapis.com/fcm/send": Connection timed out: connect; nested exception is java.net.ConnectException: Connection timed out: connect] with root cause.



But when I am hitting the api form postman with same payload I am getting a success response with message id.










share|improve this question

























  • Your application cannot reach that URL. If it's available from the same machine with other software, disable your firewall or check why your application server cannot reach the internet.

    – f1sh
    Nov 28 '18 at 12:35














0












0








0








I wrote this code in spring boot(I am using Intellij IDE).In code androidFcmUrl= "https://fcm.googleapis.com/fcm/send". androidFcmKey=my server key. deviceToken=device id.



@RequestMapping(value = "/pushNotification", method = RequestMethod.GET)
public void pushNotification() {
try {

RestTemplate restTemplate = new RestTemplate();
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.set("Content-Type","application/json; UTF-8");
httpHeaders.set("Authorization", "key=" + androidFcmKey);

JSONObject msg = new JSONObject();
JSONObject json = new JSONObject();

msg.put("title", "Title");
msg.put("body", "Message");
msg.put("notificationType", "Test");

json.put("data", msg);
json.put("notification",msg);
json.put("to", deviceToken);

HttpEntity<String> httpEntity = new HttpEntity<>(json.toString(), httpHeaders);
String response = restTemplate.postForObject(androidFcmUrl, httpEntity, String.class);
System.out.println(response);

} catch (JSONException e) {
e.printStackTrace();
}

}


I am getting Status 500 internal server error.



2018-11-28 17:42:47.712 ERROR 15292 --- [nio-8088-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path threw exception [Request processing failed; nested exception is org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://fcm.googleapis.com/fcm/send": Connection timed out: connect; nested exception is java.net.ConnectException: Connection timed out: connect] with root cause.



But when I am hitting the api form postman with same payload I am getting a success response with message id.










share|improve this question
















I wrote this code in spring boot(I am using Intellij IDE).In code androidFcmUrl= "https://fcm.googleapis.com/fcm/send". androidFcmKey=my server key. deviceToken=device id.



@RequestMapping(value = "/pushNotification", method = RequestMethod.GET)
public void pushNotification() {
try {

RestTemplate restTemplate = new RestTemplate();
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.set("Content-Type","application/json; UTF-8");
httpHeaders.set("Authorization", "key=" + androidFcmKey);

JSONObject msg = new JSONObject();
JSONObject json = new JSONObject();

msg.put("title", "Title");
msg.put("body", "Message");
msg.put("notificationType", "Test");

json.put("data", msg);
json.put("notification",msg);
json.put("to", deviceToken);

HttpEntity<String> httpEntity = new HttpEntity<>(json.toString(), httpHeaders);
String response = restTemplate.postForObject(androidFcmUrl, httpEntity, String.class);
System.out.println(response);

} catch (JSONException e) {
e.printStackTrace();
}

}


I am getting Status 500 internal server error.



2018-11-28 17:42:47.712 ERROR 15292 --- [nio-8088-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path threw exception [Request processing failed; nested exception is org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://fcm.googleapis.com/fcm/send": Connection timed out: connect; nested exception is java.net.ConnectException: Connection timed out: connect] with root cause.



But when I am hitting the api form postman with same payload I am getting a success response with message id.







java android firebase firebase-cloud-messaging






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 28 '18 at 13:52









Doug Stevenson

81.7k997115




81.7k997115










asked Nov 28 '18 at 12:19









mayank goyalmayank goyal

62




62













  • Your application cannot reach that URL. If it's available from the same machine with other software, disable your firewall or check why your application server cannot reach the internet.

    – f1sh
    Nov 28 '18 at 12:35



















  • Your application cannot reach that URL. If it's available from the same machine with other software, disable your firewall or check why your application server cannot reach the internet.

    – f1sh
    Nov 28 '18 at 12:35

















Your application cannot reach that URL. If it's available from the same machine with other software, disable your firewall or check why your application server cannot reach the internet.

– f1sh
Nov 28 '18 at 12:35





Your application cannot reach that URL. If it's available from the same machine with other software, disable your firewall or check why your application server cannot reach the internet.

– f1sh
Nov 28 '18 at 12:35












2 Answers
2






active

oldest

votes


















0














The androidFcmUrl you are trying to call is might not reachable. Ensure the path is correct and is listening. Also ensure if there is any proxy interrupting your URL.






share|improve this answer


























  • But when I am hitting the api form postman with same payload I am getting a success response with message id. So I think the api call is reachable. Also if my firewall was blocking that url I would not have been able to hit it from postman. Am I wrong somewhere?. "also ensure if there is any proxy interrupting your URL".. how can I do that?

    – mayank goyal
    Nov 29 '18 at 4:41



















0














some time IDE having diff conf setting then tool which you are using like postman. Its looks like issue of environment only. You can try to run app via OS console instead of IDE and you will see difference.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53519335%2ffirebase-cloud-messaging-getting-internal-server-error-when-calling-https-fcm%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The androidFcmUrl you are trying to call is might not reachable. Ensure the path is correct and is listening. Also ensure if there is any proxy interrupting your URL.






    share|improve this answer


























    • But when I am hitting the api form postman with same payload I am getting a success response with message id. So I think the api call is reachable. Also if my firewall was blocking that url I would not have been able to hit it from postman. Am I wrong somewhere?. "also ensure if there is any proxy interrupting your URL".. how can I do that?

      – mayank goyal
      Nov 29 '18 at 4:41
















    0














    The androidFcmUrl you are trying to call is might not reachable. Ensure the path is correct and is listening. Also ensure if there is any proxy interrupting your URL.






    share|improve this answer


























    • But when I am hitting the api form postman with same payload I am getting a success response with message id. So I think the api call is reachable. Also if my firewall was blocking that url I would not have been able to hit it from postman. Am I wrong somewhere?. "also ensure if there is any proxy interrupting your URL".. how can I do that?

      – mayank goyal
      Nov 29 '18 at 4:41














    0












    0








    0







    The androidFcmUrl you are trying to call is might not reachable. Ensure the path is correct and is listening. Also ensure if there is any proxy interrupting your URL.






    share|improve this answer















    The androidFcmUrl you are trying to call is might not reachable. Ensure the path is correct and is listening. Also ensure if there is any proxy interrupting your URL.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 28 '18 at 13:08









    LuckyLikey

    1,4231433




    1,4231433










    answered Nov 28 '18 at 12:31









    Umashankar AdhaUmashankar Adha

    1




    1













    • But when I am hitting the api form postman with same payload I am getting a success response with message id. So I think the api call is reachable. Also if my firewall was blocking that url I would not have been able to hit it from postman. Am I wrong somewhere?. "also ensure if there is any proxy interrupting your URL".. how can I do that?

      – mayank goyal
      Nov 29 '18 at 4:41



















    • But when I am hitting the api form postman with same payload I am getting a success response with message id. So I think the api call is reachable. Also if my firewall was blocking that url I would not have been able to hit it from postman. Am I wrong somewhere?. "also ensure if there is any proxy interrupting your URL".. how can I do that?

      – mayank goyal
      Nov 29 '18 at 4:41

















    But when I am hitting the api form postman with same payload I am getting a success response with message id. So I think the api call is reachable. Also if my firewall was blocking that url I would not have been able to hit it from postman. Am I wrong somewhere?. "also ensure if there is any proxy interrupting your URL".. how can I do that?

    – mayank goyal
    Nov 29 '18 at 4:41





    But when I am hitting the api form postman with same payload I am getting a success response with message id. So I think the api call is reachable. Also if my firewall was blocking that url I would not have been able to hit it from postman. Am I wrong somewhere?. "also ensure if there is any proxy interrupting your URL".. how can I do that?

    – mayank goyal
    Nov 29 '18 at 4:41













    0














    some time IDE having diff conf setting then tool which you are using like postman. Its looks like issue of environment only. You can try to run app via OS console instead of IDE and you will see difference.






    share|improve this answer




























      0














      some time IDE having diff conf setting then tool which you are using like postman. Its looks like issue of environment only. You can try to run app via OS console instead of IDE and you will see difference.






      share|improve this answer


























        0












        0








        0







        some time IDE having diff conf setting then tool which you are using like postman. Its looks like issue of environment only. You can try to run app via OS console instead of IDE and you will see difference.






        share|improve this answer













        some time IDE having diff conf setting then tool which you are using like postman. Its looks like issue of environment only. You can try to run app via OS console instead of IDE and you will see difference.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 29 '18 at 6:30









        Umashankar AdhaUmashankar Adha

        1




        1






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53519335%2ffirebase-cloud-messaging-getting-internal-server-error-when-calling-https-fcm%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Contact image not getting when fetch all contact list from iPhone by CNContact

            count number of partitions of a set with n elements into k subsets

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks