2017-03-24 39 views
0

我正在測試我的GAE上的應用程序。我已添加:如何使用遠程API谷歌應用程序引擎API客戶端?

<servlet> 
    <display-name>Remote API Servlet</display-name> 
    <servlet-name>RemoteApiServlet</servlet-name> 
    <servlet-class>com.google.apphosting.utils.remoteapi.RemoteApiServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>RemoteApiServlet</servlet-name> 
    <url-pattern>/remote_api</url-pattern> 
</servlet-mapping> 

web.xml(服務器)。
現在,我該如何從本地在線檢索存儲在數據存儲區中的類型?
localhost - > servlet client local - > api - >數據存儲在線。數據存儲在線 - >本地。
您是否有客戶端servlet的示例,用於檢索存儲在數據存儲中的用戶(或列表,對象...)的列表?

回答

0

添加這些依賴條件:

​​

以後使用這樣的事情:

RemoteApiOptions options = new RemoteApiOptions() 
    .server("your_app_id.appspot.com", 443) 
    .useApplicationDefaultCredential(); 

RemoteApiInstaller installer = new RemoteApiInstaller(); 
installer.install(options); 
DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); 
Query q=new Query("User"); 
Iterator<Entity> c=ds.prepare(q).asQueryResultIterator(); 
while (c.hasNext()) 
{System.out.println(c.next());} 
installer.uninstall(); 

,並參考doc

+0

得到它,但我得到了一些錯誤,如:(上服務器)「這個請求沒有包含必要的頭文件」; (在客戶端)「302錯誤」,當我打電話給我的servlet來檢索你寫的信息或當我嘗試用python腳本(appcfg.py)獲取數據存儲種類時。 – ValeMarz

+0

你通過瀏覽器訪問它嗎?並且您是否在web.xml中添加了servlet? –

+0

當然。我在web.xml中添加了所有內容。從客戶端我使用「localhost:8888/test_remote_api」,其中'test_remote_api'是具有檢索信息的代碼的servlet。 – ValeMarz

相關問題