How to call my app url from google app engine

2019-08-25 01:00发布

I developed my application using java GWT and I deployed my application on google app engine. my access url is sample.myappid.appspot.com I want to call this url through code so i did like this :-

  URL url;
            try {
                url = new URL("http://sample.myappid.appspot.com");

            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoOutput(true);
            connection.setRequestMethod("POST");


            if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
                // OK
                logger.log(Level.SEVERE,"Done okkkkkk");
            } else {
                // Server returned HTTP error code.
                logger.log(Level.SEVERE,"Erorrrrrrr");
            }

            } catch (Exception e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }  

This is not calling my url. so any other solution how can i call my url using code.

Any help?

1条回答
等我变得足够好
2楼-- · 2019-08-25 01:31

You need to pay attention if/when making requests to your app right from inside your apps' request handlers as you can cause infinite recursive loops, making GAE attempt to spawn a new app instance in an attempt to serve each such request. Possibly related to your other question: while user inactivity of 2mins getting info "This request caused a new process to be started for your application".

There are several methods to access your app programatically from itself, internally, basically making requests to paths in your app's serving namespace (like /index.html, for example):

Requests initiated by these internal methods are internally generated, independent of external requests, and can be safely used to implement your app's logic (loops are still possible if misused, but only creating a great deal of activity, they're not infinite recusions/deadlocking in the sense of forcing GAE to spawn a new instance for every request).

You can also use generic URL access from your app (applicable to any URL, not only those of your app), just as an external user would access your app. These can be useful for automated testing of your app, but note that they can be more costly than the internal access methods, I wouldn't recommend them for actually implementing your app's logic:

These external access methods are also subject to infinite recursion problem, so use them with care.

查看更多
登录 后发表回答