我使用Java在Google中实现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();
}但出现了错误:
访问/远程应用程序/索引时出现问题。原因:
Timeout while fetching: http://localhost:8888/remote_api我查看了调试,并知道它是由“installer.install(选项);”语句引起的。
我怎么才能解决这个问题?增加套接字超时时间?
提前感谢!
发布于 2013-03-21 06:09:57
我在本地和部署的apps.following代码中都这样做可能会对您有所帮助。请记住,代码必须用使用GWT2.4、JRE1.7和GAE1.7.2的编写。将GAE远程应用程序放入WEB/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;
} https://stackoverflow.com/questions/15330483
复制相似问题