简体   繁体   English

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

[英]Migrating to Cloud Endpoints 2.0 - Working on localhost but not on App Engine

I'm migration my GAE Java app to Google Cloud Endpoints 2.0. 我正在将GAE Java应用程序迁移到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. 我按照迁移指南( 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. 端点服务调用在localhost上运行,但上传到App Engine时返回404(未找到)。 I'm using Guice. 我正在使用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. 它总是返回404错误代码。 I tried via my Javascript client and also via the APIs Explorer, and get the same error. 我通过Javascript客户端以及API Explorer进行了尝试,并得到相同的错误。

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. 注意:我能够调用Endpoints 1.0,它部署在同一应用程序的不同版本上,没有任何问题。 But the Endpoints 2.0 version is not working. 但是Endpoints 2.0版本无法正常工作。

Am I missing something? 我想念什么吗?

I also have a very basic question. 我还有一个非常基本的问题。 My client is Javascript based. 我的客户基于Javascript。 Does it really make use of the Discovery Document? 它真的利用发现文件吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM