Nil*_*zor 5 google-app-engine google-cloud-endpoints
我已经使用此博客文章中Generate AppEngine BackEnd描述的方式在Eclipse中生成了Google Endpoint AppEngine项目.然而,该帖子没有描述的内容以及官方Google Docs描述得很差的是哪个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 GET(...)http://localhost:8888/_ah/spi/v1/deviceinfoendpoint/listDeviceInfo => 405 GET(...)DeviceInfoEndpoint.java的Exerpt:
@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;
}
}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
API请求路径通常应符合以下条件:
http(s)://{API_HOST}:{PORT}/_ah/api/{API_NAME}/{VERSION}/
Run Code Online (Sandbox Code Playgroud)
如果您对获取/更新/删除特定资源感兴趣,请在末尾添加ID.在您的示例中,这表明您应该查询:
http://localhost:8888/_ah/api/deviceinfoendpoint/v1/
Run Code Online (Sandbox Code Playgroud)
(映射到list您提出GET请求时).
通常,可用的API Explorer可以/_ah/_api/explorer轻松发现和查询这些URL.
| 归档时间: |
|
| 查看次数: |
3818 次 |
| 最近记录: |