0

我按照本教程使用 Java 在 Google App Engine (GAE) 中实现 remoteAPi: https ://developers.google.com/appengine/docs/java/tools/remoteapi

但在 web.xml 配置后,我使用以下代码将新实体插入到本地数据存储区:

String username = "myusername";  
    String password = "mypassword";

    RemoteApiOptions options = new RemoteApiOptions()
        .server("localhost", 8888)  
        .credentials(username, password);
    RemoteApiInstaller installer = new RemoteApiInstaller();
    installer.install(options);

    try {
        DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
        System.out.println("Key of new entity is " + 
            ds.put(new Entity("Hello Remote API!")));
    } finally {
        installer.uninstall();
    }

但发生了错误:

访问 /remoteApi/index 时出现问题。原因:

Timeout while fetching: http://localhost:8888/remote_api

我在调试时查看并知道它是由以下原因引起的:“installer.install(options);” 陈述。

我该如何解决这个问题?增加套接字超时?

预先感谢 !

4

1 回答 1

0

我在本地和部署的应用程序中都这样做了。以下代码可能会对您有所帮助。记住代码必须用 RPC 编写, 我使用 GWT 2.4、JRE 1.7 和 GAE 1.7.2。将GAE Remote Api 放入 WEB-INF/lib

web.xml

<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>

XyzServiceImpl.java

 @Override
public String callGaeRemote() {
    RemoteApiInstaller installer = null;
    List<Entity> allEntities = null;
    String response = null;

    try {


        RemoteApiOptions options = new RemoteApiOptions().server(
                "localhost", 8888).credentials(
                "username", "password");

        installer = new RemoteApiInstaller();
        installer.install(options);

         DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
            System.out.println("Key of new entity is " + 
                ds.put(new Entity("Hello Remote API!")));
        response = "Success";           
    } catch (IOException e) {
        e.printStackTrace();
    }
    finally {
        installer.uninstall();
    }
    return response;
}   
于 2013-03-21T06:09:57.337 回答