我正在研究Google Cloud Endpoints,我对配置有些怀疑。 我已经使用了appengine,但是端点对我来说有点混乱。
我做了这个例子:
https://cloud.google.com/endpoints/docs/frameworks/java/get-started-frameworks-java
我为测试其他可能性做了一些更改:
应用服务引擎-web.xml中
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<runtime>java8</runtime>
<threadsafe>true</threadsafe>
<module>endpointsmodule</module>
<basic-scaling>
<max-instances>1</max-instances>
</basic-scaling>
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
</system-properties>
<!-- [START env_variables] -->
<env-variables>
<env-var name="ENDPOINTS_SERVICE_NAME" value="${endpoints.service.prefix}.endpoints.${endpoints.project.id}.appspot.com" />
<env-var name="ENDPOINTS_SERVICE_VERSION" value="1.0.0" />
</env-variables>
<!-- [END env_variables] -->
</appengine-web-app>
的web.xml
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<!-- Wrap the backend with Endpoints Frameworks v2. -->
<servlet>
<servlet-name>EndpointsServlet</servlet-name>
<servlet-class>com.google.api.server.spi.EndpointsServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value>com.example.echo.Echo,com.example.echo.Echo2</param-value>
</init-param>
</servlet>
<!-- Route API method requests to the backend. -->
<servlet-mapping>
<servlet-name>EndpointsServlet</servlet-name>
<url-pattern>/endpointsmodule/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<!-- Add a filter that fetches the service config from service management. -->
<filter>
<filter-name>endpoints-api-configuration</filter-name>
<filter-class>com.google.api.control.ServiceManagementConfigFilter</filter-class>
</filter>
<!-- Add a filter that performs Endpoints logging and monitoring. -->
<!-- [START api_management] -->
<filter>
<filter-name>endpoints-api-controller</filter-name>
<filter-class>com.google.api.control.extensions.appengine.GoogleAppEngineControlFilter</filter-class>
<init-param>
<param-name>endpoints.projectId</param-name>
<param-value>${endpoints.project.id}</param-value>
</init-param>
<init-param>
<param-name>endpoints.serviceName</param-name>
<param-value>${endpoints.service.prefix}.endpoints.${endpoints.project.id}.appspot.com</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>endpoints-api-configuration</filter-name>
<servlet-name>EndpointsServlet</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>endpoints-api-controller</filter-name>
<servlet-name>EndpointsServlet</servlet-name>
</filter-mapping>
<!-- [END api_management] -->
</web-app>
的pom.xml
<endpoints.project.id>myprojectid</endpoints.project.id>
<endpoints.service.prefix>mymodule</endpoints.service.prefix>
openapi.json
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "xxx"
},
"host": "myprojectid.appspot.com",
"basePath": "/endpointsmodule",
"schemes": [
"https"
],
怀疑是:
什么是service_name的目的?我确实部署了openapi.json和appengine模块,但在我的Google控制台中仍然以“服务名称”显示我的项目名称。
此配置:ENDPOINTS_CONFIG_ID,我在Google控制台的任何位置都看不到。
我希望我的端点在“enpoints-module”(appengine)中接收requets,它是appengine,而不是默认模块。
所有对端点的请求都是通过_ah / api发生的?
我正在尝试为此路径发出请求: https://myprojectid.appspot.com/endpointsmodule/echo/v1/echo
ENDPOINTS_CONFIG_ID和ENDPOINTS_SERVICE_VERSION的正确值是什么?
appengine开始时的异常:
repackaged.com.google.api.config.ServiceConfigException: Failed to fetch default config version for service 'myserviceprefix.endpoints.myprojectid.appspot.com'. No versions exist!
答案 0 :(得分:0)
端点服务名称是OpenAPI规范中设置的主机字段。这必须匹配环境变量ENDPOINTS_SERVICE_NAME
和endpoints.serviceName
过滤器参数。