-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Oauth2 updates, Guestbook #172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d834576
appengine/oauth2 sample
1b008aa
check style helping too much.
e110bb3
More check style goodness.
26167f2
Oauth2 updates, Guestbook
0ecd6c9
Merge branch 'master' into oauth2
bd07693
Add logs back in.
64d5903
Check style changes
27fa06e
rename guestbook -> guestbook-objectify
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# appengine/guestbook-objectify | ||
|
||
An App Engine guestbook using Java, Maven, and Objectify. | ||
|
||
Data access using [Objectify](https://github.com/objectify/objectify) | ||
|
||
Please ask questions on [Stackoverflow](http://stackoverflow.com/questions/tagged/google-app-engine) | ||
|
||
## Running Locally | ||
|
||
How do I, as a developer, start working on the project? | ||
|
||
1. `mvn clean appengine:devserver` | ||
|
||
## Deploying | ||
|
||
1. `mvn clean appengine:update -Dappengine.appId=PROJECT -Dappengine.version=VERSION` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<packaging>war</packaging> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<groupId>com.example.appengine</groupId> | ||
<artifactId>guestbook</artifactId> | ||
<properties> | ||
<objectify.version>5.1.5</objectify.version> | ||
<guava.version>18.0</guava.version> | ||
</properties> | ||
<parent> | ||
<groupId>com.google.cloud</groupId> | ||
<artifactId>doc-samples</artifactId> | ||
<version>1.0.0</version> | ||
<relativePath>../..</relativePath> | ||
</parent> | ||
|
||
<!-- [START set_versions] --> | ||
<prerequisites> | ||
<maven>3.3.9</maven> | ||
</prerequisites> | ||
<!-- [END set_versions] --> | ||
|
||
<dependencies> | ||
<!-- Compile/runtime dependencies --> | ||
<dependency> | ||
<groupId>com.google.appengine</groupId> | ||
<artifactId>appengine-api-1.0-sdk</artifactId> | ||
<version>${appengine.sdk.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>servlet-api</artifactId> | ||
<version>2.5</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>jstl</groupId> | ||
<artifactId>jstl</artifactId> | ||
<version>1.2</version> | ||
</dependency> | ||
|
||
<!-- [START Objectify_Dependencies] --> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
<version>${guava.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.googlecode.objectify</groupId> | ||
<artifactId>objectify</artifactId> | ||
<version>${objectify.version}</version> | ||
</dependency> | ||
<!-- [END Objectify_Dependencies] --> | ||
|
||
<!-- Test Dependencies --> | ||
<dependency> | ||
<groupId>com.google.appengine</groupId> | ||
<artifactId>appengine-testing</artifactId> | ||
<version>${appengine.sdk.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.appengine</groupId> | ||
<artifactId>appengine-api-stubs</artifactId> | ||
<version>${appengine.sdk.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<!-- for hot reload of the web application--> | ||
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.google.appengine</groupId> | ||
<artifactId>appengine-maven-plugin</artifactId> | ||
<version>${appengine.sdk.version}</version> | ||
<configuration> | ||
<enableJarClasses>false</enableJarClasses> | ||
<!-- Comment in the below snippet to bind to all IPs instead of just localhost --> | ||
<!-- address>0.0.0.0</address> | ||
<port>8080</port --> | ||
<!-- Comment in the below snippet to enable local debugging with a remote debugger | ||
like those included with Eclipse or IntelliJ --> | ||
<!-- jvmFlags> | ||
<jvmFlag>-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n</jvmFlag> | ||
</jvmFlags --> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
80 changes: 80 additions & 0 deletions
80
appengine/guestbook-objectify/src/main/java/com/example/guestbook/Greeting.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* Copyright 2014-2015 Google Inc. All Rights Reserved. | ||
* | ||
* 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 all] | ||
package com.example.guestbook; | ||
|
||
import com.googlecode.objectify.Key; | ||
import com.googlecode.objectify.annotation.Entity; | ||
import com.googlecode.objectify.annotation.Id; | ||
import com.googlecode.objectify.annotation.Index; | ||
import com.googlecode.objectify.annotation.Parent; | ||
|
||
import java.lang.String; | ||
import java.util.Date; | ||
|
||
/** | ||
* The @Entity tells Objectify about our entity. We also register it in {@link OfyHelper} | ||
* Our primary key @Id is set automatically by the Google Datastore for us. | ||
* | ||
* We add a @Parent to tell the object about its ancestor. We are doing this to support many | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing |
||
* guestbooks. Objectify, unlike the AppEngine library requires that you specify the fields you | ||
* want to index using @Index. Only indexing the fields you need can lead to substantial gains in | ||
* performance -- though if not indexing your data from the start will require indexing it later. | ||
* | ||
* NOTE - all the properties are PUBLIC so that can keep the code simple. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing |
||
**/ | ||
@Entity | ||
public class Greeting { | ||
@Parent Key<Guestbook> theBook; | ||
@Id public Long id; | ||
|
||
public String authorEmail; | ||
public String authorId; | ||
public String content; | ||
@Index public Date date; | ||
|
||
/** | ||
* Simple constructor just sets the date. | ||
**/ | ||
public Greeting() { | ||
date = new Date(); | ||
} | ||
|
||
/** | ||
* A convenience constructor. | ||
**/ | ||
public Greeting(String book, String content) { | ||
this(); | ||
if ( book != null ) { | ||
theBook = Key.create(Guestbook.class, book); // Creating the Ancestor key | ||
} else { | ||
theBook = Key.create(Guestbook.class, "default"); | ||
} | ||
this.content = content; | ||
} | ||
|
||
/** | ||
* Takes all important fields. | ||
**/ | ||
public Greeting(String book, String content, String id, String email) { | ||
this(book, content); | ||
authorEmail = email; | ||
authorId = id; | ||
} | ||
|
||
} | ||
//[END all] |
33 changes: 33 additions & 0 deletions
33
appengine/guestbook-objectify/src/main/java/com/example/guestbook/Guestbook.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Copyright 2014-2015 Google Inc. All Rights Reserved. | ||
* | ||
* 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 all] | ||
package com.example.guestbook; | ||
|
||
import com.googlecode.objectify.annotation.Entity; | ||
import com.googlecode.objectify.annotation.Id; | ||
|
||
/** | ||
* The @Entity tells Objectify about our entity. We also register it in | ||
* OfyHelper.java -- very important. | ||
* | ||
* This is never actually created, but gives a hint to Objectify about our Ancestor key. | ||
*/ | ||
@Entity | ||
public class Guestbook { | ||
@Id public String book; | ||
} | ||
//[END all] |
37 changes: 37 additions & 0 deletions
37
appengine/guestbook-objectify/src/main/java/com/example/guestbook/OfyHelper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Copyright 2014-2015 Google Inc. All Rights Reserved. | ||
* | ||
* 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 all] | ||
package com.example.guestbook; | ||
|
||
import com.googlecode.objectify.ObjectifyService; | ||
|
||
import javax.servlet.ServletContextEvent; | ||
import javax.servlet.ServletContextListener; | ||
|
||
/** | ||
* OfyHelper, a ServletContextListener, is setup in web.xml to run before a JSP is run. This is | ||
* required to let JSP's access Ofy. | ||
**/ | ||
public class OfyHelper implements ServletContextListener { | ||
public void contextInitialized(ServletContextEvent event) { | ||
// This will be invoked as part of a warmup request, or the first user request if no warmup | ||
// request. | ||
ObjectifyService.register(Guestbook.class); | ||
ObjectifyService.register(Greeting.class); | ||
} | ||
|
||
public void contextDestroyed(ServletContextEvent event) { | ||
// App Engine does not currently invoke this method. | ||
} | ||
} | ||
//[END all] |
62 changes: 62 additions & 0 deletions
62
appengine/guestbook-objectify/src/main/java/com/example/guestbook/SignGuestbookServlet.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Copyright 2014-2015 Google Inc. All Rights Reserved. | ||
* | ||
* 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 all] | ||
package com.example.guestbook; | ||
|
||
import com.google.appengine.api.users.User; | ||
import com.google.appengine.api.users.UserService; | ||
import com.google.appengine.api.users.UserServiceFactory; | ||
|
||
import com.googlecode.objectify.ObjectifyService; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
/** | ||
* Form Handling Servlet - most of the action for this sample is in webapp/guestbook.jsp, | ||
* which displays the {@link Greeting}'s. | ||
*/ | ||
public class SignGuestbookServlet extends HttpServlet { | ||
|
||
// Process the http POST of the form | ||
@Override | ||
public void doPost(HttpServletRequest req, HttpServletResponse resp) | ||
throws IOException { | ||
Greeting greeting; | ||
|
||
UserService userService = UserServiceFactory.getUserService(); | ||
User user = userService.getCurrentUser(); // Find out who the user is. | ||
|
||
String guestbookName = req.getParameter("guestbookName"); | ||
String content = req.getParameter("content"); | ||
if (user != null) { | ||
greeting = new Greeting(guestbookName, content, user.getUserId(), user.getEmail()); | ||
} else { | ||
greeting = new Greeting(guestbookName, content); | ||
} | ||
|
||
// Use Objectify to save the greeting and now() is used to make the call synchronously as we | ||
// will immediately get a new page using redirect and we want the data to be present. | ||
ObjectifyService.ofy().save().entity(greeting).now(); | ||
|
||
resp.sendRedirect("/guestbook.jsp?guestbookName=" + guestbookName); | ||
} | ||
} | ||
//[END all] |
10 changes: 10 additions & 0 deletions
10
appengine/guestbook-objectify/src/main/webapp/WEB-INF/appengine-web.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>your-app-id</application> | ||
<version>${appengine.app.version}</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
13
appengine/guestbook-objectify/src/main/webapp/WEB-INF/logging.properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
35 changes: 35 additions & 0 deletions
35
appengine/guestbook-objectify/src/main/webapp/WEB-INF/web.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> | ||
|
||
<!-- [START standard_mappings] --> | ||
<servlet> | ||
<servlet-name>sign</servlet-name> | ||
<servlet-class>com.example.guestbook.SignGuestbookServlet</servlet-class> | ||
</servlet> | ||
|
||
<servlet-mapping> | ||
<servlet-name>sign</servlet-name> | ||
<url-pattern>/sign</url-pattern> | ||
</servlet-mapping> | ||
|
||
<welcome-file-list> | ||
<welcome-file>guestbook.jsp</welcome-file> | ||
</welcome-file-list> | ||
<!-- [END standard_mappings] --> | ||
|
||
<!-- [START Objectify] --> | ||
<filter> | ||
<filter-name>ObjectifyFilter</filter-name> | ||
<filter-class>com.googlecode.objectify.ObjectifyFilter</filter-class> | ||
</filter> | ||
<filter-mapping> | ||
<filter-name>ObjectifyFilter</filter-name> | ||
<url-pattern>/*</url-pattern> | ||
</filter-mapping> | ||
<listener> | ||
<listener-class>com.example.guestbook.OfyHelper</listener-class> | ||
</listener> | ||
<!-- [END Objectify] --> | ||
</web-app> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
License Header.
Also, xmlns attributes are optional, so can be removed.