如何從谷歌應用引擎調用我的應用網址 (How to call my app url from google app engine)


問題描述

如何從谷歌應用引擎調用我的應用網址 (How to call my app url from google app engine)

我使用 java GWT 開發了我的應用程序,並將我的應用程序部署在 google 應用引擎上。我的訪問 url 是 sample.myappid.appspot.com 我想通過代碼調用這個 url,所以我這樣做了:‑

  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();
            }  

這不是調用我的 url。所以任何其他解決方案我如何使用代碼調用我的 url。

任何幫助?


參考解法

方法 1:

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.

(by Vijay ChouguleDan Cornilescu)

參考文件

  1. How to call my app url from google app engine (CC BY‑SA 2.5/3.0/4.0)

#java #gwt #google-app-engine






相關問題

電子郵件地址中帶有 + 字符的 Java 郵件 (Java mail with + character in email address)

如何快速原型化 Java 代碼? (How to quickly prototype Java code?)

如何使用 Maven 在目標(SVN-)服務器上創建 Javadoc? (How to create Javadoc on the target (SVN-) server using Maven?)

為什麼檢查二叉樹有效性的解決方案不起作用? (Why the solution for checking the validity of binary tree is not working?)

Selenium webdriver通過第一個數字找到texy (Selenium webdriver find texy by first digits)

setOnClickListener 沒有在圖像視圖上被調用 (setOnClickListener is not getting called on image view)

繪製多邊形:找不到錯誤 (Drawing Polygon : unable to find error)

半透明 JButton:對像出現在背景中 (Semi-Transparent JButton: Objects appear in Background)

比較同一數組的元素 (Compare elements of the same array)

Java 屏幕截圖小程序 (Java screen capture applet)

Minecraft 1.8.9 Forge Modding 的Java 開發工具包,需要什麼JDK/JRE,代碼是否正確? (Java Development Kit with Minecraft 1.8.9 Forge Modding, What JDK/JRE Is Needed, Is Code Correct?)

java while (resultset.next()) 不返回同一列中的所有數據 (java while (resultset.next()) does not return all data in the same column)







留言討論