【问题标题】:Google Cloud Endpoints SPI restrictedGoogle Cloud Endpoints SPI 受限
【发布时间】:2013-06-20 19:30:37
【问题描述】:

我使用 Google Cloud Endpoints 定义了一个简单的 API:

@Api(name = "realestate", version = "v1")
public class RealEstatePropertyV1 {

    @ApiMethod(name = "properties", httpMethod = "GET")
    public List<RealEstateProperty> list() {
        return ofy().load().type(RealEstateProperty.class).list();
    }
}

我也配置了web.xml:

 <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.realestate.api.v1.RealEstatePropertyV1</param-value>
  </init-param>
 </servlet>
 <servlet-mapping>
  <servlet-name>SystemServiceServlet</servlet-name>
  <url-pattern>/_ah/spi/*</url-pattern>
 </servlet-mapping>
</web-app>

我在 Eclipse 中启动 API 并执行 curl http://localhost:8888/_ah/spi/realestate/v1/properties。回应是

<html><head><title>Error 405 HTTP method GET is not supported by this URL</title></head>
<body><h2>Error 405 HTTP method GET is not supported by this URL</h2></body>
</html>

服务器日志是:

Jun 20, 2013 9:22:14 PM com.google.appengine.tools.development.DevAppServerImpl start
INFO: Dev App Server is now running
Jun 20, 2013 9:22:29 PM com.google.api.server.spi.SystemServiceServlet init
INFO: SPI restricted: true

你知道SPI restricted 是什么意思吗?我想提一下,我没有在 Google API 控制台中注册任何内容。我的目标是首先在本地测试 API。

【问题讨论】:

    标签: java google-app-engine google-cloud-endpoints


    【解决方案1】:

    要测试您的应用程序,请尝试

    curl -X POST -d "{}" \
    > -H "Content-Type: application/json" \
    > http://localhost:8888/_ah/spi/realestate/v1/properties
    

    更好的是,使用 API 资源管理器测试您的应用程序

    http://localhost:8888/_ah/api/explorer
    

    至于您日志中的SPI restricted,这只是表明该方法是否设置了身份验证。在您的情况下,对于这种方法,它是true。

    【讨论】:

    • 使用您的curl 命令,我得到以下信息:{"error_message":"missing /{Service}.{method}"}。我没有在 App Engine 上部署 API,可能是这个原因。
    • 这与localhost:8888 无关。 {Service} 是什么?
    • 由于我没有为@ApiMethod 指定path 属性,所以正确的URL 是http://localhost:8888/_ah/api/realestate/v1/realestateproperty。我从 API 资源管理器中得到它。起初它不起作用,因为我使用的是objectify,它似乎不适用于端点。
    • 欢迎发布您在使用 Endpoints 时遇到的问题。我们很乐意提供帮助。
    • 在我的一个实体中,我有一个字段@Parent Ref&lt;Owner&gt;,似乎没有处理Ref,因为如果我有这个字段,我就无法生成客户端库并且没有任何工作。我用Objectify 4
    猜你喜欢
    • 1970-01-01
    • 2018-12-18
    • 2017-08-13
    • 2013-05-23
    • 1970-01-01
    • 2014-09-12
    • 2013-05-26
    • 2017-01-07
    • 1970-01-01
    相关资源
    最近更新 更多