Google Cloud Endpoints SPI受限制

时间:2013-06-20 19:30:38

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

我使用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。

1 个答案:

答案 0 :(得分:2)

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

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,这仅表示该方法是否已设置auth。在您的情况下,对于此方法,它是true