Skip to content

Commit

Permalink
Merge pull request #68 from udacity/gce_update
Browse files Browse the repository at this point in the history
Gce update
  • Loading branch information
dnbit authored Nov 14, 2017
2 parents b0003c8 + fc9de60 commit 248d2a5
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 5 deletions.
15 changes: 11 additions & 4 deletions FinalProject/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ behavior of the Gradle build tool, allowing automation of repetitive tasks.
Particularly, factoring functionality into libraries and creating product
flavors allow for much bigger projects with minimal added complexity.

##What Will I Learn?
## What Will I Learn?

You will learn the role of Gradle in building Android Apps and how to use
Gradle to manage apps of increasing complexity. You'll learn to:
Expand All @@ -26,7 +26,7 @@ Gradle to manage apps of increasing complexity. You'll learn to:
* Use the Gradle App Engine plugin to deploy a backend
* Configure an integration test suite that runs against the local App Engine development server

##How Do I Complete this Project?
## How Do I Complete this Project?

### Step 0: Starting Point

Expand All @@ -41,6 +41,9 @@ https://developers.google.com/mobile-ads-sdk/docs/admob/android/quick-start
You may need to download the Google Repository from the Extras section of the
Android SDK Manager.

You will also notice a folder called backend in the starter code.
It will be used in step 3 below, and you do not need to worry about it for now.

When you can build an deploy this starter code to an emulator, you're ready to
move on.

Expand Down Expand Up @@ -69,8 +72,12 @@ http://developer.android.com/guide/components/intents-filters.html

This next task will be pretty tricky. Instead of pulling jokes directly from
our Java library, we'll set up a Google Cloud Endpoints development server,
and pull our jokes from there. Follow the instructions in the following
tutorial to add a Google Could Endpoints module to your project:
and pull our jokes from there.

The following tutorial explains how to add and use a Google Cloud Endpoints module in
your project. The starter code already includes the module in the folder called backend.
Therefore, you can skip the creation steps in the tutorial and start at section
1.1 *Debugging the backend locally*:

https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/HelloEndpoints

Expand Down
43 changes: 43 additions & 0 deletions FinalProject/backend/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// If you would like more information on the gradle-appengine-plugin please refer to the github page
// https://github.com/GoogleCloudPlatform/gradle-appengine-plugin

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.42'
}
}

repositories {
jcenter();
}

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'

sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7

dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.42'
compile 'com.google.appengine:appengine-endpoints:1.9.42'
compile 'com.google.appengine:appengine-endpoints-deps:1.9.42'
compile 'javax.servlet:servlet-api:2.5'
compile 'com.google.api-client:google-api-client:1.23.0'
compile 'com.google.http-client:google-http-client-android:1.23.0'
}

