10000 [WIP] Java 11 Region Tags (#1405) · llozano100/java-docs-samples@d3d5ec4 · GitHub
[go: up one dir, main page]

Skip to content

Commit d3d5ec4

Browse files
authored
[WIP] Java 11 Region Tags (GoogleCloudPlatform#1405)
* Guestbook region tags * simple jetty main region tags * rename hello world * fix license * renamed * Fix license * Task region tags * fix errors * Add parent to pom.xml * Add oauth region tags * Update firestore instance * Fix styling * fix exception
1 parent 427bf71 commit d3d5ec4

File tree

27 files changed

+109
-27
lines changed

27 files changed

+109
-27
lines changed

appengine-java11/appengine-simple-jetty-main/src/main/java/com/example/appengine/demo/jettymain/Main.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.example.appengine.demo.jettymain;
1818

19+
// [START gae_java11_server]
1920
import org.eclipse.jetty.server.Server;
2021
import org.eclipse.jetty.webapp.Configuration.ClassList;
2122
import org.eclipse.jetty.webapp.WebAppContext;
@@ -61,3 +62,4 @@ public static void main(String[] args) throws Exception {
6162
server.join();
6263
}
6364
}
65+
// [END gae_java11_server]

appengine-java11/hello-world/Main.java renamed to appengine-java11/custom-entrypoint/Main.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Google Inc.
2+
* Copyright 2019 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
// [START gae_java11_simple_server]
1718
import com.sun.net.httpserver.HttpServer;
1819
import java.io.IOException;
1920
import java.io.OutputStream;
@@ -38,3 +39,4 @@ public static void main(String[] args) throws IOException {
3839
server.start();
3940
}
4041
}
42+
// [END gae_java11_simple_server]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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 gae_java11_custom_entrypoint]
16+
runtime: java11
17+
entrypoint: java Main.java
18+
# [END gae_java11_custom_entrypoint]

appengine-java11/gaeinfo/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
Copyright 2019 Google Inc.
2+
Copyright 2019 Google LLC
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

appengine-java11/gaeinfo/src/main/webapp/WEB-INF/templates/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<!--
33
4-
Copyright 2019 Google Inc.
4+
Copyright 2019 Google LLC
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.

appengine-java11/guestbook-cloud-firestore/pom.xml

Lines changed: 12 additions & 2 deletions
F42D
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@
1919
<groupId>com.example.guestbook</groupId>
2020
<artifactId>guestbook-cloud-firestore</artifactId>
2121

22+
<!--
23+
The parent pom defines common style checks and testing strategies for our samples.
24+
Removing or replacing it should not affect the execution of the samples in anyway.
25+
-->
26+
<parent>
27+
<groupId>com.google.cloud.samples</groupId>
28+
<artifactId>shared-configuration</artifactId>
29+
<version>1.0.11</version>
30+
</parent>
31+
2232
<properties>
2333
<maven.compiler.source>11</maven.compiler.source>
2434
<maven.compiler.target>11</maven.compiler.target>
@@ -36,14 +46,14 @@
3646
<version>1</version>
3747
<scope>provided</scope>
3848
</dependency>
39-
49+
<!-- [START gae_java11_firestore_pom] -->
4050
<dependency>
4151
<groupId>com.google.cloud</groupId>
4252
<artifactId>google-cloud-firestore</artifactId>
4353
<version>0.81.0-beta</version>
4454
<scope>provided</scope>
4555
</dependency>
46-
56+
<!-- [END gae_java11_firestore_pom] -->
4757
<dependency>
4858
<groupId>com.google.guava</groupId>
4959
<artifactId>guava</artifactId>

appengine-java11/guestbook-cloud-firestore/src/main/appengine/app.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14+
# [START gae_java11_firestore_yaml]
1415
runtime: java11
1516
instance_class: F2
1617
entrypoint: 'java -cp * com.example.appengine.demo.jettymain.Main guestbook.war'
18+
# [END gae_java11_firestore_yaml]

appengine-java11/guestbook-cloud-firestore/src/main/java/com/example/guestbook/Greeting.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.example.guestbook;
1818

19-
2019
import com.google.common.base.MoreObjects;
2120
import java.util.Date;
2221
import java.util.HashMap;
@@ -51,6 +50,7 @@ public Greeting(String book, String content, String name) {
5150

5251
/** Save the Greeting in the guestbook */
5352
public void save() {
53+
// [START gae_java11_firestore_greeting]
5454
// Construct a Greeting.
5555
Map<String, Object> greetingData = new HashMap<>();
5656
greetingData.put("date", date);
@@ -59,6 +59,7 @@ public void save() {
5959

6060
// Add Greeting to Guestbook with random id.
6161
book.getBookRef().collection("Greetings").add(greetingData);
62+
// [END gae_java11_firestore_greeting]
6263
}
6364

6465
@Override

appengine-java11/guestbook-cloud-firestore/src/main/java/com/example/guestbook/Guestbook.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,19 @@ public Guestbook(String book) {
4646
// Construct the Guestbook data.
4747
Map<String, Object> bookData = new HashMap<>();
4848
bookData.put("name", this.book);
49-
49+
// [START gae_java11_firestore_book]
5050
// Get Guestbook reference in the collection.
5151
bookRef = getFirestore().collection("Guestbooks").document(this.book);
5252
// Add Guestbook to collection.
5353
bookRef.set(bookData);
54+
// [END gae_java11_firestore_book]
5455
}
5556

5657
public DocumentReference getBookRef() {
5758
return bookRef;
5859
}
5960

61+
// [START gae_java11_firestore_get_greetings]
6062
/** Get greetings for the Guestbook */
6163
public List<Greeting> getGreetings() {
6264
// Initialize a List for Greetings.
@@ -71,12 +73,13 @@ public List<Greeting> getGreetings() {
7173
for (QueryDocumentSnapshot greeting : querySnapshot.getDocuments()) {
7274
greetings.add(greeting.toObject(Greeting.class));
7375
}
74-
} catch (Exception InterruptedException) {
75-
System.out.println("Nothing to query.");
76+
} catch (Exception e) {
77+
System.out.println(e.getMessage());
7678
}
7779

7880
return greetings.build();
7981
}
82+
// [END gae_java11_firestore_get_greetings]
8083

8184
@Override
8285
public boolean equals(Object obj) {

0 commit comments

Comments
 (0)
0