-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Could I add a spring boot version of endpoints-v2-backend? #3095
Comments
@lesv does tagging as feature request mean I can submit a pull request or does it have to go through some other story vetting first? |
@Aubrey-Y Sorry- I didn't realize you were offering to provide this. |
Hi @Aubrey-Y - we talked about this today and thought you might wish to look at our community (code) pages. Your sample is likely to get greater visibility that way. Feel free to ping me or Averi when you are ready for review. Either on the repo or on this issue. I'm going to close this for now, feel free to reopen. |
@lesv The tutorial that specifically references this is under the codelabs subdomain (https://codelabs.developers.google.com/codelabs/cloud-endpoints-appengine/index.html?index=..%2F..index#0) so is there a way to create a tutorial there that would accompany a PR to My personal thinking is that there is a much clearer purpose for it here as opposed to What I was trying to accomplish here, initially, was that if someone had run into the same issue where they would have liked to run a cloud endpoints sample locally, they could poke around and quickly find this alternate version of the project/tutorial. I would of course be happy to write a tutorial for it, even though the changes wouldn't be that significant. |
@navinger @tomboc @frankyn @simonz130 All of you have changed this. |
I no longer own endpoints. |
absolutely! where would you want it added in the repository? @lesv |
Thank you for your patiences. Can you add this sample under the |
sure, i dont have it prepared already but ill try to find time to do it over the next week |
One point of clarification - should it use Java 8 or another version (i.e. 11)? @lesv (or both) |
Java 11 is preferred. |
A small update. So I started an mvp today and ran into an issue with what I assume are the discrepancies between From what I can tell, to run tomcat with docker, cloudendpoints, which I assume is under the @google org, manages these dependencies at cloudendpoints/endpoints-management-java and I've opened up an issue there to upgrade their In the meantime, I'll keep looking for ways to ignore their version of If you have any other ideas I'd be open to those. |
In the meantime, I actually figured out a solution. Even though these are the dependencies used in the legacy appengine java8 endpoints sample that I'm sort of trying to replicate, java-docs-samples/appengine-java8/endpoints-v2-backend/pom.xml Lines 47 to 59 in 2eca87d
I had a peek through Google's other endpoints-related libraries in mvnrepository and found a version of endpoints management similar to The library endpoints-management-control actually has a package structure that enables the So, I can move forward for now like this (even though it looks ugly) <!-- Compile/runtime dependencies -->
<dependency>
<groupId>com.google.endpoints</groupId>
<artifactId>endpoints-framework</artifactId>
<version>${endpoints.framework.version}</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- [START api_management] -->
<dependency>
<groupId>com.google.endpoints</groupId>
<artifactId>endpoints-management-control</artifactId>
<version>1.0.12</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- [END api_management] --> |
How strictly do we want to follow the pipeline orchestrated by appengine-java8/endpoints-v2-backend? @lesv java-docs-samples/appengine-java8/endpoints-v2-backend/pom.xml Lines 108 to 118 in 2eca87d
I did some digging into the functionality provided by the Endpoints Framework Maven plugin (documentation) and it doesn't look like it supports much else other than generating a basic openapi spec of your controllers in json format. This is a limitation in terms of a demo project, because it doesn't really allow for much showing off of some of the most interesting features of Cloud Endpoints, like api keys for example. Google does have documentation regarding how to enable api keys but it won't fit nicely into the plugin generator because of two reasons:
I just feel like it's not a good look to the end user if we try showing off literally anything else other than the "track api activity" page, because of these constraints i just mentioned, which is all the existing demo is doing. I know, I know, this was a sort of long read, but we have a few options:
|
The google endpoint framework is for App Engine which uses servlets. We wouldn't want to force integrating it with Spring Boot. We want to show how to use Endpoints backed by Extensible Service Proxy V2 Beta (ESPv2 Beta) since it's the preferred way. Therefore the best use of time would be to provide a Spring Boot app with the proper tools to generate the openapi.yaml see in Configuring Endpoints. We then could point that documentation to your code. |
okay, im just now realizing this - so no more endpoints related dependencies in my pom now.
To make sure I'm understanding you correctly, you're looking for the spring boot app to come with a tool to generate an From reading the documentation though the implication was that you'd have to write and maintain it manually. |
I though you had said you had your personal project working with Spring and Endpoints on App Engine, correct? Moving the sample that uses the Endpoint framework with servlets to the Spring framework shouldn't work because the Endpoints framework only works on our Java 8 App Engine (servlet framework) runtime. To use Java 11 on App Engine or Cloud Run, all you need is the openAPI spec and both these runtimes work with Spring. You could provide a sample + the OpenAPI config file like the docs say; however it would be more interesting to have the spec generated. There should be libraries to generate OpenAPI config files from Spring apps. Nothing about this is actually Google or endpoints related, it's just based on the OpenAPI spec which is not Google owned. |
So third party libraries/plugins are fine? |
Yes, if you have any hesitations or questions about vetting the library/plugins just let us know here. |
Follow up -> the Configuring Endpoints resource you linked (https://cloud.google.com/endpoints/docs/openapi/get-started-cloud-run#endpoints_configure) uses Swagger 2.0. Can we upgrade to Swagger 3.0.1, and I guess a relevant question is also whether it's supported by Cloud Endpoints? @averikitsch |
Unfortunately we don't yet support version 3. |
If it helps at all, I recorded a briefish 15m video walking through the PR, while I was half asleep, with one hand >< So it's definitely low quality but if you need some context it's there At a high level, I found an open source library (springdoc) that supports openapi3, which is actually not all that different from the configuration google needs. With that said, I've tried and gcp won't accept openapi3. So there are a few minute differences, mostly lines that need to be removed, in order to convert an openapi3 file to swagger2. Since springdoc already had a convenient plugin that generates an openapi.yaml file during the integration test phase, I wrote another plugin that can conveniently run right after springdoc generates the openapi3 version, and seamlessly deliver a swagger2 version that gcp accepts (I dont actually remember to demonstrate it in the video but basically I've uploaded it here for now: https://github.com/aubrey-y/openapi-converter-maven-plugin with GCP package structure and license javadocs, under the I don't mind if I transfer ownership to you guys and you publish the plugin, or if I try to publish it myself. Or, maybe this custom plugin thing is not a good idea? It works seamlessly with springdoc to generate the openapi file as was initially requested though, so I like it. One thing that I am stuck on though is the ESPv2 container. I try and follow through all the steps from scratch here https://www.loom.com/share/e3e33e8ad1434a4888243360b92a7f6f and the ESP container never worked, so I don't think I'll be able to figure that out without extra help. I can document all the local deployment steps but I don't think I'm understanding the tutorial correctly. |
A nice thing about this approach could also be that if Cloud Endpoints eventually supports openapi3, all you would have to do is remove the extra conversion plugin and you would already be at openapi 3, less a few configurations possibly. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Fixes #3095 > It's a good idea to open an issue first for discussion. - [x] I have followed [Sample Format Guide](https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/SAMPLE_FORMAT.md) - [X] `pom.xml` parent set to latest `shared-configuration` - [x] Appropriate changes to README are included in PR - [X] API's need to be enabled to test (tell us) - [ ] Environment Variables need to be set (ask us to set them) - [X] **Tests** pass: `mvn clean verify` **required** - [X] **Lint** passes: `mvn -P lint checkstyle:check` **required** - [X] **Static Analysis**: `mvn -P lint clean compile pmd:cpd-check spotbugs:check` **advisory only** - [X] Please **merge** this PR for me once it is approved. <details> <summary>mvn clean verify</summary> <pre> aubre@DESKTOP-F4APIAI ~/Projects/java-docs-samples/run/endpoints-v2-backend (run-endpoints) $ mvn clean verify [INFO] Scanning for projects... [INFO] [INFO] -----------------------< com.example:endpoints >------------------------ [INFO] Building rest 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ endpoints --- [INFO] Deleting /mnt/c/Users/aubre/Projects/java-docs-samples/run/endpoints-v2-backend/target [INFO] [INFO] --- jacoco-maven-plugin:0.8.5:prepare-agent (default) @ endpoints --- [INFO] argLine set to -javaagent:/mnt/c/Users/aubre/.m2/repository/org/jacoco/org.jacoco.agent/0.8.5/org.jacoco.agent-0.8.5-runtime.jar=destfile=/mnt/c/Users/aubre/Projects/java-docs-samples/run/endpoints-v2-backend/target/jacoco.ex ec [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ endpoints --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ endpoints --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 2 source files to /mnt/c/Users/aubre/Projects/java-docs-samples/run/endpoints-v2-backend/target/classes [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ endpoints --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory /mnt/c/Users/aubre/Projects/java-docs-samples/run/endpoints-v2-backend/src/test/resources [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ endpoints --- [INFO] No sources to compile [INFO] [INFO] --- maven-surefire-plugin:3.0.0-M4:test (default-test) @ endpoints --- [INFO] No tests to run. [INFO] [INFO] --- jacoco-maven-plugin:0.8.5:report (report) @ endpoints --- [INFO] Skipping JaCoCo execution due to missing execution data file. [INFO] [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ endpoints --- [INFO] Building jar: /mnt/c/Users/aubre/Projects/java-docs-samples/run/endpoints-v2-backend/target/endpoints-1.0-SNAPSHOT.jar [INFO] [INFO] --- spring-boot-maven-plugin:2.3.1.RELEASE:start (pre-integration-test) @ endpoints --- [INFO] Attaching agents: [] . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.3.1.RELEASE) 2020-07-22 23:44:57.590 INFO 23566 --- [ main] c.e.endpoints.EndpointsApplication : Starting EndpointsApplication on DESKTOP-F4APIAI with PID 23566 (/mnt/c/Users/aubre/Projects/java-docs-samples/run/endpoints-v2-bac kend/target/classes started by aubre in /mnt/c/Users/aubre/Projects/java-docs-samples/run/endpoints-v2-backend) 2020-07-22 23:44:57.597 INFO 23566 --- [ main] c.e.endpoints.EndpointsApplication : No active profile set, falling back to default profiles: default 2020-07-22 23:45:01.012 INFO 23566 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2020-07-22 23:45:01.042 INFO 23566 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2020-07-22 23:45:01.042 INFO 23566 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.36] 2020-07-22 23:45:01.397 INFO 23566 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2020-07-22 23:45:01.397 INFO 23566 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3661 ms 2020-07-22 23:45:02.025 INFO 23566 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor' 2020-07-22 23:45:03.723 INFO 23566 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '' 2020-07-22 23:45:03.753 INFO 23566 --- [ main] c.e.endpoints.EndpointsApplication : Started EndpointsApplication in 7.509 seconds (JVM running for 9.314) [INFO] [INFO] --- maven-failsafe-plugin:3.0.0-M4:integration-test (default) @ endpoints --- [INFO] No tests to run. [INFO] [INFO] --- springdoc-openapi-maven-plugin:1.0:generate (integration-test) @ endpoints --- 2020-07-22 23:45:06.712 INFO 23566 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet' 2020-07-22 23:45:06.713 INFO 23566 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2020-07-22 23:45:06.728 INFO 23566 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 15 ms 2020-07-22 23:45:07.120 INFO 23566 --- [nio-8080-exec-1] o.springdoc.api.AbstractOpenApiResource : Init duration for springdoc-openapi is: 280 ms [INFO] [INFO] --- openapi-converter-maven-plugin:1.0.0-SNAPSHOT:convertOpenApiDocs (integration-test) @ endpoints --- [INFO] [INFO] --- spring-boot-maven-plugin:2.3.1.RELEASE:stop (post-integration-test) @ endpoints --- [INFO] Stopping application... 2020-07-22 23:45:08.039 INFO 23566 --- [on(2)-127.0.0.1] inMXBeanRegistrar$SpringApplicationAdmin : Application shutdown requested. 2020-07-22 23:45:08.083 INFO 23566 --- [on(2)-127.0.0.1] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor' [INFO] [INFO] --- maven-failsafe-plugin:3.0.0-M4:verify (default) @ endpoints --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 38.060 s [INFO] Finished at: 2020-07-22T23:45:08-04:00 [INFO] ------------------------------------------------------------------------ </pre> </details> <details> <summary>mvn -P lint checkstyle:check</summary> <pre> aubre@DESKTOP-F4APIAI ~/Projects/java-docs-samples/run/endpoints-v2-backend (run-endpoints) $ mvn -P lint checkstyle:check [INFO] Scanning for projects... [INFO] [INFO] -----------------------< com.example:endpoints >------------------------ [INFO] Building rest 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-checkstyle-plugin:3.1.1:check (default-cli) @ endpoints --- [INFO] Starting audit... Audit done. [INFO] You have 0 Checkstyle violations. [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 12.978 s [INFO] Finished at: 2020-07-22T23:57:47-04:00 [INFO] ------------------------------------------------------------------------ </pre> </details> <details> <summary>mvn -P lint clean compile pmd:cpd-check spotbugs:check</summary> <pre> aubre@DESKTOP-F4APIAI ~/Projects/java-docs-samples/run/endpoints-v2-backend (run-endpoints) $ mvn -P lint clean compile pmd:cpd-check spotbugs:check [INFO] Scanning for projects... [INFO] [INFO] -----------------------< com.example:endpoints >------------------------ [INFO] Building rest 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ endpoints --- [INFO] Deleting /mnt/c/Users/aubre/Projects/java-docs-samples/run/endpoints-v2-backend/target [INFO] [INFO] --- jacoco-maven-plugin:0.8.5:prepare-agent (default) @ endpoints --- [INFO] argLine set to -javaagent:/mnt/c/Users/aubre/.m2/repository/org/jacoco/org.jacoco.agent/0.8.5/org.jacoco.agent-0.8.5-runtime.jar=destfile=/mnt/c/Users/aubre/Projects/java-docs-samples/run/endpoints-v2-backend/target/jacoco.ex ec [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ endpoints --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ endpoints --- ... [INFO] Changes detected - recompiling the module! [INFO] Compiling 2 source files to /mnt/c/Users/aubre/Projects/java-docs-samples/run/endpoints-v2-backend/target/classes [INFO] [INFO] >>> spotbugs-maven-plugin:4.0.0:check (analyze-compile) > :spotbugs @ endpoints >>> [INFO] [INFO] --- spotbugs-maven-plugin:4.0.0:spotbugs (spotbugs) @ endpoints --- ... [INFO] Done SpotBugs Analysis.... [INFO] [INFO] <<< spotbugs-maven-plugin:4.0.0:check (analyze-compile) < :spotbugs @ endpoints <<< [INFO] [INFO] [INFO] --- spotbugs-maven-plugin:4.0.0:check (analyze-compile) @ endpoints --- [INFO] BugInstance size is 2 [INFO] Error size is 0 [INFO] Total bugs: 2 [ERROR] com.example.endpoints.controllers.RepeatController is a Spring endpoint (Controller) [com.example.endpoints.controllers.RepeatController] At RepeatController.java:[lines 34-40] SPRING_ENDPOINT [ERROR] Method com.example.endpoints.controllers.RepeatController.repeat(String, Integer) passes constant String of length 1 to character overridden method [com.example.endpoints.controllers.RepeatController] At RepeatController.jav a:[line 38] UCPM_USE_CHARACTER_PARAMETERIZED_METHOD [INFO] To see bug detail using the Spotbugs GUI, use the following command "mvn spotbugs:gui" [INFO] ------------------------------------------------------------------------ [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 01:11 min [INFO] Finished at: 2020-07-23T00:00:14-04:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal com.github.spotbugs:spotbugs-maven-plugin:4.0.0:check (analyze-compile) on project endpoints: failed with 2 bugs and 0 errors -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException </pre> </details> ~~This pull request is **not** final. I wanted to get the functional part of the code approved before writing a detailed instructional README.~~
In which file did you encounter the issue?
https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/appengine-java8/endpoints-v2-backend
Did you change the file? If so, how?
I can add a new
endpoints-v2-backend-spring
copy that closely resembles the linked project but uses JAR instead of WAR (which imo is the better file format) in conjunction with Spring Boot.Describe the issue
The existing demo project is fine, although it's really not beginner friendly and doesn't teach best development practices since, AFAIK, there is no way to test it locally.
Using Spring allows you to simulate what's being deployed by app engine on localhost.
I have my own more personalized version of the project working with GAE and GCF. (and of course maven + spring + jar)
The text was updated successfully, but these errors were encountered: