DFB
DFB

Reputation: 899

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. I followed the migration guide (https://cloud.google.com/endpoints/docs/frameworks/legacy/v1/java/migrating) to migrate to 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.

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

<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);
    }
}

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

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.

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

"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/ ?

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.

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?

Upvotes: 1

Views: 109

Answers (1)

Nicola Blaine
Nicola Blaine

Reputation: 75

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

Upvotes: 0

Related Questions