Skip to content

Commit 132317f

Browse files
authored
Merge branch 'master' into move-samples
2 parents dcee1fd + 109a86b commit 132317f

File tree

5 files changed

+26
-8
lines changed
  • appengine-java11
    • appengine-simple-jetty-main/src/main/java/com/example/appengine/demo/jettymain
    • custom-entrypoint
    • http-server/src/main/java/com/example/appengine
    • sparkjava-helloworld/src/main/java/com/example/appengine/sparkdemo
  • speech/cloud-client

5 files changed

+26
-8
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ public static void main(String[] args) throws Exception {
3232
System.setProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.StrErrLog");
3333
System.setProperty("org.eclipse.jetty.LEVEL", "INFO");
3434

35-
// Create a basic Jetty server object that will listen on port 8080.
35+
// Create a basic Jetty server object that will listen on port defined by
36+
// the PORT environment variable when present, otherwise on 8080.
3637
// Note: If you set this to port 0, a randomly available port will be
3738
// assigned. You can find the assigned port in the logs or programmatically
3839
// obtain it.
39-
Server server = new Server(8080);
40+
int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "8080"));
41+
Server server = new Server(port);
4042

4143
// The WebAppContext is the interface to provide configuration for a web
4244
// application. In this example, the context path is being set to "/" so

appengine-java11/custom-entrypoint/Main.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
public class Main {
2424

2525
public static void main(String[] args) throws IOException {
26-
// Create an instance of HttpServer bound to port 8080.
27-
HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0);
26+
// Create an instance of HttpServer bound to port defined by the
27+
// PORT environment variable when present, otherwise on 8080.
28+
int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "8080"));
29+
HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
2830

2931
// Set root URI path.
3032
server.createContext("/", (var t) -> {

appengine-java11/http-server/src/main/java/com/example/appengine/Main.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
public class Main {
2525

2626
public static void main(String[] args) throws IOException {
27-
// Create an instance of HttpServer with port 8080.
28-
HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0);
27+
// Create an instance of HttpServer bound to port defined by the
28+
// PORT environment variable when present, otherwise on 8080.
29+
int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "8080"));
30+
HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
2931

3032
// Set root URI path.
3133
server.createContext("/", (var t) -> {

appengine-java11/sparkjava-helloworld/src/main/java/com/example/appengine/sparkdemo/Main.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
public class Main {
2222

2323
public static void main(String[] args) {
24-
// Starts the webapp on localhost:8080.
25-
Spark.port(8080);
24+
// Starts the webapp on localhost and the port defined by the PORT
25+
// environment variable when present, otherwise on 8080.
26+
int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "8080"));
27+
Spark.port(port);
2628
Spark.get("/", (req, res) -> "Hello World!");
2729
}
2830
}

speech/cloud-client/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ using the [Google Cloud Client Library for Java][google-cloud-java].
1414

1515
## Setup
1616

17+
Before you begin, complete the following steps as listed on the [Speech-to-Text Docs pages for Getting Started](https://cloud.google.com/speech-to-text/docs/quickstart-client-libraries#before-you-begin)
18+
* Create or select a project.
19+
* Enable the Google Speech-to-Text API for that project.
20+
* Create a service account.
21+
* Download a private key as JSON.
22+
* Set `GOOGLE_APPLICATION_CREDENTIALS`
23+
```
24+
export GOOGLE_APPLICATION_CREDENTIALS=path_to_your_downloaded_json_file
25+
```
26+
1727
Install [Maven](http://maven.apache.org/).
1828

1929
Build your project with:

0 commit comments

Comments
 (0)