0

I'm using Java to implement remoteAPi in Google App Engine (GAE) by following this tutorial: https://developers.google.com/appengine/docs/java/tools/remoteapi

but after configuring at web.xml, I use the following codes to insert new entity to local datastore:

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();
    }

but error has occured:

Problem accessing /remoteApi/index. Reason:

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

I viewed on debug and know that it caused by : "installer.install(options);" statement.

How can I solve this? Increase the socket time out ?

Thank in advance !

Chung
  • 947
  • 1
  • 12
  • 22

1 Answers1

0

i did it in both local and also deployed apps.following code may help you. remember the code must be write in RPC i used GWT 2.4,JRE 1.7 and GAE 1.7.2. put GAE Remote Api in 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;
}   
Divyesh Rupawala
  • 1,221
  • 8
  • 15