2013-03-11 76 views
0

我使用Java按照本教程來實現remoteAPi在谷歌的App Engine(GAE): https://developers.google.com/appengine/docs/java/tools/remoteapi超時而獲取的remoteApi GAE

但在配置在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 /指數。原因:

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

我認爲在調試並知道它造成的: 「installer.install(選項);」聲明。

我該如何解決這個問題?增加套接字超時?

提前致謝!

回答

0

我在本地和部署的應用程序中都做了它。以下代碼可能對您有所幫助。 記得代碼必須寫在RPC 我使用了GWT 2.4,JRE 1.7和GAE 1.7.2。 把GAE遠程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; 
}