├── .github ├── CODEOWNERS ├── blunderbuss.yml └── sync-repo-settings.yaml ├── .gitignore ├── .gitmodules ├── .kokoro ├── java11 │ ├── common.cfg │ ├── continuous.cfg │ ├── periodic.cfg │ └── presubmit.cfg ├── java8 │ ├── common.cfg │ ├── continuous.cfg │ ├── periodic.cfg │ └── presubmit.cfg ├── lint │ ├── common.cfg │ └── presubmit.cfg ├── tests │ ├── run_diff_only.sh │ ├── run_lint.sh │ └── run_tests.sh └── trampoline.sh ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── appengine-standard-java8 ├── deployAll.sh ├── helloworld-gae-javasdk-tools │ ├── README.md │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── pom.xml │ ├── settings.gradle │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── appengine │ │ │ │ └── java8 │ │ │ │ └── HelloAppEngine.java │ │ └── webapp │ │ │ ├── WEB-INF │ │ │ └── appengine-web.xml │ │ │ └── index.jsp │ │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── appengine │ │ └── java8 │ │ └── HelloAppEngineTest.java ├── kotlin-appengine-standard │ ├── .gitignore │ ├── README.md │ ├── nbactions.xml │ ├── pom.xml │ └── src │ │ └── main │ │ ├── kotlin │ │ └── HomeController.kt │ │ └── webapp │ │ └── WEB-INF │ │ ├── appengine-web.xml │ │ └── logging.properties ├── kotlin-sb-appengine-standard │ ├── .gitignore │ ├── README.md │ ├── nbactions.xml │ ├── pom.xml │ └── src │ │ └── main │ │ ├── kotlin │ │ └── org │ │ │ └── jetbrains │ │ │ └── kotlin │ │ │ └── demo │ │ │ ├── Application.kt │ │ │ ├── Greeting.kt │ │ │ └── GreetingController.kt │ │ └── webapp │ │ └── WEB-INF │ │ ├── appengine-web.xml │ │ └── logging.properties └── kotlin-spark-appengine-standard │ ├── .gitignore │ ├── README.md │ ├── pom.xml │ └── src │ └── main │ ├── kotlin │ ├── MainApp.kt │ └── SparkInitFilter.kt │ └── webapp │ └── WEB-INF │ ├── appengine-web.xml │ └── logging.properties ├── background ├── README.md ├── pom.xml ├── sample_message.json └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── getstarted │ │ │ └── background │ │ │ ├── functions │ │ │ ├── CreateServlet.java │ │ │ └── TranslateServlet.java │ │ │ ├── objects │ │ │ ├── PubSubMessage.java │ │ │ ├── TranslateAttributes.java │ │ │ └── TranslateMessage.java │ │ │ └── util │ │ │ └── BackgroundContextListener.java │ └── webapp │ │ ├── base.jsp │ │ ├── form.jsp │ │ └── list.jsp │ └── test │ └── java │ └── com │ └── getstarted │ └── background │ └── UserJourneyTestIT.java ├── bookshelf-standard ├── 2-structured-data │ ├── README.md │ ├── jenkins.sh │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── getstarted │ │ │ ├── basicactions │ │ │ ├── CreateBookServlet.java │ │ │ ├── DeleteBookServlet.java │ │ │ ├── ListBookServlet.java │ │ │ ├── ReadBookServlet.java │ │ │ └── UpdateBookServlet.java │ │ │ ├── daos │ │ │ ├── BookDao.java │ │ │ ├── CloudSqlDao.java │ │ │ └── DatastoreDao.java │ │ │ ├── objects │ │ │ ├── Book.java │ │ │ └── Result.java │ │ │ └── util │ │ │ └── DatastoreSessionFilter.java │ │ └── webapp │ │ ├── WEB-INF │ │ ├── appengine-web.xml │ │ ├── logging.properties │ │ └── web.xml │ │ ├── base.jsp │ │ ├── form.jsp │ │ ├── list.jsp │ │ └── view.jsp ├── 3-binary-data │ ├── README.md │ ├── jenkins.sh │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── getstarted │ │ │ ├── basicactions │ │ │ ├── CreateBookServlet.java │ │ │ ├── DeleteBookServlet.java │ │ │ ├── ListBookServlet.java │ │ │ ├── ReadBookServlet.java │ │ │ └── UpdateBookServlet.java │ │ │ ├── daos │ │ │ ├── BookDao.java │ │ │ ├── CloudSqlDao.java │ │ │ └── DatastoreDao.java │ │ │ ├── objects │ │ │ ├── Book.java │ │ │ └── Result.java │ │ │ └── util │ │ │ ├── CloudStorageHelper.java │ │ │ └── DatastoreSessionFilter.java │ │ └── webapp │ │ ├── WEB-INF │ │ ├── appengine-web.xml │ │ ├── logging.properties │ │ └── web.xml │ │ ├── base.jsp │ │ ├── form.jsp │ │ ├── list.jsp │ │ └── view.jsp ├── 4-auth │ ├── README.md │ ├── jenkins.sh │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── getstarted │ │ │ ├── auth │ │ │ ├── ListByUserFilter.java │ │ │ ├── LoginServlet.java │ │ │ ├── LogoutFilter.java │ │ │ └── LogoutServlet.java │ │ │ ├── basicactions │ │ │ ├── CreateBookServlet.java │ │ │ ├── DeleteBookServlet.java │ │ │ ├── ListBookServlet.java │ │ │ ├── ListByUserServlet.java │ │ │ ├── ReadBookServlet.java │ │ │ └── UpdateBookServlet.java │ │ │ ├── daos │ │ │ ├── BookDao.java │ │ │ ├── CloudSqlDao.java │ │ │ └── DatastoreDao.java │ │ │ ├── objects │ │ │ ├── Book.java │ │ │ └── Result.java │ │ │ └── util │ │ │ ├── CloudStorageHelper.java │ │ │ └── DatastoreSessionFilter.java │ │ └── webapp │ │ ├── WEB-INF │ │ ├── appengine-web.xml │ │ ├── datastore-indexes.xml │ │ ├── logging.properties │ │ └── web.xml │ │ ├── base.jsp │ │ ├── form.jsp │ │ ├── list.jsp │ │ └── view.jsp └── 5-logging │ ├── README.md │ ├── jenkins.sh │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── com │ │ └── example │ │ └── getstarted │ │ ├── auth │ │ ├── ListByUserFilter.java │ │ ├── LoginServlet.java │ │ ├── LogoutFilter.java │ │ └── LogoutServlet.java │ │ ├── basicactions │ │ ├── CreateBookServlet.java │ │ ├── DeleteBookServlet.java │ │ ├── ListBookServlet.java │ │ ├── ListByUserServlet.java │ │ ├── ReadBookServlet.java │ │ └── UpdateBookServlet.java │ │ ├── daos │ │ ├── BookDao.java │ │ ├── CloudSqlDao.java │ │ └── DatastoreDao.java │ │ ├── objects │ │ ├── Book.java │ │ └── Result.java │ │ └── util │ │ ├── CloudStorageHelper.java │ │ └── DatastoreSessionFilter.java │ └── webapp │ ├── WEB-INF │ ├── appengine-web.xml │ ├── datastore-indexes.xml │ ├── logging.properties │ └── web.xml │ ├── base.jsp │ ├── form.jsp │ ├── list.jsp │ └── view.jsp ├── bookshelf └── 1-cloud-run │ ├── README.md │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── com │ │ └── example │ │ └── getstarted │ │ ├── basicactions │ │ ├── CreateBookServlet.java │ │ ├── DeleteBookServlet.java │ │ ├── ErrorsBookServlet.java │ │ ├── ListBookServlet.java │ │ ├── ReadBookServlet.java │ │ └── UpdateBookServlet.java │ │ ├── daos │ │ ├── BookDao.java │ │ └── FirestoreDao.java │ │ ├── objects │ │ ├── Book.java │ │ └── Result.java │ │ └── util │ │ ├── BookshelfContextListener.java │ │ └── CloudStorageHelper.java │ └── webapp │ ├── WEB-INF │ └── web.xml │ ├── base.jsp │ ├── form.jsp │ ├── list.jsp │ └── view.jsp ├── codecov.yml ├── gce ├── README.md ├── config │ └── base │ │ ├── etc │ │ └── java-util-logging.properties │ │ ├── modules │ │ └── gce.mod │ │ └── resources │ │ └── jetty-logging.properties ├── makeProject ├── pom.xml ├── scripts │ └── startup-script.sh └── src │ ├── main │ ├── appengine │ │ └── app.yaml │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── getstarted │ │ │ └── basicactions │ │ │ └── HelloworldController.java │ └── webapp │ │ └── WEB-INF │ │ └── web.xml │ └── test │ └── java │ └── com │ └── example │ └── getstarted │ └── basicactions │ └── UserJourneyTestIT.java ├── helloworld-jsp ├── README.md ├── build.gradle ├── eclipse-launch-profiles │ ├── AppEngineDeploy.launch │ └── AppEngineRun.launch ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── nbactions.xml ├── pom.xml └── src │ └── main │ ├── appengine │ └── app.yaml │ ├── java │ └── org │ │ └── example │ │ └── appengine │ │ └── hello │ │ └── HelloInfo.java │ └── webapp │ ├── WEB-INF │ ├── logging.properties │ └── web.xml │ ├── favicon.ico │ └── hello.jsp ├── mvnw.cmd └── renovate.json /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Code owners file. 2 | # This file controls who is tagged for review for any given pull request. 3 | 4 | # The java-samples-reviewers team is the default owner for anything not 5 | # explicitly taken by someone else. 6 | * @GoogleCloudPlatform/java-samples-reviewers 7 | -------------------------------------------------------------------------------- /.github/blunderbuss.yml: -------------------------------------------------------------------------------- 1 | assign_issues: 2 | - GoogleCloudPlatform/java-samples-reviewers 3 | assign_prs: 4 | - GoogleCloudPlatform/java-samples-reviewers 5 | -------------------------------------------------------------------------------- /.github/sync-repo-settings.yaml: -------------------------------------------------------------------------------- 1 | rebaseMergeAllowed: true 2 | squashMergeAllowed: true 3 | mergeCommitAllowed: false 4 | branchProtectionRules: 5 | - pattern: main 6 | isAdminEnforced: false 7 | requiredStatusCheckContexts: 8 | - 'Kokoro CI - Java 8' 9 | - 'Kokoro CI - Java 11' 10 | - 'Kokoro CI - Lint' 11 | - 'cla/google' 12 | requiredApprovingReviewCount: 1 13 | requiresCodeOwnerReviews: true 14 | requiresStrictStatusChecks: true 15 | permissionRules: 16 | - team: java-samples-reviewers 17 | permission: push 18 | - team: yoshi-java 19 | permission: push 20 | - team: devrel-java-admin 21 | permission: admin 22 | - team: yoshi-admins 23 | permission: admin 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Eclipse files 2 | .project 3 | .classpath 4 | .settings 5 | 6 | # IntelliJ IDEA 7 | .Idea 8 | *.iml 9 | .idea/ 10 | 11 | # Target folders 12 | target/ 13 | build/ 14 | out/ 15 | .gradle/ 16 | bin/ 17 | 18 | ## Vim ## 19 | # swap 20 | [._]*.s[a-w][a-z] 21 | [._]s[a-w][a-z] 22 | # session 23 | Session.vim 24 | # temporary 25 | .netrwhist 26 | *~ 27 | # auto-generated tag files 28 | tags 29 | 30 | ## Secrets ## 31 | client-secret.json 32 | 33 | **/pom.xml.versionsBackup -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleCloudPlatform/getting-started-java/faece5ea8b3634e9229858ff90e95a096193ada5/.gitmodules -------------------------------------------------------------------------------- /.kokoro/java11/common.cfg: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Format: //devtools/kokoro/config/proto/build.proto 16 | 17 | # Build timeout of 5 hours 18 | timeout_mins: 300 19 | 20 | # Download trampoline resources. 21 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" 22 | 23 | # Use the trampoline script to run in docker. 24 | build_file: "getting-started-java/.kokoro/trampoline.sh" 25 | 26 | action { 27 | define_artifacts { 28 | regex: "**/*sponge_log.xml" 29 | } 30 | } 31 | 32 | # Set the JAVA VERSION env var. 33 | env_vars: { 34 | key: "JAVA_VERSION" 35 | value: "1.8,11" 36 | } 37 | 38 | # Configure the docker image for kokoro-trampoline. 39 | env_vars: { 40 | key: "TRAMPOLINE_IMAGE" 41 | value: "gcr.io/cloud-devrel-kokoro-resources/java11" 42 | } 43 | -------------------------------------------------------------------------------- /.kokoro/java11/continuous.cfg: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Format: //devtools/kokoro/config/proto/build.proto 16 | 17 | # Tell the trampoline which tests to run. 18 | env_vars: { 19 | key: "TRAMPOLINE_BUILD_FILE" 20 | value: "github/getting-started-java/.kokoro/tests/run_tests.sh" 21 | } 22 | -------------------------------------------------------------------------------- /.kokoro/java11/periodic.cfg: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Format: //devtools/kokoro/config/proto/build.proto 16 | 17 | # Tell the trampoline which build file to use. 18 | env_vars: { 19 | key: "TRAMPOLINE_BUILD_FILE" 20 | value: "github/getting-started-java/.kokoro/tests/run_tests.sh" 21 | } 22 | -------------------------------------------------------------------------------- /.kokoro/java11/presubmit.cfg: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Format: //devtools/kokoro/config/proto/build.proto 16 | 17 | # Tell the trampoline which build file to use. 18 | env_vars: { 19 | key: "TRAMPOLINE_BUILD_FILE" 20 | value: "github/getting-started-java/.kokoro/tests/run_diff_only.sh" 21 | } 22 | -------------------------------------------------------------------------------- /.kokoro/java8/common.cfg: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Format: //devtools/kokoro/config/proto/build.proto 16 | 17 | # Build timeout of 5 hours 18 | timeout_mins: 300 19 | 20 | # Download trampoline resources. 21 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" 22 | 23 | # Use the trampoline script to run in docker. 24 | build_file: "getting-started-java/.kokoro/trampoline.sh" 25 | 26 | action { 27 | define_artifacts { 28 | regex: "**/*sponge_log.xml" 29 | } 30 | } 31 | 32 | # Set the JAVA VERSION env var. 33 | env_vars: { 34 | key: "JAVA_VERSION" 35 | value: "1.8" 36 | } 37 | 38 | # Configure the docker image for kokoro-trampoline. 39 | env_vars: { 40 | key: "TRAMPOLINE_IMAGE" 41 | value: "gcr.io/cloud-devrel-kokoro-resources/java8" 42 | } 43 | -------------------------------------------------------------------------------- /.kokoro/java8/continuous.cfg: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Format: //devtools/kokoro/config/proto/build.proto 16 | 17 | # Tell trampoline which tests to run. 18 | env_vars: { 19 | key: "TRAMPOLINE_BUILD_FILE" 20 | value: "github/getting-started-java/.kokoro/tests/run_tests.sh" 21 | } 22 | 23 | -------------------------------------------------------------------------------- /.kokoro/java8/periodic.cfg: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Format: //devtools/kokoro/config/proto/build.proto 16 | 17 | # Tell the trampoline which build file to use. 18 | env_vars: { 19 | key: "TRAMPOLINE_BUILD_FILE" 20 | value: "github/getting-started-java/.kokoro/tests/run_tests.sh" 21 | } 22 | 23 | -------------------------------------------------------------------------------- /.kokoro/java8/presubmit.cfg: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Format: //devtools/kokoro/config/proto/build.proto 16 | 17 | # Tell the trampoline which build file to use. 18 | env_vars: { 19 | key: "TRAMPOLINE_BUILD_FILE" 20 | value: "github/getting-started-java/.kokoro/tests/run_diff_only.sh" 21 | } 22 | -------------------------------------------------------------------------------- /.kokoro/lint/common.cfg: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Format: //devtools/kokoro/config/proto/build.proto 16 | 17 | # Use the trampoline to bounce the script into docker. 18 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" 19 | build_file: "getting-started-java/.kokoro/trampoline.sh" 20 | env_vars: { 21 | key: "TRAMPOLINE_IMAGE" 22 | value: "gcr.io/cloud-devrel-kokoro-resources/java8" 23 | } 24 | env_vars: { 25 | key: "TRAMPOLINE_BUILD_FILE" 26 | value: "github/getting-started-java/.kokoro/tests/run_lint.sh" 27 | } 28 | 29 | # Access btlr binaries used in the tests 30 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/btlr" 31 | 32 | 33 | # Upload logs to result-store 34 | action { 35 | define_artifacts { 36 | regex: "**/*sponge_log.xml" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /.kokoro/lint/presubmit.cfg: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Format: //devtools/kokoro/config/proto/build.proto 16 | 17 | # Tell the trampoline which build file to use. 18 | env_vars: { 19 | key: "GIT_DIFF" 20 | value: "origin/main... ." 21 | } 22 | -------------------------------------------------------------------------------- /.kokoro/tests/run_diff_only.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2017 Google Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | mydir="${0%/*}" 16 | "$mydir"/run_tests.sh --only-diff -------------------------------------------------------------------------------- /.kokoro/tests/run_lint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2020 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # `-e` enables the script to automatically fail when a command fails 17 | # `-o pipefail` sets the exit code to the rightmost comment to exit with a non-zero 18 | set -eo pipefail 19 | 20 | # If on kokoro, add btlr to the path and cd into repo root 21 | if [ -n "$KOKORO_GFILE_DIR" ]; then 22 | bltr_dir="$KOKORO_GFILE_DIR/v0.0.1/" 23 | chmod +x "${bltr_dir}"btlr 24 | export PATH="$PATH:$bltr_dir" 25 | cd github/getting-started-java || exit 26 | fi 27 | 28 | opts=() 29 | if [ -n "$GIT_DIFF" ]; then 30 | opts+=( 31 | "--git-diff" 32 | "$GIT_DIFF" 33 | ) 34 | fi 35 | 36 | btlr "${opts[@]}" run "**/pom.xml" -- mvn -P lint --quiet --batch-mode checkstyle:check 37 | -------------------------------------------------------------------------------- /.kokoro/trampoline.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2017 Google Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | python3 "${KOKORO_GFILE_DIR}/trampoline_v1.py" 17 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, 4 | and in the interest of fostering an open and welcoming community, 5 | we pledge to respect all people who contribute through reporting issues, 6 | posting feature requests, updating documentation, 7 | submitting pull requests or patches, and other activities. 8 | 9 | We are committed to making participation in this project 10 | a harassment-free experience for everyone, 11 | regardless of level of experience, gender, gender identity and expression, 12 | sexual orientation, disability, personal appearance, 13 | body size, race, ethnicity, age, religion, or nationality. 14 | 15 | Examples of unacceptable behavior by participants include: 16 | 17 | * The use of sexualized language or imagery 18 | * Personal attacks 19 | * Trolling or insulting/derogatory comments 20 | * Public or private harassment 21 | * Publishing other's private information, 22 | such as physical or electronic 23 | addresses, without explicit permission 24 | * Other unethical or unprofessional conduct. 25 | 26 | Project maintainers have the right and responsibility to remove, edit, or reject 27 | comments, commits, code, wiki edits, issues, and other contributions 28 | that are not aligned to this Code of Conduct. 29 | By adopting this Code of Conduct, 30 | project maintainers commit themselves to fairly and consistently 31 | applying these principles to every aspect of managing this project. 32 | Project maintainers who do not follow or enforce the Code of Conduct 33 | may be permanently removed from the project team. 34 | 35 | This code of conduct applies both within project spaces and in public spaces 36 | when an individual is representing the project or its community. 37 | 38 | Instances of abusive, harassing, or otherwise unacceptable behavior 39 | may be reported by opening an issue 40 | or contacting one or more of the project maintainers. 41 | 42 | This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, 43 | available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/) 44 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to become a contributor and submit your own code 2 | 3 | ## Contributor License Agreements 4 | 5 | We'd love to accept your sample apps and patches! Before we can take them, we 6 | have to jump a couple of legal hurdles. 7 | 8 | Please fill out either the individual or corporate Contributor License Agreement 9 | (CLA): 10 | 11 | * If you are an individual writing original source code and you're sure you 12 | own the intellectual property, then you'll need to sign an [individual CLA](https://developers.google.com/open-source/cla/individual). 13 | * If you work for a company that wants to allow you to contribute your work, 14 | then you'll need to sign a [corporate CLA](https://developers.google.com/open-source/cla/corporate). 15 | 16 | Follow either of the two links above to access the appropriate CLA and 17 | instructions for how to sign and return it. Once we receive it, we'll be able to 18 | accept your pull requests. 19 | 20 | ## Contributing A Patch 21 | 22 | 1. Submit an issue describing your proposed change to the repository in question. 23 | 2. The repository owner will respond to your issue promptly. 24 | 3. If your proposed change is accepted, and you haven't already done so, sign a 25 | CLA (see details above). 26 | 4. Fork the desired repo, then develop and test your code changes. 27 | 5. Ensure that your code adheres to the existing style in the sample to which 28 | you are contributing. Refer to the [Google Java Style Guide](http://google.github.io/styleguide/javaguide.html) and the 29 | [Google Cloud Platform Community Style Guide](https://cloud.google.com/community/tutorials/styleguide) for the 30 | recommended coding standards for this organization. 31 | 6. Ensure that your code has an appropriate set of unit tests which all pass. 32 | 7. Submit a pull request. 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Getting started on Google Cloud Platform for Java® 2 | 3 | [![CircleCI Build Status](https://circleci.com/gh/GoogleCloudPlatform/getting-started-java.svg?style=shield&circle-token=51b789e102291cbeae6817678d02da0f4cf25f1f)](https://circleci.com/gh/GoogleCloudPlatform/getting-started-java) 4 | [![Coverage Status](https://codecov.io/gh/GoogleCloudPlatform/getting-started-java/branch/main/graph/badge.svg)](https://codecov.io/gh/GoogleCloudPlatform/getting-started-java) 5 | 6 | The code for the samples is contained in individual folders on this repository. 7 | Follow the instructions at [Getting Started on Google Cloud Platform for Java](https://cloud.google.com/java/) or the README files in each folder for instructions on how to run locally and deploy. 8 | 9 | Managed VMs on Google Cloud Platform use the [Java Servlets](http://www.oracle.com/technetwork/java/overview-137084.html) & [Java Server Pages](http://www.oracle.com/technetwork/java/index-jsp-138231.html) on [Jetty](http://www.eclipse.org/jetty/). 10 | 11 | 1. [Helloworld-servlet](helloworld-servlet) Servlet based Hello World app 12 | 1. [HelloWorld-jsp](helloworld-jsp) Java Server Pages based Hello World app 13 | 1. [Bookshelf](bookshelf) A full featured app that demonstrates Authentication and CRUD operations for [Cloud Datastore](https://cloud.google.com/datastore/docs/concepts/overview?hl=en) and [Cloud SQL](https://cloud.google.com/sql/docs/introduction). 14 | 15 | ## Google Cloud Samples 16 | 17 | To browse ready to use code samples check [Google Cloud samples](https://cloud.google.com/docs/samples). 18 | 19 | ## Contributing changes 20 | 21 | * See [CONTRIBUTING.md](CONTRIBUTING.md) 22 | 23 | 24 | ## Licensing 25 | 26 | * See [LICENSE](LICENSE) 27 | 28 | Java is a registered trademark of Oracle Corporation and/or its affiliates. 29 | -------------------------------------------------------------------------------- /appengine-standard-java8/deployAll.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2017 Google Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # set -x 17 | # set -v 18 | 19 | # gcloud config configurations activate qa 20 | 21 | for app in "helloworld" "kotlin-appengine-standard" \ 22 | "kotlin-sb-appengine-standard" \ 23 | "springboot-appengine-standard" "kotlin-spark-appengine-standard" \ 24 | "sparkjava-appengine-standard" 25 | do 26 | (cd "${app}" 27 | sed --in-place='.xx' "s/<\/runtime>/<\/runtime>${app}<\/service>/" \ 28 | src/main/webapp/WEB-INF/appengine-web.xml 29 | mvn -B --fail-at-end -q package appengine:deploy -Dapp.deploy.version="1" \ 30 | -Dapp.stage.quickstart=true -Dapp.deploy.force=true -Dapp.deploy.promote=true \ 31 | -Dapp.deploy.projectId="${GOOGLE_CLOUD_PROJECT}" -DskipTests=true 32 | mv src/main/webapp/WEB-INF/appengine-web.xml.xx src/main/webapp/WEB-INF/appengine-web.xml) 33 | done 34 | 35 | echo "STATUS: ${?}" 36 | -------------------------------------------------------------------------------- /appengine-standard-java8/helloworld-gae-javasdk-tools/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleCloudPlatform/getting-started-java/faece5ea8b3634e9229858ff90e95a096193ada5/appengine-standard-java8/helloworld-gae-javasdk-tools/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /appengine-standard-java8/helloworld-gae-javasdk-tools/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jun 13 16:53:48 PDT 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip 7 | -------------------------------------------------------------------------------- /appengine-standard-java8/helloworld-gae-javasdk-tools/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /appengine-standard-java8/helloworld-gae-javasdk-tools/settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This settings file was generated by the Gradle 'init' task. 3 | * 4 | * The settings file is used to specify which projects to include in your build. 5 | * In a single project build this file can be empty or even removed. 6 | * 7 | * Detailed information about configuring a multi-project build in Gradle can be found 8 | * in the user guide at https://docs.gradle.org/3.5/userguide/multi_project_builds.html 9 | */ 10 | 11 | /* 12 | // To declare projects as part of a multi-project build use the 'include' method 13 | include 'shared' 14 | include 'api' 15 | include 'services:webservice' 16 | */ 17 | 18 | rootProject.name = 'helloworld_gae_tooling' 19 | -------------------------------------------------------------------------------- /appengine-standard-java8/helloworld-gae-javasdk-tools/src/main/java/com/example/appengine/java8/HelloAppEngine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.appengine.java8; 18 | 19 | // [START example] 20 | import com.google.appengine.api.utils.SystemProperty; 21 | import java.io.IOException; 22 | import java.util.Properties; 23 | import javax.servlet.annotation.WebServlet; 24 | import javax.servlet.http.HttpServlet; 25 | import javax.servlet.http.HttpServletRequest; 26 | import javax.servlet.http.HttpServletResponse; 27 | 28 | // With @WebServlet annotation the webapp/WEB-INF/web.xml is no longer required. 29 | @WebServlet(name = "HelloAppEngine", value = "/hello") 30 | public class HelloAppEngine extends HttpServlet { 31 | 32 | @Override 33 | public void doGet(HttpServletRequest request, HttpServletResponse response) 34 | throws IOException { 35 | 36 | Properties properties = System.getProperties(); 37 | 38 | response.setContentType("text/plain"); 39 | response.getWriter().println("Hello App Engine - Standard using " 40 | + SystemProperty.version.get() + " Java " + properties.get("java.specification.version")); 41 | 42 | } 43 | 44 | public static String getInfo() { 45 | return "Version: " + System.getProperty("java.version") 46 | + " OS: " + System.getProperty("os.name") 47 | + " User: " + System.getProperty("user.name"); 48 | } 49 | 50 | } 51 | // [END example] 52 | -------------------------------------------------------------------------------- /appengine-standard-java8/helloworld-gae-javasdk-tools/src/main/webapp/WEB-INF/appengine-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | helloworld-gae 20 | java8 21 | true 22 | 23 | 24 | -------------------------------------------------------------------------------- /appengine-standard-java8/helloworld-gae-javasdk-tools/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <%-- 4 | ~ Copyright 2017 Google Inc. 5 | ~ 6 | ~ Licensed under the Apache License, Version 2.0 (the "License"); you 7 | ~ may not use this file except in compliance with the License. You may 8 | ~ obtain a copy of the License at 9 | ~ 10 | ~ http://www.apache.org/licenses/LICENSE-2.0 11 | ~ 12 | ~ Unless required by applicable law or agreed to in writing, software 13 | ~ distributed under the License is distributed on an "AS IS" BASIS, 14 | ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 15 | ~ implied. See the License for the specific language governing 16 | ~ permissions and limitations under the License. 17 | --%> 18 | 19 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 20 | <%@ page import="com.example.appengine.java8.HelloAppEngine" %> 21 | 22 | 23 | 24 | Hello App Engine Standard Java 8 25 | 26 | 27 |

