簡體   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