appengine {
downloadSdk = true
appcfg {
oauth2 = true
}
endpoints {
getClientLibsOnBuild = true
getDiscoveryDocsOnBuild = true
googleClientVersion = '1.23.0'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.udacity.gradle.builditbigger.backend;

/** The object model for the data we are sending through endpoints */
public class MyBean {

private String myData;

public String getData() {
return myData;
}

public void setData(String data) {
myData = data;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
For step-by-step instructions on connecting your Android application to this backend module,
see "App Engine Java Endpoints Module" template documentation at
https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/HelloEndpoints
*/

package com.udacity.gradle.builditbigger.backend;

import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.google.api.server.spi.config.ApiNamespace;

import javax.inject.Named;

/** An endpoint class we are exposing */
@Api(
name = "myApi",
version = "v1",
namespace = @ApiNamespace(
ownerDomain = "backend.builditbigger.gradle.udacity.com",
ownerName = "backend.builditbigger.gradle.udacity.com",
packagePath = ""
)
)
public class MyEndpoint {

/** A simple endpoint method that takes a name and says Hi back */
@ApiMethod(name = "sayHi")
public MyBean sayHi(@Named("name") String name) {
MyBean response = new MyBean();
response.setData("Hi, " + name);

return response;
}

}
10 changes: 10 additions & 0 deletions FinalProject/backend/src/main/webapp/WEB-INF/appengine-web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>myApplicationId</application>
<version>1</version>
<threadsafe>true</threadsafe>

<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
</system-properties>
</appengine-web-app>
13 changes: 13 additions & 0 deletions FinalProject/backend/src/main/webapp/WEB-INF/logging.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# A default java.util.logging configuration.
# (All App Engine logging is through java.util.logging by default).
#
# To use this configuration, copy it into your application's WEB-INF
# folder and add the following to your appengine-web.xml:
#
# <system-properties>
# <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
# </system-properties>
#

# Set the default logging level for all loggers to WARNING
.level = WARNING
19 changes: 19 additions & 0 deletions FinalProject/backend/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
<servlet>
<servlet-name>SystemServiceServlet</servlet-name>
<servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value>com.udacity.gradle.builditbigger.backend.MyEndpoint</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SystemServiceServlet</servlet-name>
<url-pattern>/_ah/spi/*</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
136 changes: 136 additions & 0 deletions FinalProject/backend/src/main/webapp/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<!DOCTYPE html>
<html>
<head>
<title>Hello, Endpoints!</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<link rel="stylesheet"
href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
</head>
<body role="document" style="padding-top: 70px;">
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">Hello, Endpoints!</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Documentation <b
class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="https://developers.google.com/appengine/docs/java/">Google App
Engine</a></li>
<li><a href="https://developers.google.com/appengine/docs/java/endpoints/">Google
Cloud Endpoints</a></li>
<li>
<a href="https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/HelloEndpoints">Connecting
your Android application to this backend</a></li>
</ul>
</li>
<li><a href="/_ah/api/explorer">Google Cloud Endpoints API Explorer</a></li>
<li><a href="https://console.developers.google.com">Google Developers Console</a>
</li>
</ul>
</div>
</div>
</div>

<div class="container theme-showcase" role="main">
<!--
Output from Endpoints API call.
-->
<div class="alert alert-success" style="visibility: collapse;" id="outputAlert"></div>

<!--
A form that takes a text value and submits it to the Endpoint,
access to the Endpoint is enabled once the client is loaded below.
-->
<div class="jumbotron">
<div class="row">
<div class="col-lg-12">
<h1>Hello, Endpoints!</h1>
<p>Enter your name and press the button below to call your Google Cloud Endpoints
API.</p>
<form>
<div class="input-group">
<input type="text" class="form-control input-lg" placeholder="Name"
id="nameInput"/>
<span class="input-group-btn">
<button class="btn btn-default btn-primary btn-group btn-lg"
type="submit" id="helloButton">Say "Hello" &raquo;</button>
</span>
</div>
</form>
<br/>
<p>If you need step-by-step instructions for connecting your Android application to
this backend module, see <a
href="https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/HelloEndpoints">"App
Engine Java Endpoints Module" template documentation</a>.</p>
<p>
<small>
For more information about Google App Engine for Java, check out the <a
href="https://developers.google.com/appengine/docs/java/">App Engine
documentation</a>.<br/>
To learn more about Google Cloud Endpoints, see <a
href="https://developers.google.com/appengine/docs/java/endpoints/">Cloud
Endpoints documentation</a>.<br/>
If you'd like to access your generated Google Cloud Endpoints APIs directly,
see the <a href="/_ah/api/explorer">Cloud Endpoints API Explorer</a>.
</small>
</p>
</div>
</div>
</div>
</div>

<script type="text/javascript">
// A function that attaches a "Say Hello" button click handler
function enableClick() {
document.getElementById('helloButton').onclick = function() {
var name = document.getElementById('nameInput').value;
gapi.client.myApi.sayHi({'name': name}).execute(
function(response) {
var outputAlertDiv = document.getElementById('outputAlert');
outputAlertDiv.style.visibility = 'visible';

if (!response.error) {
outputAlertDiv.className = 'alert alert-success';
outputAlertDiv.innerHTML = '<h2>' + response.result.data + '</h2>';
}
else if (response.error) {
outputAlertDiv.className = 'alert alert-danger';
outputAlertDiv.innerHTML = '<b>Error Code: </b>' + response.error.code + ' [' + response.error.message + ']';
}
}
);
return false;
}
}
// This is called initially
function init() {
var apiName = 'myApi';
var apiVersion = 'v1';
var apiRoot = 'https://' + window.location.host + '/_ah/api';
if (window.location.hostname == 'localhost'
|| window.location.hostname == '127.0.0.1'
|| ((window.location.port != "") && (window.location.port > 1023))) {
// We're probably running against the DevAppServer
apiRoot = 'http://' + window.location.host + '/_ah/api';
}
var callback = function() {
enableClick();
}
gapi.client.load(apiName, apiVersion, callback, apiRoot);
}

</script>
<!--
Load the Google APIs Client Library for JavaScript
More info here : https://developers.google.com/api-client-library/javascript/reference/referencedocs
-->

<script src="https://apis.google.com/js/client.js?onload=init"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion FinalProject/settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':app'
include ':app', ':backend'

0 comments on commit 248d2a5

Please sign in to comment.