Google Cloud Endpoints - 无法加载服务

问题描述 投票:0回答:1

一些非常奇怪的事情刚刚开始发生。 我们在 Google Cloud Endpoints 上的 API 无法启动。 在尝试部署到新的测试环境后就发生了这种情况。 现在我们也无法部署到旧的测试环境。

我们一如既往地部署 API:

gcloud endpoints services deploy openapi.json

请注意,我们在 openapi 中将“host”更改为新的测试 URL。

openapi.json

{
    "swagger": "2.0",
        "info": {
        "version": "1.2.0",
        "title": "Our App API"
    },
    "host": "test2-ourappapi.appspot.com",
    "basePath": "/_ah/api",
    "schemes": [
        "https"
    ],
    "consumes": [
        "application/json"
    ],
    "produces": [
        "application/json"
    ],
    "paths": {
       ...
    }
}

现在部署到 GAE 后,这会出现在日志中。

GAE日志

Failed to load service
endpoints.repackaged.com.google.api.config.ServiceConfigException: Failed to parse the HTTP response as service configuration
    at endpoints.repackaged.com.google.api.config.ServiceConfigSupplier.parseHttpResponse(ServiceConfigSupplier.java:197)
    at endpoints.repackaged.com.google.api.config.ServiceConfigSupplier.fetch(ServiceConfigSupplier.java:170)
    at endpoints.repackaged.com.google.api.config.ServiceConfigSupplier.get(ServiceConfigSupplier.java:131)
    at endpoints.repackaged.com.google.api.config.ServiceConfigSupplier.get(ServiceConfigSupplier.java:50)
    at endpoints.repackaged.com.google.common.base.Suppliers$ExpiringMemoizingSupplier.get(Suppliers.java:241)
    at endpoints.repackaged.com.google.api.config.ServiceConfigFetcher.fetch(ServiceConfigFetcher.java:41)
    at com.google.api.control.ServiceManagementConfigFilter$1.load(ServiceManagementConfigFilter.java:33)
    at com.google.api.control.ConfigFilter.init(ConfigFilter.java:90)
    at org.eclipse.jetty.servlet.FilterHolder.initialize(FilterHolder.java:140)
    at org.eclipse.jetty.servlet.ServletHandler.lambda$initialize$0(ServletHandler.java:750)
    at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:992)
    at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:734)
    at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:774)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:379)
    at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1449)
    at com.google.apphosting.runtime.jetty9.AppEngineWebAppContext.startWebapp(AppEngineWebAppContext.java:273)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1414)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:916)
    at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:288)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:524)
    at com.google.apphosting.runtime.jetty9.AppEngineWebAppContext.doStart(AppEngineWebAppContext.java:219)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:73)
    at com.google.apphosting.runtime.jetty9.AppVersionHandlerFactory.doCreateHandler(AppVersionHandlerFactory.java:225)
    at com.google.apphosting.runtime.jetty9.AppVersionHandlerFactory.createHandler(A… [message truncated due to size]

研究后,似乎一种解决方法是注释掉 web.xml 中的行(见下文)。

web.xml

<?xml version="1.0" encoding="utf-8"?>
<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">

    <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.company.api.OurAppApi</param-value>
        </init-param>
        <init-param>
            <param-name>restricted</param-name>
            <param-value>false</param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>EndpointsServlet</servlet-name>
        <url-pattern>/_ah/api/*</url-pattern>
    </servlet-mapping>

<!-- COMMENTING THIS OUT WORKS. 
    <filter>
        <filter-name>endpoints-api-configuration</filter-name>
        <filter-class>com.google.api.control.ServiceManagementConfigFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>endpoints-api-configuration</filter-name>
        <servlet-name>EndpointsServlet</servlet-name>
    </filter-mapping>
-->

    <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>test2-ourappapi</param-value>
        </init-param>
        <init-param>
            <param-name>endpoints.serviceName</param-name>
            <param-value>test2-ourappapi.appspot.com</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>endpoints-api-controller</filter-name>
        <servlet-name>EndpointsServlet</servlet-name>
    </filter-mapping>
</web-app>

appengine-web.xml

  </system-properties>
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">

  <sessions-enabled>false</sessions-enabled>
  <runtime>java17</runtime>
  <app-engine-apis>true</app-engine-apis>
  <automatic-scaling>
    <min-instances>1</min-instances>
  </automatic-scaling>

  <system-properties>
    <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
  </system-properties>

  <env-variables>
    <env-var name="ENDPOINTS_SERVICE_NAME" value="test2-ourappapi.appspot.com" />
  </env-variables>

</appengine-web-app>

我可以确认这有效。 但是,文档表明删除这些行会绕过 GCE 对端点的管理。

发生什么事了?

请注意,我已更新到最新的 Google Cloud SDK。 设置项目后,我还运行了“gcloud auth application-default login”。

google-cloud-platform google-app-engine openapi google-cloud-endpoints
1个回答
0
投票

我想我发现了问题。 这是在 POM 中。

<dependency>
    <groupId>com.google.endpoints</groupId>
    <artifactId>endpoints-management-control-appengine-all</artifactId>
    <version>1.0.14</version>
</dependency>

当版本更改为1.0.15时似乎可以工作。 我还不太相信它。 所以,我还得再用一段时间。

© www.soinside.com 2019 - 2024. All rights reserved.