From 8973583aef4c50c4b33a822ac28d216f928a2a41 Mon Sep 17 00:00:00 2001 From: manishchaudhari-ssk <86125082+manishchaudhari-ssk@users.noreply.github.com> Date: Mon, 3 Feb 2025 16:07:44 +0530 Subject: [PATCH 1/4] Updated the Java version in app.yaml in new Java21 directory --- .../helloworld/http-server/README.md | 20 +++++++ .../helloworld/http-server/pom.xml | 49 +++++++++++++++++ .../http-server/src/main/appengine/app.yaml | 18 +++++++ .../main/java/com/example/appengine/Main.java | 52 +++++++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 appengine-java21/helloworld/http-server/README.md create mode 100644 appengine-java21/helloworld/http-server/pom.xml create mode 100644 appengine-java21/helloworld/http-server/src/main/appengine/app.yaml create mode 100644 appengine-java21/helloworld/http-server/src/main/java/com/example/appengine/Main.java diff --git a/appengine-java21/helloworld/http-server/README.md b/appengine-java21/helloworld/http-server/README.md new file mode 100644 index 00000000000..fbcc276a3a5 --- /dev/null +++ b/appengine-java21/helloworld/http-server/README.md @@ -0,0 +1,20 @@ +# Standalone HTTP Server on Google App Engine Standard with Java 11 + +This sample shows how to deploy an application to Google App Engine from source. The `entrypoint` field listed in the [`app.yaml`](src/main/appengine/app.yaml) is not required, +as GAE will determine the entrypoint by searching the `target` directory for the .jar file with a Main-Class Manifest entry. + +## Setup + +See [Prerequisites](../README.md#Prerequisites). + +## Deploy to App Engine Standard + +``` +gcloud app deploy +``` + +To view your app, use command: +``` +gcloud app browse +``` +Or navigate to `https://.appspot.com`. diff --git a/appengine-java21/helloworld/http-server/pom.xml b/appengine-java21/helloworld/http-server/pom.xml new file mode 100644 index 00000000000..88ff04908fb --- /dev/null +++ b/appengine-java21/helloworld/http-server/pom.xml @@ -0,0 +1,49 @@ + + 4.0.0 + com.example.appengine + http-server + 0.1 + + + + com.google.cloud.samples + shared-configuration + 1.2.0 + + + + + 11 + 11 + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.3.0 + + + + com.example.appengine.Main + + + + + + + com.google.cloud.tools + appengine-maven-plugin + 2.8.0 + + GCLOUD_CONFIG + http-server + + + + + diff --git a/appengine-java21/helloworld/http-server/src/main/appengine/app.yaml b/appengine-java21/helloworld/http-server/src/main/appengine/app.yaml new file mode 100644 index 00000000000..7a136112cec --- /dev/null +++ b/appengine-java21/helloworld/http-server/src/main/appengine/app.yaml @@ -0,0 +1,18 @@ +# Copyright 2019 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START gae_java21_runtime] +runtime: java21 +# No need for an entrypoint with single fatjar with correct manifest class-path entry. +# [END gae_java21_runtime] diff --git a/appengine-java21/helloworld/http-server/src/main/java/com/example/appengine/Main.java b/appengine-java21/helloworld/http-server/src/main/java/com/example/appengine/Main.java new file mode 100644 index 00000000000..f6d1b41527d --- /dev/null +++ b/appengine-java21/helloworld/http-server/src/main/java/com/example/appengine/Main.java @@ -0,0 +1,52 @@ +/* + * Copyright 2019 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.appengine; + +import com.sun.net.httpserver.HttpServer; +import java.io.IOException; +import java.io.OutputStream; +import java.net.InetSocketAddress; + +public class Main { + + public static void main(String[] args) throws IOException { + // Create an instance of HttpServer bound to port defined by the + // PORT environment variable when present, otherwise on 8080. + int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "8080")); + HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); + + // Set root URI path. + server.createContext("/", (var t) -> { + byte[] response = "Hello World!".getBytes(); + t.sendResponseHeaders(200, response.length); + try (OutputStream os = t.getResponseBody()) { + os.write(response); + } + }); + + // Create a second URI path. + server.createContext("/foo", (var t) -> { + byte[] response = "Foo!".getBytes(); + t.sendResponseHeaders(200, response.length); + try (OutputStream os = t.getResponseBody()) { + os.write(response); + } + }); + + server.start(); + } +} From f8cf131ad8fda44fe0f1a5405b71fc969ce74613 Mon Sep 17 00:00:00 2001 From: manishchaudhari-ssk <86125082+manishchaudhari-ssk@users.noreply.github.com> Date: Mon, 3 Feb 2025 16:45:06 +0530 Subject: [PATCH 2/4] minor title update --- appengine-java21/helloworld/http-server/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appengine-java21/helloworld/http-server/README.md b/appengine-java21/helloworld/http-server/README.md index fbcc276a3a5..8c85a89b255 100644 --- a/appengine-java21/helloworld/http-server/README.md +++ b/appengine-java21/helloworld/http-server/README.md @@ -1,4 +1,4 @@ -# Standalone HTTP Server on Google App Engine Standard with Java 11 +# Standalone HTTP Server on Google App Engine Standard with Java 21 This sample shows how to deploy an application to Google App Engine from source. The `entrypoint` field listed in the [`app.yaml`](src/main/appengine/app.yaml) is not required, as GAE will determine the entrypoint by searching the `target` directory for the .jar file with a Main-Class Manifest entry. From a7bd32a2a9f620c1409c3cbeb81ddd4b08cfbcd6 Mon Sep 17 00:00:00 2001 From: manishchaudhari-ssk <86125082+manishchaudhari-ssk@users.noreply.github.com> Date: Mon, 3 Feb 2025 16:47:05 +0530 Subject: [PATCH 3/4] minor changes --- .../helloworld/http-server/src/main/appengine/app.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appengine-java21/helloworld/http-server/src/main/appengine/app.yaml b/appengine-java21/helloworld/http-server/src/main/appengine/app.yaml index 7a136112cec..b84dd5b9b43 100644 --- a/appengine-java21/helloworld/http-server/src/main/appengine/app.yaml +++ b/appengine-java21/helloworld/http-server/src/main/appengine/app.yaml @@ -1,4 +1,4 @@ -# Copyright 2019 Google LLC +# Copyright 2025 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. From f680d7d7ddb80ab9886295cc630c7f58b7d67577 Mon Sep 17 00:00:00 2001 From: manishchaudhari-ssk <86125082+manishchaudhari-ssk@users.noreply.github.com> Date: Mon, 3 Feb 2025 16:47:52 +0530 Subject: [PATCH 4/4] updated copyright year --- .../http-server/src/main/java/com/example/appengine/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appengine-java21/helloworld/http-server/src/main/java/com/example/appengine/Main.java b/appengine-java21/helloworld/http-server/src/main/java/com/example/appengine/Main.java index f6d1b41527d..0b075cd3266 100644 --- a/appengine-java21/helloworld/http-server/src/main/java/com/example/appengine/Main.java +++ b/appengine-java21/helloworld/http-server/src/main/java/com/example/appengine/Main.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 Google LLC + * Copyright 2025 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.