迁移到 Google 端点 V2 后的 404



我们已经在我们的应用程序中成功使用了端点V1几年。现在,当尝试迁移到端点 V2 时,它突然刹车,只是简单地找不到端点 Servlet,并且总是返回 404。

  • 我能够浏览 API 与 https://apis-explorer.appspot.com/apis-explorer/
  • 我可以看到请求来到后端和我正在使用的一个过滤器
  • 但它从未找到/到达端点 Servlet 或任何端点
  • 奇怪的是它在本地主机开发服务器中工作??

这是否仍然是一个已知问题(对于某些应用程序(或我如何排查这种情况?

404 响应如下所示:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "notFound",
    "message": "u003chtmlu003eu003cheadu003enu003cmeta http-equiv="content-type" content="text/html;charset=utf-8"u003enu003ctitleu003e404 Not Foundu003c/titleu003enu003c/headu003enu003cbody text=#000000 bgcolor=#ffffffu003enu003ch1u003eError: Not Foundu003c/h1u003enu003c/bodyu003eu003c/htmlu003en"
   }
  ],
  "code": 404,
  "message": "u003chtmlu003eu003cheadu003enu003cmeta http-equiv="content-type" content="text/html;charset=utf-8"u003enu003ctitleu003e404 Not Foundu003c/titleu003enu003c/headu003enu003cbody text=#000000 bgcolor=#ffffffu003enu003ch1u003eError: Not Foundu003c/h1u003enu003c/bodyu003eu003c/htmlu003en"
 }
}

解决方案是在使用终结点 V2 部署应用时使用全新的未使用版本名称,因此而不是:

https://test-dot-[app_id].appspot.com (this used previously Endpoints V1)

使用全新的版本名称,例如

https://test-new-dot-[app_id].appspot.com

正如这里所说: https://cloud.google.com/endpoints/docs/known-issues

"...您当前必须部署到新的 App Engine 应用版本。重用旧应用版本可能会与旧端点部署冲突...">

当我仍然将SystemServiceServlet配置为使用旧的url模式时,我遇到了这个问题。

正确:

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

不對:

 <servlet-mapping>
    <servlet-name>SystemServiceServlet</servlet-name>
    <url-pattern>/_ah/spi/*</url-pattern>
</servlet-mapping>

V2 的 servlet 类也更改为:com.google.api.server.spi.EndpointsServlet

确保

  1. 你在web.xml中有这个部分(无论你在POM中是否有它.XML与否!
 <!-- 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.Foo</param-value>
        </init-param>
    </servlet>
<!--     Route API method requests to the backend. -->
    <servlet-mapping>
        <servlet-name>EndpointsServlet</servlet-name>
        <url-pattern>/_ah/api/*</url-pattern>
    </servlet-mapping>
  1. 您在 web.xml、pom.xml、appengine-web.xml 中正确且始终相同的 {ProjectId}。如果使用 gcloud shell,请检查您当前的活动配置及其项目。

  2. 为了更安全,请在新版本上部署应用,同时从旧框架 V1 迁移到 V2。

最新更新