Skip to content

Commit

Permalink
Make getProjectId() supports GAE (#1726)
Browse files Browse the repository at this point in the history
  • Loading branch information
shinfan authored Mar 13, 2017
1 parent 3919d63 commit 7a310c4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
33 changes: 33 additions & 0 deletions APPENGINE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Use Google Cloud Java Client with Google App Engine
=================================================

Quickstart
----------
This file provides extra instructions to set up Google Cloud Java Client with Google App Engine.

See [Google Cloud JavaQuickstart](./README.md#quickstart) for general instructions on using Google Cloud Java.

See [Quickstart for App Engine Standard Environment for Java](https://cloud.google.com/appengine/docs/standard/java/quickstart) for extra Google App Engine instructions.

If you are using Maven, add this to your pom.xml file
```xml
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>1.9.50</version>
</dependency>
```

If you are using Gradle, add this to your dependencies
```Groovy
compile 'com.google.appengine:appengine-api-1.0-sdk:1.9.50'
```
If you are using SBT, add this to your dependencies
```Scala
libraryDependencies += "com.google.appengine" % "appengine-api-1.0-sdk" % "1.9.50"
```

To test with local dev server, run
```
mvn appengine:devserver
```
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ If you are using SBT, add this to your dependencies
libraryDependencies += "com.google.cloud" % "google-cloud" % "0.9.4-alpha"
```

For running on Google App Engine, see [more instructions here](./APPENGINE.md).

Example Applications
--------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,17 @@ protected static String getAppEngineProjectId() {
String serviceAccountName = (String) method.invoke(appIdentityService);
int indexOfAtSign = serviceAccountName.indexOf('@');
return serviceAccountName.substring(0, indexOfAtSign);
} catch (ClassNotFoundException exception) {
if (System.getProperty("com.google.appengine.runtime.version") != null) {
// Could not resolve appengine classes under GAE environment.
throw new RuntimeException("Google App Engine runtime detected "
+ "(the environment variable \"com.google.appengine.runtime.version\" is set), "
+ "but unable to resolve appengine-sdk classes. "
+ "For more details see "
+ "https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/APPENGINE.md");
}
return null;
} catch (Exception ignore) {
// return null if can't determine
return null;
}
}
Expand Down

0 comments on commit 7a310c4

Please sign in to comment.