Hello App Engine -- Java 8!

28 | 29 |

This is <%= HelloAppEngine.getInfo() %>.

30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 |
Available Servlets:
Hello App Engine
38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /appengine-standard-java8/kotlin-appengine-standard/.gitignore: -------------------------------------------------------------------------------- 1 | hotspot.log 2 | *.iml 3 | *.ipr 4 | *.iws 5 | .gradle/ 6 | build/ 7 | target/ 8 | classes/ 9 | /var 10 | pom.xml.versionsBackup 11 | test-output/ 12 | /atlassian-ide-plugin.xml 13 | .idea 14 | .DS_Store 15 | .classpath 16 | .settings 17 | .project 18 | temp-testng-customsuite.xml 19 | test-output 20 | .externalToolBuilders 21 | *~ 22 | -------------------------------------------------------------------------------- /appengine-standard-java8/kotlin-appengine-standard/README.md: -------------------------------------------------------------------------------- 1 | App Engine Java Kotlin Servlet 3.1 with Java8 2 | === 3 | 4 | ## Sample Servlet 3.1 written in Kotlin for use with App Engine Java8 Standard. 5 | 6 | See the [Google App Engine standard environment documentation][ae-docs] for more 7 | detailed instructions. 8 | 9 | [ae-docs]: https://cloud.google.com/appengine/docs/java/ 10 | 11 | * [Java 8](http://www.oracle.com/technetwork/java/javase/downloads/index.html) 12 | * [Maven](https://maven.apache.org/download.cgi) (at least 3.5) 13 | * [Google Cloud SDK](https://cloud.google.com/sdk/) (aka gcloud command line tool) 14 | 15 | ## Setup 16 | 17 | * Download and initialize the [Cloud SDK](https://cloud.google.com/sdk/) 18 | 19 | ``` 20 | gcloud init 21 | ``` 22 | 23 | * Create an App Engine app within the current Google Cloud Project 24 | 25 | ``` 26 | gcloud app create 27 | ``` 28 | 29 | * In the `pom.xml`, update the [App Engine Maven Plugin](https://cloud.google.com/appengine/docs/standard/java/tools/maven-reference) 30 | with your Google Cloud Project Id: 31 | 32 | ``` 33 | 34 | com.google.cloud.tools 35 | appengine-maven-plugin 36 | 2.3.0 37 | 38 | GCLOUD_CONFIG 39 | GCLOUD_CONFIG 40 | 41 | 42 | ``` 43 | **Note:** `GCLOUD_CONFIG` is a special version for autogenerating an App Engine 44 | version. Change this field to specify a specific version name. 45 | 46 | ## Maven 47 | ### Running locally 48 | 49 | `mvn package appengine:run` 50 | 51 | To use visit: http://localhost:8080/ 52 | 53 | ### Deploying 54 | 55 | `mvn package appengine:deploy` 56 | 57 | To use visit: https://YOUR-PROJECT-ID.appspot.com 58 | 59 | ## Testing 60 | 61 | `mvn verify` 62 | 63 | As you add / modify the source code (`src/main/java/...`) it's very useful to add [unit testing](https://cloud.google.com/appengine/docs/java/tools/localunittesting) 64 | to (`src/main/test/...`). The following resources are quite useful: 65 | 66 | * [Junit4](http://junit.org/junit4/) 67 | * [Mockito](http://mockito.org/) 68 | * [Truth](http://google.github.io/truth/) 69 | 70 | 71 | For further information, consult the 72 | [Java App Engine](https://developers.google.com/appengine/docs/java/overview) documentation. 73 | -------------------------------------------------------------------------------- /appengine-standard-java8/kotlin-appengine-standard/src/main/kotlin/HomeController.kt: -------------------------------------------------------------------------------- 1 | // See https://github.com/JetBrains/kotlin-examples/blob/master/LICENSE 2 | package org.jetbrains.kotlin.demo 3 | 4 | import javax.servlet.annotation.WebServlet 5 | import javax.servlet.http.HttpServlet 6 | import javax.servlet.http.HttpServletRequest 7 | import javax.servlet.http.HttpServletResponse 8 | 9 | @WebServlet(name = "Hello", value = ["/"]) 10 | class HomeController : HttpServlet() { 11 | override fun doGet(req: HttpServletRequest, res: HttpServletResponse) { 12 | res.writer.write("Hello, World! I am a Servlet 3.1 running on Java8 App Engine Standard, and written in Kotlin...") 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /appengine-standard-java8/kotlin-appengine-standard/src/main/webapp/WEB-INF/appengine-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | true 16 | java8 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /appengine-standard-java8/kotlin-appengine-standard/src/main/webapp/WEB-INF/logging.properties: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # Licensed under the Apache License, Version 2.0 (the "License"); 3 | # you may not use this file except in compliance with the License. 4 | # You may obtain a copy of the License at 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # Unless required by applicable law or agreed to in writing, software 7 | # distributed under the License is distributed on an "AS IS" BASIS, 8 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | # See the License for the specific language governing permissions and 10 | # limitations under the License. 11 | 12 | # A default java.util.logging configuration. 13 | # (All App Engine logging is through java.util.logging by default). 14 | # 15 | # To use this configuration, copy it into your application's WEB-INF 16 | # folder and add the following to your appengine-web.xml: 17 | # 18 | # 19 | # 20 | # 21 | # 22 | 23 | # Set the default logging level for all loggers to WARNING 24 | .level = WARNING 25 | -------------------------------------------------------------------------------- /appengine-standard-java8/kotlin-sb-appengine-standard/.gitignore: -------------------------------------------------------------------------------- 1 | hotspot.log 2 | *.iml 3 | *.ipr 4 | *.iws 5 | .gradle/ 6 | build/ 7 | target/ 8 | classes/ 9 | /var 10 | pom.xml.versionsBackup 11 | test-output/ 12 | /atlassian-ide-plugin.xml 13 | .idea 14 | .DS_Store 15 | .classpath 16 | .settings 17 | .project 18 | temp-testng-customsuite.xml 19 | test-output 20 | .externalToolBuilders 21 | *~ 22 | -------------------------------------------------------------------------------- /appengine-standard-java8/kotlin-sb-appengine-standard/README.md: -------------------------------------------------------------------------------- 1 | App Engine Java SpringBoot Kotlin application 2 | === 3 | 4 | ## Sample SpringBoot application written in Kotlin for use with App Engine Java8 Standard. 5 | 6 | See the [Google App Engine standard environment documentation][ae-docs] for more 7 | detailed instructions. 8 | 9 | [ae-docs]: https://cloud.google.com/appengine/docs/java/ 10 | 11 | * [Java 8](http://www.oracle.com/technetwork/java/javase/downloads/index.html) 12 | * [Maven](https://maven.apache.org/download.cgi) (at least 3.5) 13 | * [Google Cloud SDK](https://cloud.google.com/sdk/) (aka gcloud command line tool) 14 | 15 | ## Setup 16 | 17 | * Download and initialize the [Cloud SDK](https://cloud.google.com/sdk/) 18 | 19 | ``` 20 | gcloud init 21 | ``` 22 | 23 | * Create an App Engine app within the current Google Cloud Project 24 | 25 | ``` 26 | gcloud app create 27 | ``` 28 | 29 | * In the `pom.xml`, update the [App Engine Maven Plugin](https://cloud.google.com/appengine/docs/standard/java/tools/maven-reference) 30 | with your Google Cloud Project Id: 31 | 32 | ``` 33 | 34 | com.google.cloud.tools 35 | appengine-maven-plugin 36 | 2.3.0 37 | 38 | GCLOUD_CONFIG 39 | GCLOUD_CONFIG 40 | 41 | 42 | ``` 43 | **Note:** `GCLOUD_CONFIG` is a special version for autogenerating an App Engine 44 | version. Change this field to specify a specific version name. 45 | 46 | ## Maven 47 | ### Running locally 48 | 49 | `mvn package appengine:run` 50 | 51 | To use visit: http://localhost:8080/ 52 | 53 | ### Deploying 54 | 55 | `mvn package appengine:deploy` 56 | 57 | To use visit: https://YOUR-PROJECT-ID.appspot.com 58 | 59 | ## Testing 60 | 61 | `mvn verify` 62 | 63 | As you add / modify the source code (`src/main/java/...`) it's very useful to add [unit testing](https://cloud.google.com/appengine/docs/java/tools/localunittesting) 64 | to (`src/main/test/...`). The following resources are quite useful: 65 | 66 | * [Junit4](http://junit.org/junit4/) 67 | * [Mockito](http://mockito.org/) 68 | * [Truth](http://google.github.io/truth/) 69 | 70 | 71 | For further information, consult the 72 | [Java App Engine](https://developers.google.com/appengine/docs/java/overview) documentation. 73 | -------------------------------------------------------------------------------- /appengine-standard-java8/kotlin-sb-appengine-standard/src/main/kotlin/org/jetbrains/kotlin/demo/Application.kt: -------------------------------------------------------------------------------- 1 | // See https://github.com/JetBrains/kotlin-examples/blob/master/LICENSE 2 | package org.jetbrains.kotlin.demo 3 | 4 | import org.springframework.boot.SpringApplication 5 | import org.springframework.boot.autoconfigure.SpringBootApplication 6 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer 7 | 8 | @SpringBootApplication 9 | class Application : SpringBootServletInitializer() { 10 | 11 | } 12 | 13 | fun main(args: Array) { 14 | SpringApplication.run(Application::class.java, *args) 15 | } 16 | -------------------------------------------------------------------------------- /appengine-standard-java8/kotlin-sb-appengine-standard/src/main/kotlin/org/jetbrains/kotlin/demo/Greeting.kt: -------------------------------------------------------------------------------- 1 | // See https://github.com/JetBrains/kotlin-examples/blob/master/LICENSE 2 | package org.jetbrains.kotlin.demo 3 | 4 | data class Greeting(val id: Long, val content: String) 5 | -------------------------------------------------------------------------------- /appengine-standard-java8/kotlin-sb-appengine-standard/src/main/kotlin/org/jetbrains/kotlin/demo/GreetingController.kt: -------------------------------------------------------------------------------- 1 | // See https://github.com/JetBrains/kotlin-examples/blob/master/LICENSE 2 | package org.jetbrains.kotlin.demo 3 | 4 | import org.springframework.web.bind.annotation.GetMapping 5 | import org.springframework.web.bind.annotation.RequestParam 6 | import org.springframework.web.bind.annotation.RestController 7 | import java.util.concurrent.atomic.AtomicLong 8 | 9 | @RestController 10 | class GreetingController { 11 | 12 | val counter = AtomicLong() 13 | 14 | @GetMapping("/greeting") 15 | fun greeting(@RequestParam(value = "name", defaultValue = "World") name: String) = 16 | Greeting(counter.incrementAndGet(), "Hello, $name, from a SpringBoot Application written in Kotlin, running on Google App Engine Java8 Standard...") 17 | } 18 | -------------------------------------------------------------------------------- /appengine-standard-java8/kotlin-sb-appengine-standard/src/main/webapp/WEB-INF/appengine-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | true 16 | java8 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /appengine-standard-java8/kotlin-sb-appengine-standard/src/main/webapp/WEB-INF/logging.properties: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # Licensed under the Apache License, Version 2.0 (the "License"); 3 | # you may not use this file except in compliance with the License. 4 | # You may obtain a copy of the License at 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # Unless required by applicable law or agreed to in writing, software 7 | # distributed under the License is distributed on an "AS IS" BASIS, 8 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | # See the License for the specific language governing permissions and 10 | # limitations under the License. 11 | 12 | # A default java.util.logging configuration. 13 | # (All App Engine logging is through java.util.logging by default). 14 | # 15 | # To use this configuration, copy it into your application's WEB-INF 16 | # folder and add the following to your appengine-web.xml: 17 | # 18 | # 19 | # 20 | # 21 | # 22 | 23 | # Set the default logging level for all loggers to WARNING 24 | .level = WARNING 25 | -------------------------------------------------------------------------------- /appengine-standard-java8/kotlin-spark-appengine-standard/.gitignore: -------------------------------------------------------------------------------- 1 | hotspot.log 2 | *.iml 3 | *.ipr 4 | *.iws 5 | .gradle/ 6 | build/ 7 | target/ 8 | classes/ 9 | /var 10 | pom.xml.versionsBackup 11 | test-output/ 12 | /atlassian-ide-plugin.xml 13 | .idea 14 | .DS_Store 15 | .classpath 16 | .settings 17 | .project 18 | temp-testng-customsuite.xml 19 | test-output 20 | .externalToolBuilders 21 | *~ 22 | -------------------------------------------------------------------------------- /appengine-standard-java8/kotlin-spark-appengine-standard/README.md: -------------------------------------------------------------------------------- 1 | App Engine SparkJava Kotlin with Java8 2 | === 3 | 4 | ## Sample SparkJava application written in Kotlin for use with App Engine Java8 Standard. 5 | 6 | For Spark Kotlin documentation, see [Spark Kotlin](https://github.com/perwendel/spark-kotlin/). 7 | 8 | See the [Google App Engine standard environment documentation][ae-docs] for more 9 | detailed instructions. 10 | 11 | [ae-docs]: https://cloud.google.com/appengine/docs/java/ 12 | 13 | * [Java 8](http://www.oracle.com/technetwork/java/javase/downloads/index.html) 14 | * [Maven](https://maven.apache.org/download.cgi) (at least 3.5) 15 | * [Google Cloud SDK](https://cloud.google.com/sdk/) (aka gcloud command line tool) 16 | 17 | ## Setup 18 | 19 | * Download and initialize the [Cloud SDK](https://cloud.google.com/sdk/) 20 | 21 | ``` 22 | gcloud init 23 | ``` 24 | 25 | * Create an App Engine app within the current Google Cloud Project 26 | 27 | ``` 28 | gcloud app create 29 | ``` 30 | 31 | * In the `pom.xml`, update the [App Engine Maven Plugin](https://cloud.google.com/appengine/docs/standard/java/tools/maven-reference) 32 | with your Google Cloud Project Id: 33 | 34 | ``` 35 | 36 | com.google.cloud.tools 37 | appengine-maven-plugin 38 | 2.3.0 39 | 40 | GCLOUD_CONFIG 41 | GCLOUD_CONFIG 42 | 43 | 44 | ``` 45 | **Note:** `GCLOUD_CONFIG` is a special version for autogenerating an App Engine 46 | version. Change this field to specify a specific version name. 47 | 48 | ## Maven 49 | ### Running locally 50 | 51 | `mvn package appengine:run` 52 | 53 | To use visit: http://localhost:8080/ 54 | 55 | ### Deploying 56 | 57 | `mvn package appengine:deploy` 58 | 59 | To use visit: https://YOUR-PROJECT-ID.appspot.com 60 | 61 | ## Testing 62 | 63 | `mvn verify` 64 | 65 | As you add / modify the source code (`src/main/java/...`) it's very useful to add [unit testing](https://cloud.google.com/appengine/docs/java/tools/localunittesting) 66 | to (`src/main/test/...`). The following resources are quite useful: 67 | 68 | * [Junit4](http://junit.org/junit4/) 69 | * [Mockito](http://mockito.org/) 70 | * [Truth](http://google.github.io/truth/) 71 | 72 | 73 | For further information, consult the 74 | [Java App Engine](https://developers.google.com/appengine/docs/java/overview) documentation. 75 | -------------------------------------------------------------------------------- /appengine-standard-java8/kotlin-spark-appengine-standard/src/main/kotlin/MainApp.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import spark.kotlin.Http 17 | import spark.kotlin.ignite 18 | import spark.servlet.SparkApplication 19 | 20 | /** 21 | * Example usage of spark-kotlin. 22 | * See https://github.com/perwendel/spark-kotlin 23 | */ 24 | class MainApp : SparkApplication { 25 | override fun init() { 26 | 27 | val http: Http = ignite() 28 | 29 | http.get("/") { 30 | """Hello Spark Kotlin running on Java8 App Engine Standard. 31 |

