【问题标题】:Timeout while fetching for remoteApi GAE获取 remoteApi GAE 时超时
【发布时间】:2013-02-26 03:37:51
【问题描述】:

我正在按照本教程使用 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);”引起的声明。

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

提前致谢!

【问题讨论】:

    标签: google-app-engine remoteapi


    【解决方案1】:

    我在本地和部署的应用程序中都这样做了。以下代码可能会对您有所帮助。 记住代码必须用 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;
    }   
    

    【讨论】:

      猜你喜欢
      • 2011-05-06
      • 1970-01-01
      • 2012-10-30
      • 2013-11-15
      • 1970-01-01
      • 2018-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多