我正在使用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);”言。
我该如何解决这个问题?增加套接字时间?
提前感谢!
答案 0 :(得分: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;
}