迁移到Cloud Endpoints 2.0 - 在localhost上工作,但在App Engine上工作

时间:2023-02-11 23:12:46

I'm migration my GAE Java app to Google Cloud Endpoints 2.0. I followed the migration guide (https://cloud.google.com/endpoints/docs/frameworks/legacy/v1/java/migrating) to migrate to Endpoints v2.0.

我将我的GAE Java应用程序迁移到Google Cloud Endpoints 2.0。我按照迁移指南(https://cloud.google.com/endpoints/docs/frameworks/legacy/v1/java/migrating)迁移到Endpoints v2.0。

The endpoints service calls are working on localhost but returning 404 (Not Found) when uploaded to the App Engine. I'm using Guice.

端点服务调用正在localhost上工作,但在上传到App Engine时返回404(未找到)。我正在使用Guice。

The relevant section from my web.xml looks similar to this:

我的web.xml中的相关部分看起来类似于:

<filter>
    <filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>guiceFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<listener>
    <listener-class>com.xyz.myapp.server.guice.MyAppGuiceServletContextListener</listener-class>
</listener>

<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.xyz.myapp.server.endpoints.MyEP1,com.xyz.myapp.server.endpoints.MyEP2</param-value>
  </init-param>
</servlet>

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

MyAppGuiceServletContextListener.java

MyAppGuiceServletContextListener.java

public class MyAppGuiceServletContextListener extends GuiceServletContextListener { 
    @Override
    protected Injector getInjector() {
        return Guice.createInjector(new GuiceServletModule(), new EPServletModule());
    }
}

EPServletModule.java

EPServletModule.java

public class EPServletModule extends EndpointsModule {
    @Override
    protected void configureServlets() {
        super.configureServlets();      
        Set<Class<?>> serviceClasses = new HashSet<Class<?>>();
        serviceClasses.add(MyEP1.class);
        serviceClasses.add(MyEP2.class);
        configureEndpoints("/_ah/api/*", serviceClasses);       
    }
}

GuiceServletModule:

GuiceServletModule:

public class GuiceServletModule extends ServletModule {
    @Override
    protected void configureServlets() {
    super.configureServlets();
    serve("/myapp/servlet1").with(Servlet1.class);
    serve("/myapp/servlet2").with(Servlet2.class);
    }
}

I'm able to invoke the regular servlets at the paths:

我可以在路径上调用常规servlet:

https://[version]-dot-myapp-id.appspot.com/myapp/servlet1

https://[version]-dot-myapp-id.appspot.com/myapp/servlet2

But I'm not able to access the endpoints. It always returns 404 error code. I tried via my Javascript client and also via the APIs Explorer, and get the same error.

但是我无法访问端点。它总是返回404错误代码。我尝试通过我的Javascript客户端,也通过API资源管理器,并得到相同的错误。

I also checked the logs and strangely the logs show the POST request like this:

我还检查了日志,奇怪的是日志显示POST请求,如下所示:

"POST /_ah/spi/com.xyz.myapp.server.endpoints.MyEP1.myEPMethod HTTP/1.1" 404

Why does it start with /_ah/spi/ when my client is invoking it via /_ah/api/ ?

当我的客户端通过/ _ah / api /调用它时,为什么以/ _ah / spi /开头?

NOTE: I'm able to invoke the Endpoints 1.0, which are deployed on a different version of the same app, without any issue. But the Endpoints 2.0 version is not working.

注意:我可以调用Endpoints 1.0,它们部署在同一个应用程序的不同版本上,没有任何问题。但Endpoints 2.0版本无效。

Am I missing something?

我错过了什么吗?

I also have a very basic question. My client is Javascript based. Does it really make use of the Discovery Document?

我也有一个非常基本的问题。我的客户端是基于Javascript的。它真的使用了Discovery文档吗?

1 个解决方案

#1


0  

I fixed this by Updating Android Studio to the latest version and updating the SDK.

我通过将Android Studio更新到最新版本并更新SDK来解决此问题。

#1


0  

I fixed this by Updating Android Studio to the latest version and updating the SDK.

我通过将Android Studio更新到最新版本并更新SDK来解决此问题。