Closed deepfriedbrain closed 2 years ago
Perhaps it's not finding any servlets, there is no annotation based auto-detection anymore. Does your web.xml include the EndpointsServlets in the SystemServiceServletSection
<servlet>
<servlet-name>SystemServiceServlet</servlet-name>
<servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value>com.example.helloendpoints.Greetings</param-value>
</init-param>
<servlet-name>
<servlet>
The example here will generated endpoints config for com.example.helloendpoints.Greetings
Previously you could see this in the final web.xml generated for you by the maven tooling.
@lesv @frankyn can we update the docs to indicate that they must define their servlets in step 5?
@loosebazooka, the request is to call out:
Documentation should call out that every service should be defined under services:
<init-param>
<param-name>services</param-name>
<param-value>com.example.helloendpoints.Greetings</param-value>
</init-param>
I managed to get the Discovery Docs generated. The problem was with my folder structure. It was looking for src/main/webapp
folder but I had it as web
as in a regular Java web application. After moving web
to src/main/webapp
, I could get the Discovery Docs generated.
Everything else was configured correctly as per the migration guide (which I linked in my original post).
My project was not a Maven project earlier. I converted it to a Maven project just so I could generate the Discovery Docs for Endpoints Framework 2.0. I had never used Maven before and didn't know that it was very particular about the folder structure.
BTW, is there a way to generate the Discovery Docs without using Maven (say through Google Cloud Tools for Eclipse)?
I have the services defined correctly in the web.xml . I have multiple services under param-value, separated by comma. But it would be good to add that to the documentation for those who may not be aware of it.
Similarly, under the Guice configuration section, it would be good to include an example with multiple endpoint classes instead of the single class example.
@elharo should know better about cloud tools for eclipse. @deepfriedbrain yes, it makes sense to add a note about multiple values. @frankyn can we add to the docs a comma separated multiple value example?
Thanks for the help. I uploaded my app to the app engine, but somehow the endpoints service calls are returning 404 (Not Found). It works on local dev server though.
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? I'm lost on the need of the Discovery Document.
@tangiel ?
@frankyn Are you working on this? Or do I need to find a TW?
Apologies for the delay. I can pick up the update next week with the Endpoints TW.
Follow-up question: Guice allows a user to define services in Java and not in the web.xml
. If a user doesn't know this then they will not be able to generate a discovery document. Why was the annotation auto-detection removed?
Sorry but I'm not following the last few comments. Is that follow-up question directed to me?
Can someone please comment on my issue? I've tried out everything I could possibly do. Is there something I should fix or is someone looking into it? Thanks.
The question was meant for @patflynn and @loosebazooka
@frankyn There wasn't a way to guarantee accuracy.
@deepfriedbrain yes, the JS client uses the discovery doc to dynamically generate the surface. Regarding your issue, can you deploy the migrated code to a new version of your App Engine service? That should fix it. If not, please show what your 404 looks like.
@tangiel I did deploy it to a new version (a standard practice that I follow with any new update) and still had this issue. I showed what the 404 looks like in the logs in my earlier post.
With Endpoints 1.0, even though I don't have any discovery doc, the JS client is able to call my APIs and it has been working well for the past several months. I can also use the API Explorer to view my API information. So how does the JS client and the API Explorer work without the discovery docs? Please help me understand.
In the meantime, I had contacted Cloud Platform Support and got this response from them:
Just an update, the scenario you raised is also being experienced by other users and I already raised this to our superiors in order for the product specialist to be engaged as soon as possible as this can be related to a bug.
I will keep you updated on the progress and rest assured that the problem is being worked on towards to immediate resolution.
Meanwhile, kindly use Cloud Endpoints version 1 as a workaround.
Requesting for your patience on this one.
I'm hoping that they know what the issue is and working on a fix. Let me know if I can provide any additional information on this case.
I have similar problem with Endpoints V2 migration. Getting 404 NOT systematically. Any updates or advice to the issue? Found this thread after asking here also: https://stackoverflow.com/questions/49133695/404-after-migrating-to-google-endpoints-v2
I followed the migration guide (https://cloud.google.com/endpoints/docs/frameworks/legacy/v1/java/migrating) to migrate to Endpoints v2.0.
However, when I run
mvn endpoints-framework:discoveryDocs
the target\discovery-docs folder is blank and no discovery docs are generated. I don't see any errors either in the console and at the end I do see "BUILD SUCCESS".Am I missing something?