【发布时间】:2013-02-04 09:12:02
【问题描述】:
我使用Generate AppEngine BackEnd 在Eclipse 中生成了一个Google Endpoint AppEngine 项目,如this blog post 中所述。但是,该帖子 没有 描述了什么,官方的 Google 文档描述也很糟糕,我可以在本地访问该服务的 URL 是什么?
生成的服务有一个生成的端点,称为 DeviceInfoEndpoint。代码如下所示,以及 web.xml 中的代码。鉴于我在本地端口 8888 上托管,我应该使用哪个 URL 访问 listDeviceInfo()?我尝试了以下方法:
-
http://localhost:8888/_ah/api/deviceinfoendpoint/v1/listDeviceInfo=> 404 -
http://localhost:8888/_ah/spi/deviceinfoendpoint/v1/listDeviceInfo=> 405 GET 不支持 -
http://localhost:8888/_ah/spi/deviceinfoendpoint/v1/DeviceInfo=> 405 GET (...) -
http://localhost:8888/_ah/spi/v1/deviceinfoendpoint/listDeviceInfo= > 405 GET(...)
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>
【问题讨论】:
标签: google-app-engine google-cloud-endpoints