繁体   English   中英

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

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

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

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

我的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

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

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:

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

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

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

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

但是我无法访问端点。 它总是返回404错误代码。 我通过Javascript客户端以及API Explorer进行了尝试,并得到相同的错误。

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

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

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

注意:我能够调用Endpoints 1.0,它部署在同一应用程序的不同版本上,没有任何问题。 但是Endpoints 2.0版本无法正常工作。

我想念什么吗?

我还有一个非常基本的问题。 我的客户基于Javascript。 它真的利用发现文件吗?

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

暂无
暂无

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

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