Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.users.User;
import com.google.auto.value.AutoValue;
import java.util.Date;
import javax.annotation.Nullable;
import org.joda.time.Instant;

import javax.annotation.Nullable;
import java.util.Date;

@AutoValue
public abstract class Greeting {

static Greeting create(Entity entity) {
User user = (User) entity.getProperty("user");
Instant date = new Instant((Date) entity.getProperty("date"));
String content = (String) entity.getProperty("content");
return new AutoValue_Greeting(user, date, content);
return new com.example.appengine.AutoValue_Greeting(user, date, content);
}

@Nullable
Expand Down
6 changes: 6 additions & 0 deletions appengine-java8/mail/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ Copyright 2016 Google Inc.
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>RELEASE</version>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change from RELEASE to the latest version number instead (for all dependencies).

We have a tool that incrementally updates to ensure the samples are working correctly (it's not running for this project because it isn't linked in the main pom.)

<scope>compile</scope>
</dependency>
</dependencies>
<build>
<!-- for hot reload of the web application -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,32 @@
import com.google.appengine.api.mail.BounceNotification;
import com.google.appengine.api.mail.BounceNotificationParser;

import java.io.IOException;
import java.util.logging.Logger;
import javax.mail.MessagingException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.logging.Logger;

public class BounceHandlerServlet extends HttpServlet {

private static final Logger log = Logger.getLogger(BounceHandlerServlet.class.getName());
private static final Logger log = Logger.getLogger(BounceHandlerServletJ8.class.getName());

@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
try {
BounceNotification bounce = BounceNotificationParser.parse(req);
log.warning("Bounced email notification.");
// The following data is available in a BounceNotification object
// bounce.getOriginal().getFrom()
// bounce.getOriginal().getTo()
// bounce.getOriginal().getSubject()
// bounce.getOriginal().getText()
// bounce.getNotification().getFrom()
// bounce.getNotification().getTo()
// bounce.getNotification().getSubject()
// bounce.getNotification().getText()
// ...
// bounce.getOriginal().getFrom()
// bounce.getOriginal().getTo()
// bounce.getOriginal().getSubject()
// bounce.getOriginal().getText()
// bounce.getNotification().getFrom()
// bounce.getNotification().getTo()
// bounce.getNotification().getSubject()
// bounce.getNotification().getText()

} catch (MessagingException e) {
// ...
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
import java.util.regex.Matcher;

// [START example]
public class HandleDiscussionEmail extends MailHandlerBase {
public class HandleDiscussionEmailJ8 extends MailHandlerBaseJ8 {

private static final Logger log = Logger.getLogger(HandleDiscussionEmail.class.getName());
public HandleDiscussionEmail() { super("discuss-(.*)@(.*)"); }
private static final Logger log = Logger.getLogger(HandleDiscussionEmailJ8.class.getName());
public HandleDiscussionEmailJ8() { super("discuss-(.*)@(.*)"); }

@Override
protected boolean processMessage(HttpServletRequest req, HttpServletResponse res)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@
* Base class for handling the filtering of incoming emails in App Engine.
*/
// [START example]
public abstract class MailHandlerBase implements Filter {
public abstract class MailHandlerBaseJ8 implements Filter {

private Pattern pattern = null;

protected MailHandlerBase(String pattern) {
protected MailHandlerBaseJ8(String pattern) {
if (pattern == null || pattern.trim().length() == 0)
{
throw new IllegalArgumentException("Expected non-empty regular expression");
}
this.pattern = Pattern.compile("/_ah/mail/"+pattern);
}

@Override public void init(FilterConfig config) throws ServletException { }
public void init(FilterConfig config) throws ServletException { }

@Override public void destroy() { }
public void destroy() { }

/**
* Process the message. A message will only be passed to this method
Expand All @@ -65,7 +65,6 @@ protected MailHandlerBase(String pattern) {
*/
protected abstract boolean processMessage(HttpServletRequest req, HttpServletResponse res) throws ServletException;

@Override
public void doFilter(ServletRequest sreq, ServletResponse sres, FilterChain chain)
throws IOException, ServletException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MailHandlerServlet extends HttpServlet {
public class MailHandlerServletJ8 extends HttpServlet {

private static final Logger log = Logger.getLogger(MailHandlerServlet.class.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
public class MailServlet extends HttpServlet {
public class MailServletJ8 extends HttpServlet {

@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
Expand Down
6 changes: 3 additions & 3 deletions appengine-java8/mail/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
version="3.1">
<servlet>
<servlet-name>mail</servlet-name>
<servlet-class>com.example.appengine.mail.MailServlet</servlet-class>
<servlet-class>com.example.appengine.mail.MailServletJ8</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>mail</servlet-name>
Expand All @@ -31,7 +31,7 @@
<!-- [START filter_handler] -->
<filter>
<filter-name>HandleDiscussionEmail</filter-name>
<filter-class>com.example.appengine.mail.HandleDiscussionEmail</filter-class>
<filter-class>com.example.appengine.mail.HandleDiscussionEmailJ8</filter-class>
</filter>
<filter-mapping>
<filter-name>HandleDiscussionEmail</filter-name>
Expand Down Expand Up @@ -64,7 +64,7 @@
<!-- [START bounced_mail_servlet] -->
<servlet>
<servlet-name>bouncehandler</servlet-name>
<servlet-class>com.example.appengine.mail.BounceHandlerServlet</servlet-class>
<servlet-class>com.example.appengine.mail.BounceHandlerServletJ8</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>bouncehandler</servlet-name>
Expand Down
76 changes: 75 additions & 1 deletion appengine/datastore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,81 @@
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<groupId>com.example.appengine</groupId>
<dependencies>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.endpoints</groupId>
<artifactId>endpoints-management-control-appengine-all</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-tools-sdk</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.endpoints</groupId>
<artifactId>endpoints-management-control-appengine-all</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value-annotations</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-tools-sdk</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-testing</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-stubs</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
<groupId>com.example.appengine</groupId>
<artifactId>appengine-datastore</artifactId>

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package com.example.appengine;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

abstract class AbstractGuestbookServlet extends HttpServlet {
private final AbstractGuestbook guestbook;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.appengine;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class doesn't seem necessary?


import com.google.appengine.api.users.User;
import com.google.appengine.repackaged.org.joda.time.Instant;

import javax.annotation.Nullable;

public class AutoValue_Greeting extends Greeting {
@Nullable
@Override
public User getUser() {
return null;
}

public AutoValue_Greeting(User user, Instant date, String content) {
super();
}

@Override
public Instant getDate() {
return null;
}

@Override
public String getContent() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.users.User;
import com.google.appengine.repackaged.org.joda.time.Instant;
import com.google.auto.value.AutoValue;
import java.util.Date;

import javax.annotation.Nullable;
import org.joda.time.Instant;
import java.util.Date;

@AutoValue
public abstract class Greeting {
Expand Down
4 changes: 2 additions & 2 deletions appengine/datastore/src/main/java/com/example/time/Clock.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

package com.example.time;

import org.joda.time.Instant;
import com.google.appengine.repackaged.org.joda.time.Instant;

/**
* Provides the current value of "now." To preserve testability, avoid all other libraries that
* access the system clock (whether {@linkplain System#currentTimeMillis directly} or {@linkplain
* org.joda.time.DateTime#DateTime() indirectly}).
* com.google.appengine.repackaged.org.joda.time.DateTime#DateTime() indirectly}).
*
* <p>In production, use the {@link SystemClock} implementation to return the "real" system time. In
* tests, either use {@link com.example.time.testing.FakeClock}, or get an instance from a mocking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.example.time;

import org.joda.time.Instant;
import com.google.appengine.repackaged.org.joda.time.Instant;

/**
* Clock implementation that returns the "real" system time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
package com.example.time.testing;

import com.example.time.Clock;
import com.google.appengine.repackaged.org.joda.time.Instant;
import com.google.appengine.repackaged.org.joda.time.ReadableDuration;
import com.google.appengine.repackaged.org.joda.time.ReadableInstant;

import java.util.concurrent.atomic.AtomicLong;
import org.joda.time.Instant;
import org.joda.time.ReadableDuration;
import org.joda.time.ReadableInstant;

/**
* A Clock that returns a fixed Instant value as the current clock time. The
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@

package com.example.appengine;

import static com.google.common.truth.Truth.assertThat;

import com.example.time.testing.FakeClock;
import com.google.appengine.repackaged.org.joda.time.Instant;
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalServiceTestHelper;
import com.google.appengine.tools.development.testing.LocalUserServiceTestConfig;
import java.util.List;
import org.joda.time.Instant;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.util.List;

import static com.google.common.truth.Truth.assertThat;

/**
* Unit tests for {@link GuestbookStrong}.
*/
Expand Down
Loading