2017-03-24 41 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

相关问题