You can try /hello

or /saymy/:name

or redirect 32 |

or /nothing""" 33 | } 34 | http.get("/hello") { 35 | "Hello Spark Kotlin running on Java8 App Engine Standard." 36 | } 37 | 38 | http.get("/nothing") { 39 | status(404) 40 | "Oops, we couldn't find what you're looking for." 41 | } 42 | 43 | http.get("/saymy/:name") { 44 | params(":name") 45 | } 46 | 47 | http.get("/redirect") { 48 | redirect("/hello"); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /appengine-standard-java8/kotlin-spark-appengine-standard/src/main/kotlin/SparkInitFilter.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import javax.servlet.annotation.WebFilter 17 | import javax.servlet.annotation.WebInitParam 18 | 19 | import spark.servlet.SparkFilter 20 | 21 | 22 | // Use Servlet annotation to define the Spark filter without web.xml: 23 | @WebFilter( 24 | filterName = "SparkInitFilter", 25 | urlPatterns = arrayOf("/*"), 26 | initParams = arrayOf( 27 | WebInitParam( 28 | name = "applicationClass", 29 | value = "MainApp") 30 | 31 | )) 32 | class SparkInitFilter : SparkFilter() { 33 | } 34 | -------------------------------------------------------------------------------- /appengine-standard-java8/kotlin-spark-appengine-standard/src/main/webapp/WEB-INF/appengine-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | true 16 | java8 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /appengine-standard-java8/kotlin-spark-appengine-standard/src/main/webapp/WEB-INF/logging.properties: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # Licensed under the Apache License, Version 2.0 (the "License"); 3 | # you may not use this file except in compliance with the License. 4 | # You may obtain a copy of the License at 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # Unless required by applicable law or agreed to in writing, software 7 | # distributed under the License is distributed on an "AS IS" BASIS, 8 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | # See the License for the specific language governing permissions and 10 | # limitations under the License. 11 | 12 | # A default java.util.logging configuration. 13 | # (All App Engine logging is through java.util.logging by default). 14 | # 15 | # To use this configuration, copy it into your application's WEB-INF 16 | # folder and add the following to your appengine-web.xml: 17 | # 18 | # 19 | # 20 | # 21 | # 22 | 23 | # Set the default logging level for all loggers to WARNING 24 | .level = WARNING 25 | -------------------------------------------------------------------------------- /background/sample_message.json: -------------------------------------------------------------------------------- 1 | { 2 | "message":{ 3 | "data":"Hello world!", 4 | "attributes":{ 5 | "sourceLang":"en", 6 | "targetLang":"es" 7 | }, 8 | "messageId":"181789827785065", 9 | "publishTime":"2018-01-06T00:41:01.839Z" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /background/src/main/java/com/getstarted/background/objects/PubSubMessage.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 Google LLC 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.getstarted.background.objects; 17 | 18 | // [START getting_started_background_pub_sub_message] 19 | public class PubSubMessage { 20 | private TranslateMessage message; 21 | private String subscription; 22 | 23 | public TranslateMessage getMessage() { 24 | return message; 25 | } 26 | 27 | public void setMessage(TranslateMessage message) { 28 | this.message = message; 29 | } 30 | 31 | public String getSubscription() { 32 | return subscription; 33 | } 34 | 35 | public void setSubscription(String subscription) { 36 | this.subscription = subscription; 37 | } 38 | } 39 | // [END getting_started_background_pub_sub_message] 40 | -------------------------------------------------------------------------------- /background/src/main/java/com/getstarted/background/objects/TranslateAttributes.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 Google LLC 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.getstarted.background.objects; 17 | 18 | // [START getting_started_background_translate_attributes] 19 | public class TranslateAttributes { 20 | private String sourceLang; 21 | private String targetLang; 22 | 23 | public String getSourceLang() { 24 | return sourceLang; 25 | } 26 | 27 | public void setSourceLang(String sourceLang) { 28 | this.sourceLang = sourceLang; 29 | } 30 | 31 | public String getTargetLang() { 32 | return targetLang; 33 | } 34 | 35 | public void setTargetLang(String targetLang) { 36 | this.targetLang = targetLang; 37 | } 38 | } 39 | // [END getting_started_background_translate_attributes] 40 | -------------------------------------------------------------------------------- /background/src/main/java/com/getstarted/background/objects/TranslateMessage.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 Google LLC 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.getstarted.background.objects; 17 | 18 | // [START getting_started_background_translate_message] 19 | public class TranslateMessage { 20 | public String data; 21 | public TranslateAttributes attributes; 22 | public String messageId; 23 | public String publishTime; 24 | public String translatedText; 25 | public String sourceLang = "en"; 26 | public String targetLang = "en"; 27 | 28 | public String getData() { 29 | return data; 30 | } 31 | 32 | public void setData(String data) { 33 | this.data = data; 34 | } 35 | 36 | public TranslateAttributes getAttributes() { 37 | return attributes; 38 | } 39 | 40 | public void setAttributes(TranslateAttributes attributes) { 41 | this.attributes = attributes; 42 | } 43 | 44 | public String getMessageId() { 45 | return messageId; 46 | } 47 | 48 | public void setMessageId(String messageId) { 49 | this.messageId = messageId; 50 | } 51 | 52 | public String getPublishTime() { 53 | return publishTime; 54 | } 55 | 56 | public void setPublishTime(String publishTime) { 57 | this.publishTime = publishTime; 58 | } 59 | 60 | public String getTranslatedText() { 61 | return translatedText; 62 | } 63 | 64 | public void setTranslatedText(String translatedText) { 65 | this.translatedText = translatedText; 66 | } 67 | 68 | public String getSourceLang() { 69 | return sourceLang; 70 | } 71 | 72 | public void setSourceLang(String sourceLang) { 73 | this.sourceLang = sourceLang; 74 | } 75 | 76 | public String getTargetLang() { 77 | return targetLang; 78 | } 79 | 80 | public void setTargetLang(String targetLang) { 81 | this.targetLang = targetLang; 82 | } 83 | } 84 | // [END getting_started_background_translate_message] 85 | -------------------------------------------------------------------------------- /background/src/main/webapp/base.jsp: -------------------------------------------------------------------------------- 1 | 16 | 17 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 18 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 19 | 20 | 21 | Background Processing - Java on Google Cloud Platform 22 | 23 | 24 | 25 | 26 | 27 |

34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /background/src/main/webapp/form.jsp: -------------------------------------------------------------------------------- 1 | 16 | 17 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 18 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%> 19 |
20 |

21 | book 22 |

23 | 24 |
25 | 26 |
27 | 28 | 29 |
30 | 31 |
32 |

See language codes

33 | 34 | 35 |
36 |
37 | 38 | 39 |
40 | 41 | 42 |
43 |
44 | 45 | -------------------------------------------------------------------------------- /background/src/main/webapp/list.jsp: -------------------------------------------------------------------------------- 1 | 16 | 17 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 18 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 19 | 25 |
26 |

Translations

27 | 28 | 29 | Request translation 30 | 31 | 32 | 33 |

No translations found.

34 |
35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
TimestampMessageSource LanguageTarget LanguageTranslation
${message.publishTime}${fn:escapeXml(message.data)}${message.attributes.sourceLang}${message.attributes.targetLang}${fn:escapeXml(message.translatedText)}
54 | 55 | 60 | 61 |
62 |
63 |
64 | 65 | -------------------------------------------------------------------------------- /bookshelf-standard/2-structured-data/README.md: -------------------------------------------------------------------------------- 1 | mvn package appengine:deploymvn package appengine:deploymvn package appengine:deploy# Bookshelf App for Java on App Engine Standard Tutorial 2 | ## Structured Data 3 | 4 | Contains the code for using Cloud Datastore and Cloud SQL v2. 5 | 6 | This is part of a [Bookshelf tutorial](https://cloud.google.com/java/getting-started/tutorial-app). 7 | 8 | Most users can get this running by updating the parameters in `pom.xml`. 9 | 10 | ### Running Locally 11 | 12 | mvn -Plocal clean appengine:devserver 13 | 14 | ### Deploying to App Engine Standard 15 | 16 | * In the `pom.xml`, update the [App Engine Maven Plugin](https://cloud.google.com/appengine/docs/standard/java/tools/maven-reference) 17 | with your Google Cloud Project Id: 18 | 19 | ``` 20 | 21 | com.google.cloud.tools 22 | appengine-maven-plugin 23 | 2.3.0 24 | 25 | GCLOUD_CONFIG 26 | bookshelf 27 | 28 | 29 | ``` 30 | 31 | * Deploy your App 32 | 33 | mvn package appengine:deploy 34 | 35 | Visit it at http://bookshelf..appspot.com 36 | -------------------------------------------------------------------------------- /bookshelf-standard/2-structured-data/jenkins.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2017 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # Fail on non-zero return and print command to stdout 18 | set -xe 19 | 20 | # Jenkins provides values for GOOGLE_CLOUD_PROJECT and GOOGLE_VERSION_ID 21 | 22 | # Make sure it works on GAE7 23 | 24 | # Deploy and run selenium tests 25 | mvn clean appengine:update verify \ 26 | -Pselenium \ 27 | -Dappengine.appId="${GOOGLE_CLOUD_PROJECT}" \ 28 | -Dappengine.version="${GOOGLE_VERSION_ID}" \ 29 | -Dappengine.additionalParams="--service_account_json_key_file=${GOOGLE_APPLICATION_CREDENTIALS}" 30 | 31 | 32 | # Make sure it deploys on GAE8 33 | 34 | FILE_PATH=src/main/webapp/WEB-INF/appengine-web.xml 35 | sed -i'.bak' '/java8' "${FILE_PATH}" 36 | # Restore the backup after we're done 37 | trap 'mv "${FILE_PATH}"{.bak,}' EXIT 38 | # Deploy and run selenium tests 39 | mvn clean appengine:update verify \ 40 | -Pselenium \ 41 | -Dappengine.appId="${GOOGLE_CLOUD_PROJECT}" \ 42 | -Dappengine.version="${GOOGLE_VERSION_ID}" \ 43 | -Dappengine.additionalParams="--service_account_json_key_file=${GOOGLE_APPLICATION_CREDENTIALS}" 44 | 45 | -------------------------------------------------------------------------------- /bookshelf-standard/2-structured-data/src/main/java/com/example/getstarted/basicactions/CreateBookServlet.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.example.getstarted.basicactions; 17 | 18 | import com.example.getstarted.daos.BookDao; 19 | import com.example.getstarted.objects.Book; 20 | import java.io.IOException; 21 | import javax.servlet.ServletException; 22 | import javax.servlet.http.HttpServlet; 23 | import javax.servlet.http.HttpServletRequest; 24 | import javax.servlet.http.HttpServletResponse; 25 | 26 | // [START example] 27 | @SuppressWarnings("serial") 28 | public class CreateBookServlet extends HttpServlet { 29 | 30 | // [START setup] 31 | @Override 32 | public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, 33 | IOException { 34 | req.setAttribute("action", "Add"); // Part of the Header in form.jsp 35 | req.setAttribute("destination", "create"); // The urlPattern to invoke (this Servlet) 36 | req.setAttribute("page", "form"); // Tells base.jsp to include form.jsp 37 | req.getRequestDispatcher("/base.jsp").forward(req, resp); 38 | } 39 | // [END setup] 40 | 41 | // [START formpost] 42 | @Override 43 | public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, 44 | IOException { 45 | // [START bookBuilder] 46 | Book book = new Book.Builder() 47 | .author(req.getParameter("author")) // form parameter 48 | .description(req.getParameter("description")) 49 | .publishedDate(req.getParameter("publishedDate")) 50 | .title(req.getParameter("title")) 51 | .imageUrl(null) 52 | .build(); 53 | // [END bookBuilder] 54 | 55 | BookDao dao = (BookDao) this.getServletContext().getAttribute("dao"); 56 | try { 57 | Long id = dao.createBook(book); 58 | resp.sendRedirect("/read?id=" + id.toString()); // read what we just wrote 59 | } catch (Exception e) { 60 | throw new ServletException("Error creating book", e); 61 | } 62 | } 63 | // [END formpost] 64 | } 65 | // [END example] 66 | -------------------------------------------------------------------------------- /bookshelf-standard/2-structured-data/src/main/java/com/example/getstarted/basicactions/DeleteBookServlet.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.example.getstarted.basicactions; 17 | 18 | import com.example.getstarted.daos.BookDao; 19 | import java.io.IOException; 20 | import javax.servlet.ServletException; 21 | import javax.servlet.http.HttpServlet; 22 | import javax.servlet.http.HttpServletRequest; 23 | import javax.servlet.http.HttpServletResponse; 24 | 25 | // [START example] 26 | @SuppressWarnings("serial") 27 | public class DeleteBookServlet extends HttpServlet { 28 | 29 | @Override 30 | public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, 31 | IOException { 32 | Long id = Long.decode(req.getParameter("id")); 33 | BookDao dao = (BookDao) this.getServletContext().getAttribute("dao"); 34 | try { 35 | dao.deleteBook(id); 36 | resp.sendRedirect("/books"); 37 | } catch (Exception e) { 38 | throw new ServletException("Error deleting book", e); 39 | } 40 | } 41 | } 42 | // [END example] 43 | -------------------------------------------------------------------------------- /bookshelf-standard/2-structured-data/src/main/java/com/example/getstarted/basicactions/ReadBookServlet.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.example.getstarted.basicactions; 17 | 18 | import com.example.getstarted.daos.BookDao; 19 | import com.example.getstarted.objects.Book; 20 | import java.io.IOException; 21 | import javax.servlet.ServletException; 22 | import javax.servlet.http.HttpServlet; 23 | import javax.servlet.http.HttpServletRequest; 24 | import javax.servlet.http.HttpServletResponse; 25 | 26 | // [START example] 27 | @SuppressWarnings("serial") 28 | public class ReadBookServlet extends HttpServlet { 29 | 30 | @Override 31 | public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, 32 | ServletException { 33 | Long id = Long.decode(req.getParameter("id")); 34 | BookDao dao = (BookDao) this.getServletContext().getAttribute("dao"); 35 | try { 36 | Book book = dao.readBook(id); 37 | req.setAttribute("book", book); 38 | req.setAttribute("page", "view"); 39 | req.getRequestDispatcher("/base.jsp").forward(req, resp); 40 | } catch (Exception e) { 41 | throw new ServletException("Error reading book", e); 42 | } 43 | } 44 | } 45 | // [END example] 46 | -------------------------------------------------------------------------------- /bookshelf-standard/2-structured-data/src/main/java/com/example/getstarted/daos/BookDao.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.example.getstarted.daos; 17 | 18 | import com.example.getstarted.objects.Book; 19 | import com.example.getstarted.objects.Result; 20 | import java.sql.SQLException; 21 | 22 | // [START example] 23 | public interface BookDao { 24 | Long createBook(Book book) throws SQLException; 25 | 26 | Book readBook(Long bookId) throws SQLException; 27 | 28 | void updateBook(Book book) throws SQLException; 29 | 30 | void deleteBook(Long bookId) throws SQLException; 31 | 32 | Result listBooks(String startCursor) throws SQLException; 33 | } 34 | // [END example] 35 | -------------------------------------------------------------------------------- /bookshelf-standard/2-structured-data/src/main/java/com/example/getstarted/objects/Result.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.example.getstarted.objects; 17 | 18 | import java.util.List; 19 | 20 | // [START example] 21 | public class Result { 22 | 23 | public String cursor; 24 | public List result; 25 | 26 | public Result(List result, String cursor) { 27 | this.result = result; 28 | this.cursor = cursor; 29 | } 30 | 31 | public Result(List result) { 32 | this.result = result; 33 | this.cursor = null; 34 | } 35 | } 36 | // [END example] 37 | -------------------------------------------------------------------------------- /bookshelf-standard/2-structured-data/src/main/webapp/WEB-INF/appengine-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | true 19 | true 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | true 35 | 36 | 37 | -------------------------------------------------------------------------------- /bookshelf-standard/2-structured-data/src/main/webapp/WEB-INF/logging.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleCloudPlatform/getting-started-java/faece5ea8b3634e9229858ff90e95a096193ada5/bookshelf-standard/2-structured-data/src/main/webapp/WEB-INF/logging.properties -------------------------------------------------------------------------------- /bookshelf-standard/2-structured-data/src/main/webapp/base.jsp: -------------------------------------------------------------------------------- 1 | 16 | 17 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 18 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 19 | 20 | 21 | Bookshelf - Java on Google Cloud Platform 22 | 23 | 24 | 25 | 26 | 27 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /bookshelf-standard/2-structured-data/src/main/webapp/form.jsp: -------------------------------------------------------------------------------- 1 | 16 | 17 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 18 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%> 19 |
20 |

21 | book 22 |

23 | 24 |
25 | 26 |
27 | 28 | 29 |
30 | 31 |
32 | 33 | 34 |
35 | 36 |
37 | 38 | 39 |
40 | 41 |
42 | 43 | 44 |
45 | 46 |
47 | 48 | 49 |
50 | 51 | 56 | 57 | 58 |
59 |
60 | 61 | -------------------------------------------------------------------------------- /bookshelf-standard/2-structured-data/src/main/webapp/list.jsp: -------------------------------------------------------------------------------- 1 | 16 | 17 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 18 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 19 |
20 |

Books

21 | 22 | 23 | Add book 24 | 25 | 26 | 27 |

No books found

28 |
29 | 30 | 31 | 42 | 43 | 44 | 49 | 50 | 51 |
52 |
53 | 54 | -------------------------------------------------------------------------------- /bookshelf-standard/2-structured-data/src/main/webapp/view.jsp: -------------------------------------------------------------------------------- 1 | 16 | 17 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 18 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 19 |
20 |

Book

21 | 31 | 32 |
33 |
34 | 35 |
36 |
37 |

38 | ${fn:escapeXml(book.title)} 39 | ${fn:escapeXml(book.publishedDate)} 40 |

41 |
By ${fn:escapeXml(not empty book.author?book.author:'Unknown')}
42 |

${fn:escapeXml(book.description)}

43 | Added by 44 | ${fn:escapeXml(not empty book.createdBy?book.createdBy:'Anonymous')} 45 |
46 |
47 |
48 | 49 | -------------------------------------------------------------------------------- /bookshelf-standard/3-binary-data/README.md: -------------------------------------------------------------------------------- 1 | # Bookshelf App for Java on App Engine Standard Tutorial 2 | ## Binary Data 3 | 4 | Contains the code for using Cloud Datastore and Cloud SQL v2. 5 | 6 | This is part of a [Bookshelf tutorial](https://cloud.google.com/java/getting-started/tutorial-app). 7 | 8 | Most users can get this running by updating the parameters in `pom.xml`. You'll 9 | also need to [create a bucket][create-bucket] in Google Cloud Storage, referred 10 | to below as `MY-BUCKET`. 11 | 12 | [create-bucket]: https://cloud.google.com/storage/docs/creating-buckets 13 | 14 | ### Running Locally 15 | 16 | mvn -Plocal clean appengine:devserver -Dbookshelf.bucket=MY-BUCKET 17 | 18 | **Note**: If you run into an error about `Invalid Credentials`, you may have to 19 | run: 20 | 21 | gcloud auth application-default login 22 | 23 | ### Deploying to App Engine Standard 24 | 25 | * In the `pom.xml`, update the [App Engine Maven Plugin](https://cloud.google.com/appengine/docs/standard/java/tools/maven-reference) 26 | with your Google Cloud Project Id: 27 | 28 | ``` 29 | 30 | com.google.cloud.tools 31 | appengine-maven-plugin 32 | 2.3.0 33 | 34 | GCLOUD_CONFIG 35 | bookshelf 36 | 37 | 38 | ``` 39 | 40 | * Deploy your App 41 | 42 | mvn package appengine:deploy \ 43 | -Dbookshelf.bucket=MY-BUCKET 44 | 45 | Visit it at http://bookshelf..appspot.com 46 | -------------------------------------------------------------------------------- /bookshelf-standard/3-binary-data/jenkins.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2017 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # Fail on non-zero return and print command to stdout 18 | set -xe 19 | 20 | # Jenkins provides values for GOOGLE_PROJECT_ID and GOOGLE_VERSION_ID 21 | 22 | # Make sure it works on GAE7 23 | 24 | # Deploy and run selenium tests 25 | mvn clean appengine:update verify \ 26 | -Pselenium \ 27 | -Dappengine.appId="${GOOGLE_PROJECT_ID}" \ 28 | -Dappengine.version="${GOOGLE_VERSION_ID}" \ 29 | -Dbookshelf.bucket="${GCS_BUCKET}" \ 30 | -Dappengine.additionalParams="--service_account_json_key_file=${GOOGLE_APPLICATION_CREDENTIALS}" 31 | 32 | 33 | # Make sure it deploys on GAE8 34 | 35 | FILE_PATH=src/main/webapp/WEB-INF/appengine-web.xml 36 | sed -i'.bak' '/java8' "${FILE_PATH}" 37 | # Restore the backup after we're done 38 | trap 'mv "${FILE_PATH}"{.bak,}' EXIT 39 | # Deploy and run selenium tests 40 | mvn clean appengine:update verify \ 41 | -Pselenium \ 42 | -Dappengine.appId="${GOOGLE_PROJECT_ID}" \ 43 | -Dappengine.version="${GOOGLE_VERSION_ID}" \ 44 | -Dbookshelf.bucket="${GCS_BUCKET}" \ 45 | -Dappengine.additionalParams="--service_account_json_key_file=${GOOGLE_APPLICATION_CREDENTIALS}" 46 | 47 | -------------------------------------------------------------------------------- /bookshelf-standard/3-binary-data/src/main/java/com/example/getstarted/basicactions/DeleteBookServlet.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.example.getstarted.basicactions; 17 | 18 | import com.example.getstarted.daos.BookDao; 19 | import java.io.IOException; 20 | import javax.servlet.ServletException; 21 | import javax.servlet.http.HttpServlet; 22 | import javax.servlet.http.HttpServletRequest; 23 | import javax.servlet.http.HttpServletResponse; 24 | 25 | // [START example] 26 | @SuppressWarnings("serial") 27 | public class DeleteBookServlet extends HttpServlet { 28 | 29 | @Override 30 | public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, 31 | IOException { 32 | Long id = Long.decode(req.getParameter("id")); 33 | BookDao dao = (BookDao) this.getServletContext().getAttribute("dao"); 34 | try { 35 | dao.deleteBook(id); 36 | resp.sendRedirect("/books"); 37 | } catch (Exception e) { 38 | throw new ServletException("Error deleting book", e); 39 | } 40 | } 41 | } 42 | // [END example] 43 | -------------------------------------------------------------------------------- /bookshelf-standard/3-binary-data/src/main/java/com/example/getstarted/basicactions/ReadBookServlet.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.example.getstarted.basicactions; 17 | 18 | import com.example.getstarted.daos.BookDao; 19 | import com.example.getstarted.objects.Book; 20 | import java.io.IOException; 21 | import javax.servlet.ServletException; 22 | import javax.servlet.http.HttpServlet; 23 | import javax.servlet.http.HttpServletRequest; 24 | import javax.servlet.http.HttpServletResponse; 25 | 26 | // [START example] 27 | @SuppressWarnings("serial") 28 | public class ReadBookServlet extends HttpServlet { 29 | 30 | @Override 31 | public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, 32 | ServletException { 33 | Long id = Long.decode(req.getParameter("id")); 34 | BookDao dao = (BookDao) this.getServletContext().getAttribute("dao"); 35 | try { 36 | Book book = dao.readBook(id); 37 | req.setAttribute("book", book); 38 | req.setAttribute("page", "view"); 39 | req.getRequestDispatcher("/base.jsp").forward(req, resp); 40 | } catch (Exception e) { 41 | throw new ServletException("Error reading book", e); 42 | } 43 | } 44 | } 45 | // [END example] 46 | -------------------------------------------------------------------------------- /bookshelf-standard/3-binary-data/src/main/java/com/example/getstarted/daos/BookDao.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.example.getstarted.daos; 17 | 18 | import com.example.getstarted.objects.Book; 19 | import com.example.getstarted.objects.Result; 20 | import java.sql.SQLException; 21 | 22 | // [START example] 23 | public interface BookDao { 24 | Long createBook(Book book) throws SQLException; 25 | 26 | Book readBook(Long bookId) throws SQLException; 27 | 28 | void updateBook(Book book) throws SQLException; 29 | 30 | void deleteBook(Long bookId) throws SQLException; 31 | 32 | Result listBooks(String startCursor) throws SQLException; 33 | } 34 | // [END example] 35 | -------------------------------------------------------------------------------- /bookshelf-standard/3-binary-data/src/main/java/com/example/getstarted/objects/Result.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.example.getstarted.objects; 17 | 18 | import java.util.List; 19 | 20 | // [START example] 21 | public class Result { 22 | 23 | public String cursor; 24 | public List result; 25 | 26 | public Result(List result, String cursor) { 27 | this.result = result; 28 | this.cursor = cursor; 29 | } 30 | 31 | public Result(List result) { 32 | this.result = result; 33 | this.cursor = null; 34 | } 35 | } 36 | // [END example] 37 | -------------------------------------------------------------------------------- /bookshelf-standard/3-binary-data/src/main/webapp/WEB-INF/appengine-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | true 19 | true 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | true 35 | 36 | 37 | -------------------------------------------------------------------------------- /bookshelf-standard/3-binary-data/src/main/webapp/WEB-INF/logging.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleCloudPlatform/getting-started-java/faece5ea8b3634e9229858ff90e95a096193ada5/bookshelf-standard/3-binary-data/src/main/webapp/WEB-INF/logging.properties -------------------------------------------------------------------------------- /bookshelf-standard/3-binary-data/src/main/webapp/base.jsp: -------------------------------------------------------------------------------- 1 | 16 | 17 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 18 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 19 | 20 | 21 | Bookshelf - Java on Google Cloud Platform 22 | 23 | 24 | 25 | 26 | 27 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /bookshelf-standard/3-binary-data/src/main/webapp/form.jsp: -------------------------------------------------------------------------------- 1 | 16 | 17 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 18 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%> 19 |
20 |

21 | book 22 |

23 | 24 |
25 | 26 |
27 | 28 | 29 |
30 | 31 |
32 | 33 | 34 |
35 | 36 |
37 | 38 | 39 |
40 | 41 |
42 | 43 | 44 |
45 | 46 |
47 | 48 | 49 |
50 | 51 | 56 | 57 | 58 |
59 |
60 | 61 | -------------------------------------------------------------------------------- /bookshelf-standard/3-binary-data/src/main/webapp/list.jsp: -------------------------------------------------------------------------------- 1 | 16 | 17 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 18 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 19 |
20 |

Books

21 | 22 | 23 | Add book 24 | 25 | 26 | 27 |

No books found

28 |
29 | 30 | 31 | 42 | 43 | 44 | 49 | 50 | 51 |
52 |
53 | 54 | -------------------------------------------------------------------------------- /bookshelf-standard/3-binary-data/src/main/webapp/view.jsp: -------------------------------------------------------------------------------- 1 | 16 | 17 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 18 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 19 |
20 |

Book

21 | 31 | 32 |
33 |
34 | 35 |
36 |
37 |

38 | ${fn:escapeXml(book.title)} 39 | ${fn:escapeXml(book.publishedDate)} 40 |

41 |
By ${fn:escapeXml(not empty book.author?book.author:'Unknown')}
42 |

${fn:escapeXml(book.description)}

43 | Added by 44 | ${fn:escapeXml(not empty book.createdBy?book.createdBy:'Anonymous')} 45 |
46 |
47 |
48 | 49 | -------------------------------------------------------------------------------- /bookshelf-standard/4-auth/README.md: -------------------------------------------------------------------------------- 1 | # Bookshelf App for Java on App Engine Standard Tutorial 2 | ## Auth 3 | 4 | Contains the code for using Cloud Datastore and Cloud SQL v2. 5 | 6 | This is part of a [Bookshelf tutorial](https://cloud.google.com/java/getting-started/tutorial-app). 7 | 8 | Most users can get this running by updating the parameters in `pom.xml`. You'll 9 | also need to [create a bucket][create-bucket] in Google Cloud Storage, referred 10 | to below as `MY-BUCKET`. 11 | 12 | [create-bucket]: https://cloud.google.com/storage/docs/creating-buckets 13 | 14 | ### Running Locally 15 | 16 | mvn -Plocal clean appengine:devserver -Dbookshelf.bucket=MY-BUCKET 17 | 18 | **Note**: If you run into an error about `Invalid Credentials`, you may have to run: 19 | 20 | gcloud auth application-default login 21 | 22 | ### Deploying to App Engine Standard 23 | 24 | * In the `pom.xml`, update the [App Engine Maven Plugin](https://cloud.google.com/appengine/docs/standard/java/tools/maven-reference) 25 | with your Google Cloud Project Id: 26 | 27 | ``` 28 | 29 | com.google.cloud.tools 30 | appengine-maven-plugin 31 | 2.3.0 32 | 33 | GCLOUD_CONFIG 34 | bookshelf 35 | 36 | 37 | ``` 38 | 39 | * Deploy your App 40 | 41 | mvn clean appengine appengine:deploy \ 42 | -Dbookshelf.bucket=MY-BUCKET 43 | 44 | Visit it at http://bookshelf..appspot.com 45 | -------------------------------------------------------------------------------- /bookshelf-standard/4-auth/jenkins.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2017 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # Fail on non-zero return and print command to stdout 18 | set -xe 19 | 20 | # Jenkins provides values for GOOGLE_PROJECT_ID and GOOGLE_VERSION_ID 21 | 22 | # Make sure it works on GAE7 23 | 24 | # Deploy and run selenium tests 25 | mvn clean appengine:update verify \ 26 | -Pselenium \ 27 | -Dappengine.appId="${GOOGLE_PROJECT_ID}" \ 28 | -Dappengine.version="${GOOGLE_VERSION_ID}" \ 29 | -Dbookshelf.bucket="${GCS_BUCKET}" \ 30 | -Dappengine.additionalParams="--service_account_json_key_file=${GOOGLE_APPLICATION_CREDENTIALS}" 31 | 32 | 33 | # Make sure it deploys on GAE8 34 | 35 | FILE_PATH=src/main/webapp/WEB-INF/appengine-web.xml 36 | sed -i'.bak' '/java8' "${FILE_PATH}" 37 | # Restore the backup after we're done 38 | trap 'mv "${FILE_PATH}"{.bak,}' EXIT 39 | # Deploy and run selenium tests 40 | mvn clean appengine:update verify \ 41 | -Pselenium \ 42 | -Dappengine.appId="${GOOGLE_PROJECT_ID}" \ 43 | -Dappengine.version="${GOOGLE_VERSION_ID}" \ 44 | -Dbookshelf.bucket="${GCS_BUCKET}" \ 45 | -Dappengine.additionalParams="--service_account_json_key_file=${GOOGLE_APPLICATION_CREDENTIALS}" 46 | 47 | -------------------------------------------------------------------------------- /bookshelf-standard/4-auth/src/main/java/com/example/getstarted/auth/ListByUserFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.getstarted.auth; 18 | 19 | import com.google.appengine.api.users.UserService; 20 | import com.google.appengine.api.users.UserServiceFactory; 21 | import java.io.IOException; 22 | import javax.servlet.Filter; 23 | import javax.servlet.FilterChain; 24 | import javax.servlet.FilterConfig; 25 | import javax.servlet.ServletException; 26 | import javax.servlet.ServletRequest; 27 | import javax.servlet.ServletResponse; 28 | import javax.servlet.http.HttpServletRequest; 29 | import javax.servlet.http.HttpServletResponse; 30 | 31 | public class ListByUserFilter implements Filter { 32 | 33 | @Override 34 | public void init(FilterConfig config) throws ServletException { 35 | } 36 | 37 | @Override 38 | public void doFilter(ServletRequest servletReq, ServletResponse servletResp, FilterChain chain) 39 | throws IOException, ServletException { 40 | HttpServletRequest req = (HttpServletRequest) servletReq; 41 | HttpServletResponse resp = (HttpServletResponse) servletResp; 42 | 43 | UserService userService = UserServiceFactory.getUserService(); 44 | if (userService.isUserLoggedIn()) { 45 | chain.doFilter(servletReq, servletResp); 46 | } else { 47 | req.getSession().setAttribute("loginDestination", "/books/mine"); 48 | resp.sendRedirect(userService.createLoginURL("/login")); 49 | } 50 | } 51 | 52 | @Override 53 | public void destroy() { 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /bookshelf-standard/4-auth/src/main/java/com/example/getstarted/auth/LoginServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.getstarted.auth; 18 | 19 | import com.google.appengine.api.users.User; 20 | import com.google.appengine.api.users.UserService; 21 | import com.google.appengine.api.users.UserServiceFactory; 22 | import java.io.IOException; 23 | import javax.servlet.ServletException; 24 | import javax.servlet.http.HttpServlet; 25 | import javax.servlet.http.HttpServletRequest; 26 | import javax.servlet.http.HttpServletResponse; 27 | 28 | // [START example] 29 | @SuppressWarnings("serial") 30 | public class LoginServlet extends HttpServlet { 31 | @Override 32 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) 33 | throws IOException, ServletException { 34 | 35 | UserService userService = UserServiceFactory.getUserService(); 36 | if (userService.isUserLoggedIn()) { 37 | // Save the relevant profile info and store it in the session. 38 | User user = userService.getCurrentUser(); 39 | req.getSession().setAttribute("userEmail", user.getEmail()); 40 | req.getSession().setAttribute("userId", user.getUserId()); 41 | 42 | String destination = (String) req.getSession().getAttribute("loginDestination"); 43 | if (destination == null) { 44 | destination = "/books"; 45 | } 46 | 47 | resp.sendRedirect(destination); 48 | } else { 49 | resp.sendRedirect(userService.createLoginURL("/login")); 50 | } 51 | } 52 | } 53 | // [END example] 54 | -------------------------------------------------------------------------------- /bookshelf-standard/4-auth/src/main/java/com/example/getstarted/auth/LogoutFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.getstarted.auth; 18 | 19 | import com.google.appengine.api.users.UserService; 20 | import com.google.appengine.api.users.UserServiceFactory; 21 | import java.io.IOException; 22 | import javax.servlet.Filter; 23 | import javax.servlet.FilterChain; 24 | import javax.servlet.FilterConfig; 25 | import javax.servlet.ServletException; 26 | import javax.servlet.ServletRequest; 27 | import javax.servlet.ServletResponse; 28 | import javax.servlet.http.HttpServletRequest; 29 | import javax.servlet.http.HttpServletResponse; 30 | 31 | // [START init] 32 | public class LogoutFilter implements Filter { 33 | // [END init] 34 | 35 | @Override 36 | public void init(FilterConfig config) throws ServletException { 37 | } 38 | 39 | @Override 40 | public void doFilter(ServletRequest servletReq, ServletResponse servletResp, FilterChain chain) 41 | throws IOException, ServletException { 42 | HttpServletRequest req = (HttpServletRequest) servletReq; 43 | HttpServletResponse resp = (HttpServletResponse) servletResp; 44 | String path = req.getRequestURI(); 45 | 46 | chain.doFilter(servletReq, servletResp); 47 | 48 | UserService userService = UserServiceFactory.getUserService(); 49 | if (userService.isUserLoggedIn()) { 50 | resp.sendRedirect(userService.createLogoutURL("/logout")); 51 | } else if (path.startsWith("/logout")) { 52 | resp.sendRedirect("/books"); 53 | } 54 | } 55 | 56 | @Override 57 | public void destroy() { 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /bookshelf-standard/4-auth/src/main/java/com/example/getstarted/auth/LogoutServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.getstarted.auth; 18 | 19 | import java.io.IOException; 20 | import javax.servlet.ServletException; 21 | import javax.servlet.http.HttpServlet; 22 | import javax.servlet.http.HttpServletRequest; 23 | import javax.servlet.http.HttpServletResponse; 24 | import javax.servlet.http.HttpSession; 25 | 26 | // [START example] 27 | @SuppressWarnings("serial") 28 | public class LogoutServlet extends HttpServlet { 29 | 30 | @Override 31 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) 32 | throws IOException, ServletException { 33 | // you can also make an authenticated request to logout, but here we choose to 34 | // simply delete the session variables for simplicity 35 | HttpSession session = req.getSession(false); 36 | if (session != null) { 37 | session.invalidate(); 38 | } 39 | // rebuild session 40 | req.getSession(); 41 | } 42 | } 43 | // [END example] 44 | -------------------------------------------------------------------------------- /bookshelf-standard/4-auth/src/main/java/com/example/getstarted/basicactions/DeleteBookServlet.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.example.getstarted.basicactions; 17 | 18 | import com.example.getstarted.daos.BookDao; 19 | import java.io.IOException; 20 | import javax.servlet.ServletException; 21 | import javax.servlet.http.HttpServlet; 22 | import javax.servlet.http.HttpServletRequest; 23 | import javax.servlet.http.HttpServletResponse; 24 | 25 | // [START example] 26 | @SuppressWarnings("serial") 27 | public class DeleteBookServlet extends HttpServlet { 28 | 29 | @Override 30 | public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, 31 | IOException { 32 | Long id = Long.decode(req.getParameter("id")); 33 | BookDao dao = (BookDao) this.getServletContext().getAttribute("dao"); 34 | try { 35 | dao.deleteBook(id); 36 | resp.sendRedirect("/books"); 37 | } catch (Exception e) { 38 | throw new ServletException("Error deleting book", e); 39 | } 40 | } 41 | } 42 | // [END example] 43 | -------------------------------------------------------------------------------- /bookshelf-standard/4-auth/src/main/java/com/example/getstarted/basicactions/ListByUserServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.getstarted.basicactions; 18 | 19 | import com.example.getstarted.daos.BookDao; 20 | import com.example.getstarted.objects.Book; 21 | import com.example.getstarted.objects.Result; 22 | import java.io.IOException; 23 | import java.util.List; 24 | import javax.servlet.ServletException; 25 | import javax.servlet.http.HttpServlet; 26 | import javax.servlet.http.HttpServletRequest; 27 | import javax.servlet.http.HttpServletResponse; 28 | 29 | // [START example] 30 | @SuppressWarnings("serial") 31 | public class ListByUserServlet extends HttpServlet { 32 | 33 | @Override 34 | public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, 35 | ServletException { 36 | BookDao dao = (BookDao) this.getServletContext().getAttribute("dao"); 37 | String startCursor = req.getParameter("cursor"); 38 | List books = null; 39 | String endCursor = null; 40 | try { 41 | Result result = 42 | dao.listBooksByUser((String) req.getSession().getAttribute("userId"), startCursor); 43 | books = result.result; 44 | endCursor = result.cursor; 45 | } catch (Exception e) { 46 | throw new ServletException("Error listing books", e); 47 | } 48 | req.getSession().getServletContext().setAttribute("books", books); 49 | StringBuilder bookNames = new StringBuilder(); 50 | for (Book book : books) { 51 | bookNames.append(book.getTitle() + " "); 52 | } 53 | req.getSession().setAttribute("cursor", endCursor); 54 | req.getSession().setAttribute("page", "list"); 55 | req.getRequestDispatcher("/base.jsp").forward(req, resp); 56 | } 57 | } 58 | // [END example] 59 | -------------------------------------------------------------------------------- /bookshelf-standard/4-auth/src/main/java/com/example/getstarted/basicactions/ReadBookServlet.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.example.getstarted.basicactions; 17 | 18 | import com.example.getstarted.daos.BookDao; 19 | import com.example.getstarted.objects.Book; 20 | import java.io.IOException; 21 | import javax.servlet.ServletException; 22 | import javax.servlet.http.HttpServlet; 23 | import javax.servlet.http.HttpServletRequest; 24 | import javax.servlet.http.HttpServletResponse; 25 | 26 | // [START example] 27 | @SuppressWarnings("serial") 28 | public class ReadBookServlet extends HttpServlet { 29 | 30 | @Override 31 | public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, 32 | ServletException { 33 | Long id = Long.decode(req.getParameter("id")); 34 | BookDao dao = (BookDao) this.getServletContext().getAttribute("dao"); 35 | try { 36 | Book book = dao.readBook(id); 37 | req.setAttribute("book", book); 38 | req.setAttribute("page", "view"); 39 | req.getRequestDispatcher("/base.jsp").forward(req, resp); 40 | } catch (Exception e) { 41 | throw new ServletException("Error reading book", e); 42 | } 43 | } 44 | } 45 | // [END example] 46 | -------------------------------------------------------------------------------- /bookshelf-standard/4-auth/src/main/java/com/example/getstarted/daos/BookDao.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.example.getstarted.daos; 17 | 18 | import com.example.getstarted.objects.Book; 19 | import com.example.getstarted.objects.Result; 20 | import java.sql.SQLException; 21 | 22 | // [START example] 23 | public interface BookDao { 24 | Long createBook(Book book) throws SQLException; 25 | 26 | Book readBook(Long bookId) throws SQLException; 27 | 28 | void updateBook(Book book) throws SQLException; 29 | 30 | void deleteBook(Long bookId) throws SQLException; 31 | 32 | Result listBooks(String startCursor) throws SQLException; 33 | 34 | Result listBooksByUser(String userId, String startCursor) throws SQLException; 35 | } 36 | // [END example] 37 | -------------------------------------------------------------------------------- /bookshelf-standard/4-auth/src/main/java/com/example/getstarted/objects/Result.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.example.getstarted.objects; 17 | 18 | import java.util.List; 19 | 20 | // [START example] 21 | public class Result { 22 | 23 | public String cursor; 24 | public List result; 25 | 26 | public Result(List result, String cursor) { 27 | this.result = result; 28 | this.cursor = cursor; 29 | } 30 | 31 | public Result(List result) { 32 | this.result = result; 33 | this.cursor = null; 34 | } 35 | } 36 | // [END example] 37 | -------------------------------------------------------------------------------- /bookshelf-standard/4-auth/src/main/webapp/WEB-INF/appengine-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | true 19 | true 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | true 35 | 36 | 37 | -------------------------------------------------------------------------------- /bookshelf-standard/4-auth/src/main/webapp/WEB-INF/datastore-indexes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /bookshelf-standard/4-auth/src/main/webapp/WEB-INF/logging.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleCloudPlatform/getting-started-java/faece5ea8b3634e9229858ff90e95a096193ada5/bookshelf-standard/4-auth/src/main/webapp/WEB-INF/logging.properties -------------------------------------------------------------------------------- /bookshelf-standard/4-auth/src/main/webapp/base.jsp: -------------------------------------------------------------------------------- 1 | 16 | 17 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 18 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 19 | 20 | 21 | Bookshelf - Java on Google Cloud Platform 22 | 23 | 24 | 25 | 26 | 27 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /bookshelf-standard/4-auth/src/main/webapp/form.jsp: -------------------------------------------------------------------------------- 1 | 16 | 17 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 18 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%> 19 |
20 |

21 | book 22 |

23 | 24 |
25 | 26 |
27 | 28 | 29 |
30 | 31 |
32 | 33 | 34 |
35 | 36 |
37 | 38 | 39 |
40 | 41 |
42 | 43 | 44 |
45 | 46 |
47 | 48 | 49 |
50 | 51 | 56 | 57 | 58 |
59 |
60 | 61 | -------------------------------------------------------------------------------- /bookshelf-standard/4-auth/src/main/webapp/list.jsp: -------------------------------------------------------------------------------- 1 | 16 | 17 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 18 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 19 |
20 |

Books

21 | 22 | 23 | Add book 24 | 25 | 26 | 27 |

No books found

28 |
29 | 30 | 31 | 42 | 43 | 44 | 49 | 50 | 51 |
52 |
53 | 54 | -------------------------------------------------------------------------------- /bookshelf-standard/4-auth/src/main/webapp/view.jsp: -------------------------------------------------------------------------------- 1 | 16 | 17 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 18 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 19 |
20 |

Book

21 | 31 | 32 |
33 |
34 | 35 |
36 |
37 |

38 | ${fn:escapeXml(book.title)} 39 | ${fn:escapeXml(book.publishedDate)} 40 |

41 |
By ${fn:escapeXml(not empty book.author?book.author:'Unknown')}
42 |

${fn:escapeXml(book.description)}

43 | Added by 44 | ${fn:escapeXml(not empty book.createdBy?book.createdBy:'Anonymous')} 45 |
46 |
47 |
48 | 49 | -------------------------------------------------------------------------------- /bookshelf-standard/5-logging/README.md: -------------------------------------------------------------------------------- 1 | # Bookshelf App for Java on App Engine Standard Tutorial 2 | ## Logging 3 | 4 | Contains the code for using Cloud Datastore and Cloud SQL v2. 5 | 6 | This is part of a [Bookshelf tutorial](https://cloud.google.com/java/getting-started/tutorial-app). 7 | 8 | Most users can get this running by updating the parameters in `pom.xml`. You'll 9 | also need to [create a bucket][create-bucket] in Google Cloud Storage, referred 10 | to below as `MY-BUCKET`. 11 | 12 | [create-bucket]: https://cloud.google.com/storage/docs/creating-buckets 13 | 14 | ### Running Locally 15 | 16 | mvn -Plocal clean appengine:devserver -Dbookshelf.bucket=MY-BUCKET 17 | 18 | **Note**: If you run into an error about `Invalid Credentials`, you may have to run: 19 | 20 | gcloud auth application-default login 21 | 22 | ### Deploying to App Engine Standard 23 | 24 | * In the `pom.xml`, update the [App Engine Maven Plugin](https://cloud.google.com/appengine/docs/standard/java/tools/maven-reference) 25 | with your Google Cloud Project Id: 26 | 27 | ``` 28 | 29 | com.google.cloud.tools 30 | appengine-maven-plugin 31 | 2.3.0 32 | 33 | GCLOUD_CONFIG 34 | bookshelf 35 | 36 | 37 | ``` 38 | 39 | * Deploy your App 40 | 41 | mvn package appengine:deploy \ 42 | -Dbookshelf.bucket=MY-BUCKET 43 | 44 | Visit it at http://bookshelf..appspot.com 45 | -------------------------------------------------------------------------------- /bookshelf-standard/5-logging/jenkins.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2017 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # Fail on non-zero return and print command to stdout 18 | set -xe 19 | 20 | # Jenkins provides values for GOOGLE_PROJECT_ID and GOOGLE_VERSION_ID 21 | 22 | # Make sure it works on GAE7 23 | 24 | # Deploy and run selenium tests 25 | mvn clean appengine:update verify \ 26 | -Pselenium \ 27 | -Dappengine.appId="${GOOGLE_PROJECT_ID}" \ 28 | -Dappengine.version="${GOOGLE_VERSION_ID}" \ 29 | -Dbookshelf.bucket="${GCS_BUCKET}" \ 30 | -Dappengine.additionalParams="--service_account_json_key_file=${GOOGLE_APPLICATION_CREDENTIALS}" 31 | 32 | 33 | # Make sure it deploys on GAE8 34 | 35 | FILE_PATH=src/main/webapp/WEB-INF/appengine-web.xml 36 | sed -i'.bak' '/java8' "${FILE_PATH}" 37 | # Restore the backup after we're done 38 | trap 'mv "${FILE_PATH}"{.bak,}' EXIT 39 | # Deploy and run selenium tests 40 | mvn clean appengine:update verify \ 41 | -Pselenium \ 42 | -Dappengine.appId="${GOOGLE_PROJECT_ID}" \ 43 | -Dappengine.version="${GOOGLE_VERSION_ID}" \ 44 | -Dbookshelf.bucket="${GCS_BUCKET}" \ 45 | -Dappengine.additionalParams="--service_account_json_key_file=${GOOGLE_APPLICATION_CREDENTIALS}" 46 | 47 | -------------------------------------------------------------------------------- /bookshelf-standard/5-logging/src/main/java/com/example/getstarted/auth/LoginServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.getstarted.auth; 18 | 19 | import com.google.appengine.api.users.User; 20 | import com.google.appengine.api.users.UserService; 21 | import com.google.appengine.api.users.UserServiceFactory; 22 | import java.io.IOException; 23 | import java.util.logging.Level; 24 | import java.util.logging.Logger; 25 | import javax.servlet.ServletException; 26 | import javax.servlet.http.HttpServlet; 27 | import javax.servlet.http.HttpServletRequest; 28 | import javax.servlet.http.HttpServletResponse; 29 | 30 | // [START example] 31 | @SuppressWarnings("serial") 32 | public class LoginServlet extends HttpServlet { 33 | 34 | private Logger logger = Logger.getLogger(this.getClass().getName()); 35 | 36 | @Override 37 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) 38 | throws IOException, ServletException { 39 | 40 | UserService userService = UserServiceFactory.getUserService(); 41 | if (userService.isUserLoggedIn()) { 42 | // Save the relevant profile info and store it in the session. 43 | User user = userService.getCurrentUser(); 44 | req.getSession().setAttribute("userEmail", user.getEmail()); 45 | req.getSession().setAttribute("userId", user.getUserId()); 46 | 47 | String destination = (String) req.getSession().getAttribute("loginDestination"); 48 | if (destination == null) { 49 | destination = "/books"; 50 | } 51 | 52 | logger.log(Level.INFO, "logging destination " + destination); 53 | resp.sendRedirect(destination); 54 | } else { 55 | resp.sendRedirect(userService.createLoginURL("/login")); 56 | logger.log(Level.INFO, "logging destination /login"); 57 | } 58 | } 59 | } 60 | // [END example] 61 | -------------------------------------------------------------------------------- /bookshelf-standard/5-logging/src/main/java/com/example/getstarted/auth/LogoutFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.getstarted.auth; 18 | 19 | import com.google.appengine.api.users.UserService; 20 | import com.google.appengine.api.users.UserServiceFactory; 21 | import java.io.IOException; 22 | import java.util.logging.Level; 23 | import java.util.logging.Logger; 24 | import javax.servlet.Filter; 25 | import javax.servlet.FilterChain; 26 | import javax.servlet.FilterConfig; 27 | import javax.servlet.ServletException; 28 | import javax.servlet.ServletRequest; 29 | import javax.servlet.ServletResponse; 30 | import javax.servlet.http.HttpServletRequest; 31 | import javax.servlet.http.HttpServletResponse; 32 | 33 | // [START init] 34 | public class LogoutFilter implements Filter { 35 | 36 | private static final Logger logger = Logger.getLogger(ListByUserFilter.class.getName()); 37 | // [END init] 38 | 39 | @Override 40 | public void init(FilterConfig config) throws ServletException { 41 | } 42 | 43 | @Override 44 | public void doFilter(ServletRequest servletReq, ServletResponse servletResp, FilterChain chain) 45 | throws IOException, ServletException { 46 | HttpServletRequest req = (HttpServletRequest) servletReq; 47 | HttpServletResponse resp = (HttpServletResponse) servletResp; 48 | String path = req.getRequestURI(); 49 | 50 | chain.doFilter(servletReq, servletResp); 51 | 52 | UserService userService = UserServiceFactory.getUserService(); 53 | if (userService.isUserLoggedIn()) { 54 | resp.sendRedirect(userService.createLogoutURL("/logout")); 55 | } else if (path.startsWith("/logout")) { 56 | resp.sendRedirect("/books"); 57 | } 58 | } 59 | 60 | @Override 61 | public void destroy() { 62 | logger.log(Level.INFO, "destroy called in LogoutFilter"); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /bookshelf-standard/5-logging/src/main/java/com/example/getstarted/auth/LogoutServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.getstarted.auth; 18 | 19 | import java.io.IOException; 20 | import javax.servlet.ServletException; 21 | import javax.servlet.http.HttpServlet; 22 | import javax.servlet.http.HttpServletRequest; 23 | import javax.servlet.http.HttpServletResponse; 24 | import javax.servlet.http.HttpSession; 25 | 26 | // [START example] 27 | @SuppressWarnings("serial") 28 | public class LogoutServlet extends HttpServlet { 29 | 30 | @Override 31 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) 32 | throws IOException, ServletException { 33 | // you can also make an authenticated request to logout, but here we choose to 34 | // simply delete the session variables for simplicity 35 | HttpSession session = req.getSession(false); 36 | if (session != null) { 37 | session.invalidate(); 38 | } 39 | // rebuild session 40 | req.getSession(); 41 | } 42 | } 43 | // [END example] 44 | -------------------------------------------------------------------------------- /bookshelf-standard/5-logging/src/main/java/com/example/getstarted/basicactions/DeleteBookServlet.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.example.getstarted.basicactions; 17 | 18 | import com.example.getstarted.daos.BookDao; 19 | import java.io.IOException; 20 | import javax.servlet.ServletException; 21 | import javax.servlet.http.HttpServlet; 22 | import javax.servlet.http.HttpServletRequest; 23 | import javax.servlet.http.HttpServletResponse; 24 | 25 | // [START example] 26 | @SuppressWarnings("serial") 27 | public class DeleteBookServlet extends HttpServlet { 28 | 29 | @Override 30 | public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, 31 | IOException { 32 | Long id = Long.decode(req.getParameter("id")); 33 | BookDao dao = (BookDao) this.getServletContext().getAttribute("dao"); 34 | try { 35 | dao.deleteBook(id); 36 | resp.sendRedirect("/books"); 37 | } catch (Exception e) { 38 | throw new ServletException("Error deleting book", e); 39 | } 40 | } 41 | } 42 | // [END example] 43 | -------------------------------------------------------------------------------- /bookshelf-standard/5-logging/src/main/java/com/example/getstarted/basicactions/ListByUserServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.getstarted.basicactions; 18 | 19 | import com.example.getstarted.daos.BookDao; 20 | import com.example.getstarted.objects.Book; 21 | import com.example.getstarted.objects.Result; 22 | import java.io.IOException; 23 | import java.util.List; 24 | import java.util.logging.Level; 25 | import java.util.logging.Logger; 26 | import javax.servlet.ServletException; 27 | import javax.servlet.http.HttpServlet; 28 | import javax.servlet.http.HttpServletRequest; 29 | import javax.servlet.http.HttpServletResponse; 30 | 31 | // [START example] 32 | @SuppressWarnings("serial") 33 | public class ListByUserServlet extends HttpServlet { 34 | 35 | private static final Logger logger = Logger.getLogger(ListByUserServlet.class.getName()); 36 | 37 | @Override 38 | public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, 39 | ServletException { 40 | BookDao dao = (BookDao) this.getServletContext().getAttribute("dao"); 41 | String startCursor = req.getParameter("cursor"); 42 | List books = null; 43 | String endCursor = null; 44 | try { 45 | Result result = 46 | dao.listBooksByUser((String) req.getSession().getAttribute("userId"), startCursor); 47 | books = result.result; 48 | endCursor = result.cursor; 49 | } catch (Exception e) { 50 | throw new ServletException("Error listing books", e); 51 | } 52 | req.getSession().getServletContext().setAttribute("books", books); 53 | StringBuilder bookNames = new StringBuilder(); 54 | for (Book book : books) { 55 | bookNames.append(book.getTitle() + " "); 56 | } 57 | logger.log(Level.INFO, "Loaded books: " + bookNames.toString() 58 | + " for user " + (String) req.getSession().getAttribute("userId")); 59 | req.getSession().setAttribute("cursor", endCursor); 60 | req.getSession().setAttribute("page", "list"); 61 | req.getRequestDispatcher("/base.jsp").forward(req, resp); 62 | } 63 | } 64 | // [END example] 65 | -------------------------------------------------------------------------------- /bookshelf-standard/5-logging/src/main/java/com/example/getstarted/basicactions/ReadBookServlet.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.example.getstarted.basicactions; 17 | 18 | import com.example.getstarted.daos.BookDao; 19 | import com.example.getstarted.objects.Book; 20 | import java.io.IOException; 21 | import java.util.logging.Level; 22 | import java.util.logging.Logger; 23 | import javax.servlet.ServletException; 24 | import javax.servlet.http.HttpServlet; 25 | import javax.servlet.http.HttpServletRequest; 26 | import javax.servlet.http.HttpServletResponse; 27 | 28 | // [START example] 29 | @SuppressWarnings("serial") 30 | public class ReadBookServlet extends HttpServlet { 31 | 32 | // [START init] 33 | private final Logger logger = Logger.getLogger(ReadBookServlet.class.getName()); 34 | // [END init] 35 | 36 | @Override 37 | public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, 38 | ServletException { 39 | Long id = Long.decode(req.getParameter("id")); 40 | BookDao dao = (BookDao) this.getServletContext().getAttribute("dao"); 41 | try { 42 | Book book = dao.readBook(id); 43 | // [START log] 44 | logger.log(Level.INFO, "Read book with id {0}", id); 45 | // [END log] 46 | req.setAttribute("book", book); 47 | req.setAttribute("page", "view"); 48 | req.getRequestDispatcher("/base.jsp").forward(req, resp); 49 | } catch (Exception e) { 50 | throw new ServletException("Error reading book", e); 51 | } 52 | } 53 | } 54 | // [END example] 55 | -------------------------------------------------------------------------------- /bookshelf-standard/5-logging/src/main/java/com/example/getstarted/daos/BookDao.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.example.getstarted.daos; 17 | 18 | import com.example.getstarted.objects.Book; 19 | import com.example.getstarted.objects.Result; 20 | import java.sql.SQLException; 21 | 22 | // [START example] 23 | public interface BookDao { 24 | Long createBook(Book book) throws SQLException; 25 | 26 | Book readBook(Long bookId) throws SQLException; 27 | 28 | void updateBook(Book book) throws SQLException; 29 | 30 | void deleteBook(Long bookId) throws SQLException; 31 | 32 | Result listBooks(String startCursor) throws SQLException; 33 | 34 | Result listBooksByUser(String userId, String startCursor) throws SQLException; 35 | } 36 | // [END example] 37 | -------------------------------------------------------------------------------- /bookshelf-standard/5-logging/src/main/java/com/example/getstarted/objects/Result.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.example.getstarted.objects; 17 | 18 | import java.util.List; 19 | 20 | // [START example] 21 | public class Result { 22 | 23 | public String cursor; 24 | public List result; 25 | 26 | public Result(List result, String cursor) { 27 | this.result = result; 28 | this.cursor = cursor; 29 | } 30 | 31 | public Result(List result) { 32 | this.result = result; 33 | this.cursor = null; 34 | } 35 | } 36 | // [END example] 37 | -------------------------------------------------------------------------------- /bookshelf-standard/5-logging/src/main/webapp/WEB-INF/appengine-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | true 19 | true 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | true 35 | 36 | 37 | -------------------------------------------------------------------------------- /bookshelf-standard/5-logging/src/main/webapp/WEB-INF/datastore-indexes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /bookshelf-standard/5-logging/src/main/webapp/WEB-INF/logging.properties: -------------------------------------------------------------------------------- 1 | # A default java.util.logging configuration. 2 | # (All App Engine logging is through java.util.logging by default). 3 | 4 | # Set the default logging level for all loggers to INFO 5 | .level = INFO 6 | handlers=java.util.logging.ConsoleHandler 7 | java.util.logging.ConsoleHandler.level=FINEST 8 | java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter 9 | java.util.logging.SimpleFormatter.format = [%1$tc] %4$s: %2$s - %5$s %6$s%n 10 | -------------------------------------------------------------------------------- /bookshelf-standard/5-logging/src/main/webapp/base.jsp: -------------------------------------------------------------------------------- 1 | 16 | 17 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 18 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 19 | 20 | 21 | Bookshelf - Java on Google Cloud Platform 22 | 23 | 24 | 25 | 26 | 27 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /bookshelf-standard/5-logging/src/main/webapp/form.jsp: -------------------------------------------------------------------------------- 1 | 16 | 17 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 18 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%> 19 |
20 |

21 | book 22 |

23 | 24 |
25 | 26 |
27 | 28 | 29 |
30 | 31 |
32 | 33 | 34 |
35 | 36 |
37 | 38 | 39 |
40 | 41 |
42 | 43 | 44 |
45 | 46 |
47 | 48 | 49 |
50 | 51 | 56 | 57 | 58 |
59 |
60 | 61 | -------------------------------------------------------------------------------- /bookshelf-standard/5-logging/src/main/webapp/list.jsp: -------------------------------------------------------------------------------- 1 | 16 | 17 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 18 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 19 |
20 |

Books

21 | 22 | 23 | Add book 24 | 25 | 26 | 27 |

No books found

28 |
29 | 30 | 31 | 42 | 43 | 44 | 49 | 50 | 51 |
52 |
53 | 54 | -------------------------------------------------------------------------------- /bookshelf-standard/5-logging/src/main/webapp/view.jsp: -------------------------------------------------------------------------------- 1 | 16 | 17 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 18 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 19 |
20 |

Book

21 | 31 | 32 |
33 |
34 | 35 |
36 |
37 |

38 | ${fn:escapeXml(book.title)} 39 | ${fn:escapeXml(book.publishedDate)} 40 |

41 |
By ${fn:escapeXml(not empty book.author?book.author:'Unknown')}
42 |

${fn:escapeXml(book.description)}

43 | Added by 44 | ${fn:escapeXml(not empty book.createdBy?book.createdBy:'Anonymous')} 45 |
46 |
47 |
48 | 49 | -------------------------------------------------------------------------------- /bookshelf/1-cloud-run/README.md: -------------------------------------------------------------------------------- 1 | # Bookshelf App for Java on Cloud Run Tutorial 2 | 3 | Contains the code for using Cloud Firestore. 4 | 5 | This is part of a [Bookshelf tutorial](https://cloud.google.com/java/getting-started). 6 | 7 | Most users can get this running by updating the parameters in `pom.xml`. You'll 8 | also need to [create a bucket][create-bucket] in Google Cloud Storage, referred 9 | to below as `MY_BUCKET`. 10 | 11 | [create-bucket]: https://cloud.google.com/storage/docs/creating-buckets 12 | 13 | ### Running Locally 14 | 15 | To run your project locally: 16 | 17 | * Set the `BOOKSHELF_BUCKET` environment variable: 18 | 19 | export BOOKSHELF_BUCKET= 20 | 21 | Where is the bucket you created above. 22 | * Run with the Jetty Maven plugin: 23 | 24 | mvn jetty:run 25 | 26 | **Note**: If you run into an error about `Invalid Credentials`, you may have to run: 27 | 28 | gcloud auth application-default login 29 | 30 | ### Deploying to Cloud Run 31 | 32 | To build your image: 33 | 34 | * Update the parameters in `pom.xml`: 35 | * Replace `MY_PROJECT` with your project ID. 36 | * Build and deploy to your GCR with [Jib][jib] Maven plugin. 37 | 38 | mvn clean package jib:build 39 | 40 | * Deploy the app to Cloud Run: 41 | 42 | gcloud run deploy bookshelf --image gcr.io//bookshelf \ 43 | --region us-central1 --memory 512M \ 44 | --update-env-vars BOOKSHELF_BUCKET="" 45 | 46 | Where is the name of the project you created. 47 | 48 | This command will output a link to visit the page. 49 | 50 | [jib]: https://github.com/GoogleContainerTools/jib 51 | [configure-memory]: https://cloud.google.com/run/docs/configuring/memory-limits 52 | -------------------------------------------------------------------------------- /bookshelf/1-cloud-run/src/main/java/com/example/getstarted/basicactions/DeleteBookServlet.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 Google LLC 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.example.getstarted.basicactions; 17 | 18 | // [START bookshelf_delete_servlet] 19 | 20 | import com.example.getstarted.daos.BookDao; 21 | import java.io.IOException; 22 | import javax.servlet.annotation.WebServlet; 23 | import javax.servlet.http.HttpServlet; 24 | import javax.servlet.http.HttpServletRequest; 25 | import javax.servlet.http.HttpServletResponse; 26 | 27 | @SuppressWarnings("serial") 28 | @WebServlet( 29 | name = "delete", 30 | urlPatterns = {"/delete"}) 31 | public class DeleteBookServlet extends HttpServlet { 32 | 33 | @Override 34 | public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { 35 | String id = req.getParameter("id"); 36 | BookDao dao = (BookDao) this.getServletContext().getAttribute("dao"); 37 | dao.deleteBook(id); 38 | resp.sendRedirect("/books"); 39 | } 40 | } 41 | // [END bookshelf_delete_servlet] 42 | -------------------------------------------------------------------------------- /bookshelf/1-cloud-run/src/main/java/com/example/getstarted/basicactions/ErrorsBookServlet.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 Google LLC 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.example.getstarted.basicactions; 17 | 18 | // [START bookshelf_errors_servlet] 19 | 20 | import javax.servlet.ServletException; 21 | import javax.servlet.annotation.WebServlet; 22 | import javax.servlet.http.HttpServlet; 23 | import javax.servlet.http.HttpServletRequest; 24 | import javax.servlet.http.HttpServletResponse; 25 | 26 | @SuppressWarnings("serial") 27 | @WebServlet( 28 | name = "errors", 29 | urlPatterns = {"/errors"}) 30 | public class ErrorsBookServlet extends HttpServlet { 31 | @Override 32 | public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException { 33 | throw new ServletException("Expected exception."); 34 | } 35 | } 36 | // [END bookshelf_errors_servlet] 37 | -------------------------------------------------------------------------------- /bookshelf/1-cloud-run/src/main/java/com/example/getstarted/basicactions/ReadBookServlet.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 Google LLC 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.example.getstarted.basicactions; 17 | 18 | // [START bookshelf_read_servlet] 19 | 20 | import com.example.getstarted.daos.BookDao; 21 | import com.example.getstarted.objects.Book; 22 | import java.io.IOException; 23 | import java.util.logging.Level; 24 | import java.util.logging.Logger; 25 | import javax.servlet.ServletException; 26 | import javax.servlet.annotation.WebServlet; 27 | import javax.servlet.http.HttpServlet; 28 | import javax.servlet.http.HttpServletRequest; 29 | import javax.servlet.http.HttpServletResponse; 30 | 31 | @SuppressWarnings("serial") 32 | @WebServlet( 33 | name = "read", 34 | urlPatterns = {"/read"}) 35 | public class ReadBookServlet extends HttpServlet { 36 | 37 | private final Logger logger = Logger.getLogger(ReadBookServlet.class.getName()); 38 | 39 | @Override 40 | public void doGet(HttpServletRequest req, 41 | HttpServletResponse resp) throws ServletException, IOException { 42 | String id = req.getParameter("id"); 43 | BookDao dao = (BookDao) this.getServletContext().getAttribute("dao"); 44 | Book book = dao.readBook(id); 45 | logger.log(Level.INFO, "Read book with id {0}", id); 46 | req.setAttribute("book", book); 47 | req.setAttribute("page", "view"); 48 | req.getRequestDispatcher("/base.jsp").forward(req, resp); 49 | } 50 | } 51 | // [END bookshelf_read_servlet] 52 | -------------------------------------------------------------------------------- /bookshelf/1-cloud-run/src/main/java/com/example/getstarted/daos/BookDao.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 Google LLC 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.example.getstarted.daos; 17 | 18 | import com.example.getstarted.objects.Book; 19 | import com.example.getstarted.objects.Result; 20 | 21 | // [START bookshelf_base_dao] 22 | public interface BookDao { 23 | String createBook(Book book); 24 | 25 | Book readBook(String bookId); 26 | 27 | void updateBook(Book book); 28 | 29 | void deleteBook(String bookId); 30 | 31 | Result listBooks(String startCursor); 32 | 33 | Result listBooksByUser(String userId, String startCursor); 34 | } 35 | // [END bookshelf_base_dao] 36 | -------------------------------------------------------------------------------- /bookshelf/1-cloud-run/src/main/java/com/example/getstarted/objects/Result.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 Google LLC 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.example.getstarted.objects; 17 | 18 | import java.util.List; 19 | 20 | // [START bookshelf_result] 21 | public class Result { 22 | private String cursor; 23 | private List result; 24 | 25 | public String getCursor() { 26 | return cursor; 27 | } 28 | 29 | public void setCursor(String cursor) { 30 | this.cursor = cursor; 31 | } 32 | 33 | public List getResult() { 34 | return result; 35 | } 36 | 37 | public void setResult(List result) { 38 | this.result = result; 39 | } 40 | 41 | public Result(List result, String cursor) { 42 | this.result = result; 43 | this.cursor = cursor; 44 | } 45 | 46 | public Result(List result) { 47 | this.result = result; 48 | this.cursor = null; 49 | } 50 | } 51 | // [END bookshelf_result] 52 | -------------------------------------------------------------------------------- /bookshelf/1-cloud-run/src/main/java/com/example/getstarted/util/BookshelfContextListener.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 Google LLC 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.example.getstarted.util; 17 | 18 | import com.example.getstarted.daos.BookDao; 19 | import com.example.getstarted.daos.FirestoreDao; 20 | import com.google.common.base.Strings; 21 | import javax.servlet.ServletContextEvent; 22 | import javax.servlet.ServletContextListener; 23 | import javax.servlet.annotation.WebListener; 24 | 25 | @WebListener("Creates BookDao and other servlet context objects for reuse.") 26 | public class BookshelfContextListener implements ServletContextListener { 27 | @Override 28 | public void contextDestroyed(javax.servlet.ServletContextEvent event) { 29 | } 30 | 31 | @Override 32 | public void contextInitialized(ServletContextEvent event) { 33 | // This function is called when the application starts and will safely set a few required 34 | // context attributes such as the BookDao. 35 | 36 | BookDao dao = (BookDao) event.getServletContext().getAttribute("dao"); 37 | if (dao == null) { 38 | dao = new FirestoreDao(); 39 | event.getServletContext().setAttribute("dao", dao); 40 | } 41 | 42 | Boolean isCloudStorageConfigured = (Boolean) event.getServletContext() 43 | .getAttribute("isCloudStorageConfigured"); 44 | if (isCloudStorageConfigured == null) { 45 | event.getServletContext() 46 | .setAttribute( 47 | "isCloudStorageConfigured", 48 | !Strings.isNullOrEmpty(System.getenv("BOOKSHELF_BUCKET"))); 49 | } 50 | 51 | CloudStorageHelper storageHelper = (CloudStorageHelper) event.getServletContext().getAttribute( 52 | "storageHelper"); 53 | if (storageHelper == null) { 54 | storageHelper = new CloudStorageHelper(); 55 | event.getServletContext().setAttribute("storageHelper", storageHelper); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /bookshelf/1-cloud-run/src/main/webapp/base.jsp: -------------------------------------------------------------------------------- 1 | 16 | 17 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 18 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 19 | 20 | 21 | Bookshelf - Java on Google Cloud Platform 22 | 23 | 24 | 25 | 26 | 27 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /bookshelf/1-cloud-run/src/main/webapp/form.jsp: -------------------------------------------------------------------------------- 1 | 16 | 17 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 18 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%> 19 |
20 |

21 | book 22 |

23 | 24 |
25 | 26 |
27 | 28 | 29 |
30 | 31 |
32 | 33 | 34 |
35 | 36 |
37 | 38 | 39 |
40 | 41 |
42 | 43 | 44 |
45 | 46 |
47 | 48 | 49 |
50 | 51 | 56 | 57 | 58 |
59 |
60 | 61 | -------------------------------------------------------------------------------- /bookshelf/1-cloud-run/src/main/webapp/list.jsp: -------------------------------------------------------------------------------- 1 | 16 | 17 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 18 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 19 |
20 |

Books

21 | 22 | 23 | Add book 24 | 25 | 26 | 27 |

No books found

28 |
29 | 30 | 31 | 42 | 43 | 44 | 49 | 50 | 51 |
52 |
53 | 54 | -------------------------------------------------------------------------------- /bookshelf/1-cloud-run/src/main/webapp/view.jsp: -------------------------------------------------------------------------------- 1 | 16 | 17 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 18 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 19 |
20 |

Book

21 | 31 | 32 |
33 |
34 | 35 |
36 |
37 |

38 | ${fn:escapeXml(book.title)} 39 | ${fn:escapeXml(book.publishedDate)} 40 |

41 |
By ${fn:escapeXml(not empty book.author?book.author:'Unknown')}
42 |

${fn:escapeXml(book.description)}

43 | Added by 44 | ${fn:escapeXml(not empty book.createdBy?book.createdBy:'Anonymous')} 45 |
46 |
47 |
48 | 49 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | codecov: 15 | branch: main 16 | 17 | comment: 18 | branches: 19 | - main 20 | -------------------------------------------------------------------------------- /gce/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Java - Google Compute Engine 2 | 3 | See the [Bookshelf tutorial][tutorial] for help getting started with Google App Engine (Standard), Google Cloud 4 | Firestore, and more. 5 | 6 | You'll need to [create a bucket][create-bucket] in Google Cloud Storage, 7 | referred to below as `MY-BUCKET`. You'll also need to create an OAuth2 client 8 | and secret, and edit `pom.xml` with its values. 9 | 10 | ### Running Locally 11 | 12 | mvn clean jetty:run-war -DprojectID=YOUR-PROJECT-ID 13 | 14 | ### Deploying to Compute Engine 15 | 16 | * Initialize the [Google Cloud SDK][cloud_sdk] 17 | 18 | gcloud init 19 | 20 | * In the `makeProject` script update the `BUCKET` environment variable 21 | with your bucket name. 22 | 23 | * Deploy your App 24 | 25 | ./makeProject gce 26 | 27 | * To tear down the App, use 28 | 29 | ./makeProject down 30 | 31 | ### Deploying to Compute Engine with horizontal scaling 32 | 33 | * Initialize Google Cloud SDK and `makeProject` as above. 34 | 35 | * Deploy your App 36 | 37 | ./makeProject gce-many 38 | 39 | * To tear down the App, use 40 | 41 | ./makeProject down-many 42 | 43 | [tutorial]: https://cloud.google.com/java/getting-started/tutorial-app 44 | [create-bucket]: https://cloud.google.com/storage/docs/creating-buckets#storage-create-bucket-console 45 | [cloud_sdk]: https://cloud.google.com/sdk/ 46 | -------------------------------------------------------------------------------- /gce/config/base/etc/java-util-logging.properties: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # A default java.util.logging configuration. 16 | # 17 | 18 | handlers=java.util.logging.ConsoleHandler,java.util.logging.FileHandler 19 | 20 | java.util.logging.FileHandler.level=INFO 21 | #java.util.logging.FileHandler.formatter= 22 | #java.util.logging.FileHandler.pattern=/opt/jetty/logs/app.%g.log.json 23 | java.util.logging.FileHandler.limit=104857600 24 | java.util.logging.FileHandler.count=3 25 | 26 | # Set the default logging level for all loggers to INFO 27 | .level=INFO 28 | 29 | # Override root level 30 | com.foo.level=FINE 31 | 32 | # Override parent's level 33 | com.foo.bar.level=SEVERE 34 | -------------------------------------------------------------------------------- /gce/config/base/modules/gce.mod: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # GCE Module 16 | # 17 | 18 | [depend] 19 | resources 20 | server 21 | 22 | [optional] 23 | 24 | [ini-template] 25 | 26 | ## Google Defaults 27 | jetty.httpConfig.outputAggregationSize=32768 28 | jetty.httpConfig.headerCacheSize=512 29 | 30 | jetty.httpConfig.sendServerVersion=true 31 | jetty.httpConfig.sendDateHeader=false 32 | 33 | #gae.httpPort=80 34 | #gae.httpsPort=443 35 | -------------------------------------------------------------------------------- /gce/config/base/resources/jetty-logging.properties: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Direct Jetty logging to JavaUtilLog 16 | # see etc/java-util-logging.properties 17 | org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.JavaUtilLog 18 | -------------------------------------------------------------------------------- /gce/src/main/appengine/app.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # [START runtime] 16 | runtime: java 17 | env: flex 18 | 19 | handlers: 20 | - url: /.* 21 | script: this field is required, but ignored 22 | 23 | # [START env_variables] 24 | env_variables: # Logging options 25 | JAVA_OPTS: >- 26 | -D.level=INFO 27 | # [END env_variables] 28 | # [END runtime] 29 | 30 | runtime_config: # Optional 31 | jdk: openjdk8 32 | server: jetty9 33 | -------------------------------------------------------------------------------- /gce/src/main/java/com/example/getstarted/basicactions/HelloworldController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.getstarted.basicactions; 18 | 19 | import java.io.IOException; 20 | import javax.servlet.annotation.WebServlet; 21 | import javax.servlet.http.HttpServlet; 22 | import javax.servlet.http.HttpServletRequest; 23 | import javax.servlet.http.HttpServletResponse; 24 | 25 | @WebServlet(value = "/") 26 | public class HelloworldController extends HttpServlet { 27 | 28 | @Override 29 | public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { 30 | resp.getWriter().write("Hello world - GCE!"); 31 | resp.setStatus(HttpServletResponse.SC_OK); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /gce/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | 20 | 21 | 22 | / 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /gce/src/test/java/com/example/getstarted/basicactions/UserJourneyTestIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.getstarted.basicactions; 18 | 19 | import static org.junit.Assert.assertTrue; 20 | 21 | import org.junit.After; 22 | import org.junit.Before; 23 | import org.junit.BeforeClass; 24 | import org.junit.Ignore; 25 | import org.junit.Test; 26 | import org.junit.runner.RunWith; 27 | import org.junit.runners.JUnit4; 28 | import org.openqa.selenium.WebDriver; 29 | import org.openqa.selenium.chrome.ChromeDriverService; 30 | import org.openqa.selenium.chrome.ChromeOptions; 31 | import org.openqa.selenium.remote.RemoteWebDriver; 32 | import org.openqa.selenium.remote.service.DriverService; 33 | 34 | @RunWith(JUnit4.class) 35 | @SuppressWarnings("checkstyle:AbbreviationAsWordInName") 36 | public class UserJourneyTestIT { 37 | private static DriverService service; 38 | private WebDriver driver; 39 | 40 | @BeforeClass 41 | public static void setupClass() throws Exception { 42 | service = ChromeDriverService.createDefaultService(); 43 | service.start(); 44 | } 45 | 46 | @Before 47 | public void setup() { 48 | driver = new RemoteWebDriver(service.getUrl(), new ChromeOptions()); 49 | } 50 | 51 | @After 52 | public void tearDown() { 53 | driver.quit(); 54 | } 55 | 56 | @Test 57 | @Ignore("b/138123046") 58 | public void userJourney() { 59 | driver.get("http://localhost:8080"); 60 | 61 | try { 62 | assertTrue(driver.getPageSource().contains("Hello world - GCE!")); 63 | } catch (Exception e) { 64 | System.err.println(driver.getPageSource()); 65 | throw e; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /helloworld-jsp/README.md: -------------------------------------------------------------------------------- 1 | # Java Server Pages based Hello World app 2 | 3 | ## Requirements 4 | * [Apache Maven](http://maven.apache.org) 3.3.9 or greater 5 | * [Google Cloud SDK](https://cloud.google.com/sdk/) 6 | * `gcloud components install app-engine-java` 7 | * `gcloud components update` 8 | 9 | ## Setup 10 | 11 | Use either: 12 | 13 | * `gcloud init` 14 | * `gcloud beta auth application-default login` 15 | 16 | Set your project, the plugins in this example are configured to use this value from gcloud 17 | 18 | * `gcloud config set project ` 19 | 20 | We support building with [Maven](http://maven.apache.org/), [Gradle](https://gradle.org), and [IntelliJ IDEA](https://cloud.google.com/tools/intellij/docs/). 21 | The samples have files to support both Maven and Gradle. To use the IDE plugins, see the documentation pages above. 22 | 23 | ## Maven 24 | [Using Maven and the App Engine Plugin](https://cloud.google.com/appengine/docs/flexible/java/using-maven) 25 | & [Maven Plugin Goals and Parameters](https://cloud.google.com/appengine/docs/flexible/java/maven-reference) 26 | ### Running locally 27 | 28 | $ mvn jetty:run-exploded 29 | 30 | ### Deploying 31 | 32 | * In the `pom.xml`, update the [App Engine Maven Plugin](https://cloud.google.com/appengine/docs/standard/java/tools/maven-reference) 33 | with your Google Cloud Project Id: 34 | 35 | ``` 36 | 37 | com.google.cloud.tools 38 | appengine-maven-plugin 39 | 2.3.0 40 | 41 | GCLOUD_CONFIG 42 | GCLOUD_CONFIG 43 | 44 | 45 | ``` 46 | **Note:** `GCLOUD_CONFIG` is a special version for autogenerating an App Engine 47 | version. Change this field to specify a specific version name. 48 | 49 | * Deploy your App 50 | ``` 51 | $ mvn package appengine:deploy 52 | ``` 53 | 54 | ## Gradle 55 | [Using Gradle and the App Engine Plugin](https://cloud.google.com/appengine/docs/flexible/java/using-gradle) 56 | & [Gradle Tasks and Parameters](https://cloud.google.com/appengine/docs/flexible/java/gradle-reference) 57 | ### Running locally 58 | 59 | $ gradle jettyRun 60 | 61 | ### Deploying 62 | 63 | $ gradle appengineDeploy 64 | -------------------------------------------------------------------------------- /helloworld-jsp/build.gradle: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // [START gradle] 15 | buildscript { // Configuration for building 16 | repositories { 17 | jcenter() // Bintray's repository - a fast Maven Central mirror & more 18 | mavenCentral() 19 | } 20 | dependencies { 21 | classpath 'com.google.cloud.tools:appengine-gradle-plugin:2.5.0' 22 | classpath 'org.akhikhl.gretty:gretty:+' 23 | } 24 | } 25 | 26 | repositories { // repositories for JARs you access in your code 27 | maven { 28 | url 'https://maven-central.storage.googleapis.com' // Google's mirror of Maven Central 29 | } 30 | 31 | //maven { 32 | // url 'https://oss.sonatype.org/content/repositories/snapshots' // SNAPSHOT repository if needed 33 | //} 34 | 35 | jcenter() 36 | mavenCentral() 37 | } 38 | 39 | apply plugin: 'java' 40 | apply plugin: 'war' 41 | apply plugin: 'org.akhikhl.gretty' 42 | apply plugin: 'com.google.cloud.tools.appengine' 43 | 44 | dependencies { 45 | providedCompile 'javax.servlet:javax.servlet-api:4.0.1' 46 | providedCompile 'com.google.appengine:appengine:+' 47 | // Add your dependencies here. 48 | 49 | } 50 | 51 | // [START gretty] 52 | gretty { 53 | httpPort = 8080 54 | contextPath = '/' 55 | servletContainer = 'jetty9' // What App Engine Flexible uses 56 | } 57 | // [END gretty] 58 | 59 | // [START model] 60 | appengine { 61 | 62 | deploy { // deploy configuration 63 | stopPreviousVersion = true // default - stop the current version 64 | promote = true // default - & make this the current version 65 | projectId = 'GCLOUD_CONFIG' // delegate to project in gcloud config 66 | version = 'GCLOUD_CONFIG' // delegate to gcloud to generate a version 67 | } 68 | } 69 | // [END model] 70 | 71 | group = 'com.example.appengine.helloworld-jsp' // Generated output GroupId 72 | version = '1.0-SNAPSHOT' // Version in generated output 73 | 74 | sourceCompatibility = 1.8 75 | targetCompatibility = 1.8 76 | // [END gradle] 77 | -------------------------------------------------------------------------------- /helloworld-jsp/eclipse-launch-profiles/AppEngineDeploy.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /helloworld-jsp/eclipse-launch-profiles/AppEngineRun.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /helloworld-jsp/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleCloudPlatform/getting-started-java/faece5ea8b3634e9229858ff90e95a096193ada5/helloworld-jsp/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /helloworld-jsp/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Sep 07 11:48:19 PDT 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip 7 | -------------------------------------------------------------------------------- /helloworld-jsp/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /helloworld-jsp/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | CUSTOM-appengine:gcloud 21 | appengine:run 22 | 23 | jetty:run-exploded 24 | 25 | 26 | 27 | CUSTOM-appengine:gcloud 28 | appengine:deploy 29 | 30 | appengine:deploy 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /helloworld-jsp/src/main/appengine/app.yaml: -------------------------------------------------------------------------------- 1 | # [START_EXCLUDE] 2 | #Copyright 2015 Google Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # [END_EXCLUDE] 16 | runtime: java 17 | env: flex 18 | 19 | runtime_config: # Optional 20 | jdk: openjdk8 21 | server: jetty9 22 | 23 | handlers: 24 | - url: /.* 25 | script: this field is required, but ignored 26 | 27 | manual_scaling: 28 | instances: 1 29 | 30 | beta_settings: 31 | java_quickstart: true 32 | -------------------------------------------------------------------------------- /helloworld-jsp/src/main/java/org/example/appengine/hello/HelloInfo.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package org.example.appengine.hello; 17 | 18 | // [START example] 19 | /** 20 | * Generate some simple information. 21 | */ 22 | public class HelloInfo { 23 | 24 | public static String getInfo() { 25 | return "Version: " + System.getProperty("java.version") 26 | + " OS: " + System.getProperty("os.name") 27 | + " User: " + System.getProperty("user.name"); 28 | } 29 | } 30 | // [END example] 31 | -------------------------------------------------------------------------------- /helloworld-jsp/src/main/webapp/WEB-INF/logging.properties: -------------------------------------------------------------------------------- 1 | # A default java.util.logging configuration. 2 | # (All App Engine logging is through java.util.logging by default). 3 | # 4 | # To use this configuration, copy it into your application's WEB-INF 5 | # folder and add the following to your appengine-web.xml: 6 | # 7 | # 8 | # 9 | # 10 | # 11 | 12 | # Set the default logging level for all loggers to WARNING 13 | .level = WARNING 14 | -------------------------------------------------------------------------------- /helloworld-jsp/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 21 | 22 | 23 | hello.jsp 24 | 25 | 26 | -------------------------------------------------------------------------------- /helloworld-jsp/src/main/webapp/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleCloudPlatform/getting-started-java/faece5ea8b3634e9229858ff90e95a096193ada5/helloworld-jsp/src/main/webapp/favicon.ico -------------------------------------------------------------------------------- /helloworld-jsp/src/main/webapp/hello.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | <%@ page import="org.example.appengine.hello.HelloInfo" %> 3 | 4 | <%-- 5 | ~ Copyright (c) 2016 Google Inc. 6 | ~ 7 | ~ Licensed under the Apache License, Version 2.0 (the "License"); you 8 | ~ may not use this file except in compliance with the License. You may 9 | ~ obtain a copy of the License at 10 | ~ 11 | ~ http://www.apache.org/licenses/LICENSE-2.0 12 | ~ 13 | ~ Unless required by applicable law or agreed to in writing, software 14 | ~ distributed under the License is distributed on an "AS IS" BASIS, 15 | ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 16 | ~ implied. See the License for the specific language governing 17 | ~ permissions and limitations under the License. 18 | --%> 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |

Hello!

27 | 28 |

This is <%= HelloInfo.getInfo() %>.

29 | 30 | 31 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base" 4 | ], 5 | "packageRules": [ 6 | { 7 | "packagePatterns": [ "^com.google.appengine:" ], 8 | "groupName": "AppEngine packages" 9 | }, 10 | { 11 | "packagePatterns": [ "^io.grpc:grpc-" ], 12 | "groupName": "gRPC packages" 13 | }, 14 | { 15 | "packagePatterns": [ "^io.vertx:vertex-" ], 16 | "groupName": "Vertx packages" 17 | }, 18 | { 19 | "packagePatterns": [ "^org.jetbrains.kotlin:" ], 20 | "groupName": "Kotlin packages" 21 | }, 22 | { 23 | "packagePatterns": [ "^org.springframework.boot:" ], 24 | "groupName": "Spring packages" 25 | }, 26 | { 27 | "packagePatterns": [ "^io.opencensus:" ], 28 | "groupName": "Opencensus packages" 29 | } 30 | ], 31 | "labels": [ 32 | "automerge" 33 | ], 34 | "prConcurrentLimit": 0, 35 | "rebaseWhen": "never", 36 | "dependencyDashboard": true, 37 | "dependencyDashboardLabels": [ 38 | "type: process" 39 | ], 40 | "constraints": { 41 | "java": "1.8" 42 | } 43 | } 44 | --------------------------------------------------------------------------------