访问Hello-World Google云端点服务的URL是什么? [英] What is the URL to access a Hello-World Google Cloud Endpoint service?

查看:163
本文介绍了访问Hello-World Google云端点服务的URL是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Eclipse中使用 Generate AppEngine BackEnd 生成了一个Google Endpoint AppEngine项目,如此博文。然而,那篇文章并未描述 ,官方的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 {

/ **
*此方法列出所有插入数据存储中的实体。
*它使用HTTP GET方法。
*
* @return所有实体列表持续存在。
* /
@SuppressWarnings({cast,unchecked})
public List< DeviceInfo> listDeviceInfo(){
EntityManager mgr = getEntityManager();
列表< DeviceInfo> result = new ArrayList< DeviceInfo>();
try {
Query query = mgr
.createQuery(从DeviceInfo中选择DeviceInfo); ()()(){
for(Object obj:(List< Object>)query.getResultList()){
result.add(((DeviceInfo)obj));
}
} finally {
mgr.close();
}
返回结果;
}
}

Web.xml:

 <?xml version =1.0encoding =utf-8standalone =no?>< web-app xmlns =http ://java.sun.com/xml/ns/javaeexmlns:web =http://java.sun.com/xml/ns/javaee/web-app_2_5.xsdxmlns:xsi =http:/ /www.w3.org/2001/XMLSchema-instanceversion =2.5xsi:schemaLocation =http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ NS / JavaEE的/网络app_2_5.xsd> 

< servlet>
< servlet-name> SystemServiceServlet< / servlet-name>
< servlet-class> com.google.api.server.spi.SystemServiceServlet< / servlet-class>
< init-param>
< param-name>服务< / 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>


解决方案

API请求路径通常应符合以下要求:

  http(s):// {API_HOST}:{PORT} / _ah / api / {API_NAME} / {VERSION} / 

如果您有兴趣获取/更新/删除特定资源,请将ID添加到末尾。在你的例子中,这表明你应该查询:

pre $ http $ localhost 8888 / /

(当您映射到 list 'code> GET 请求)。

通常,APIs Explorer位于 / _ah / _api / explorer 可以很容易地发现和查询这些网址。


I've generated a Google Endpoint AppEngine project in Eclipse by using the Generate AppEngine BackEnd as described in this blog post. What that post does not describe however, and which the official Google Docs describe poorly as well, is which URL I can access that service with locally?

The service generated has one generated endpoint called DeviceInfoEndpoint. The code is shown below as well as the code in web.xml. Which URL should I access listDeviceInfo() with given that I'm hosting on port 8888 locally? I've tried the following:

  • http://localhost:8888/_ah/api/deviceinfoendpoint/v1/listDeviceInfo => 404
  • http://localhost:8888/_ah/spi/deviceinfoendpoint/v1/listDeviceInfo => 405 GET not supported
  • http://localhost:8888/_ah/spi/deviceinfoendpoint/v1/DeviceInfo => 405 GET (...)
  • http://localhost:8888/_ah/spi/v1/deviceinfoendpoint/listDeviceInfo = > 405 GET(...)

Exerpt of 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>

解决方案

API request paths should generally conform to the following:

http(s)://{API_HOST}:{PORT}/_ah/api/{API_NAME}/{VERSION}/

If you're interested in fetching/updating/deleting a specific resource, add an ID to the end. In your example, that suggests you should be querying:

http://localhost:8888/_ah/api/deviceinfoendpoint/v1/

(which maps to list when you're making a GET request).

In general, the APIs Explorer available at /_ah/_api/explorer makes it easy to discover and query these URLs.

这篇关于访问Hello-World Google云端点服务的URL是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