我在 Eclipse 中使用此博客文章Generate AppEngine BackEnd
中描述的方法生成了一个 Google Endpoint AppEngine 项目。然而,那篇文章没有描述什么,官方的谷歌文档描述也很糟糕,我可以在本地访问该服务的 URL 是什么?
生成的服务有一个生成的端点,称为 DeviceInfoEndpoint。代码如下所示,以及 web.xml 中的代码。鉴于我在本地端口 8888 上托管,我应该使用哪个 URL 访问 listDeviceInfo()?我尝试了以下方法:
http://localhost:8888/_ah/api/deviceinfoendpoint/v1/listDeviceInfo
=> 404http://localhost:8888/_ah/spi/deviceinfoendpoint/v1/listDeviceInfo
=> 405 GET 不支持http://localhost:8888/_ah/spi/deviceinfoendpoint/v1/DeviceInfo
=> 405 获取 (...)http://localhost:8888/_ah/spi/v1/deviceinfoendpoint/listDeviceInfo
= > 405 获取(...)
DeviceInfoEndpoint.java 的摘录:
@Api(name = "deviceinfoendpoint")
public class DeviceInfoEndpoint {
/**
* This method lists all the entities inserted in datastore.
* It uses HTTP GET method.
*
* @return List of all entities persisted.
*/
@SuppressWarnings({ "cast", "unchecked" })
public List<DeviceInfo> listDeviceInfo() {
EntityManager mgr = getEntityManager();
List<DeviceInfo> result = new ArrayList<DeviceInfo>();
try {
Query query = mgr
.createQuery("select from DeviceInfo as DeviceInfo");
for (Object obj : (List<Object>) query.getResultList()) {
result.add(((DeviceInfo) obj));
}
} finally {
mgr.close();
}
return result;
}
}
Web.xml:
<?xml version="1.0" encoding="utf-8" standalone="no"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>SystemServiceServlet</servlet-name>
<servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value>com.example.dummyandroidapp.DeviceInfoEndpoint</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SystemServiceServlet</servlet-name>
<url-pattern>/_ah/spi/*</url-pattern>
</servlet-mapping>
</web-app>