From a0f38fa8109a119638e067528429a2e484405945 Mon Sep 17 00:00:00 2001 From: Les Vogel Date: Sun, 21 May 2017 20:06:21 -0700 Subject: [PATCH] web.xml and Annotations (#672) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * web.xml and Annotations 1. Upgrade all web.xml to 3.1 2. Add annotations 3. Hello World is old, remove this one. * Fix check style * strike unittests 1. things stopped working, so I took them out. I’ll try to put them back later, but they are just a copy from the root. --- .../appengine/analytics/AnalyticsServlet.java | 3 + .../analytics/src/main/webapp/WEB-INF/web.xml | 19 ++-- .../appidentity/IdentityServlet.java | 3 + .../appidentity/SignForAppServlet.java | 8 +- .../appidentity/UrlShortenerServlet.java | 3 + .../src/main/webapp/WEB-INF/web.xml | 35 ++----- .../bigtable/src/main/webapp/WEB-INF/web.xml | 2 +- .../main/webapp/{index.jsp => bigtable.jsp} | 0 .../appengine/cloudsql/CloudSqlServlet.java | 3 + .../cloudsql/src/main/webapp/WEB-INF/web.xml | 20 ++-- .../src/main/webapp/WEB-INF/web.xml | 9 +- .../src/main/webapp/WEB-INF/web.xml | 9 +- .../indexes/src/main/webapp/WEB-INF/web.xml | 9 +- .../datastore/src/main/webapp/WEB-INF/web.xml | 9 +- .../backend/src/main/webapp/WEB-INF/web.xml | 6 +- .../src/main/webapp/WEB-INF/web.xml | 7 +- .../src/main/webapp/WEB-INF/web.xml | 7 +- .../src/main/webapp/WEB-INF/web.xml | 9 +- .../src/main/webapp/WEB-INF/web.xml | 22 ++++- .../src/main/webapp/WEB-INF/web.xml | 22 ++++- appengine-java8/helloworld/README.md | 18 ---- appengine-java8/helloworld/jenkins.sh | 21 ----- appengine-java8/helloworld/pom.xml | 54 ----------- .../appengine/helloworld/HelloServlet.java | 36 ------- .../src/main/webapp/WEB-INF/appengine-web.xml | 19 ---- .../src/main/webapp/WEB-INF/web.xml | 14 --- .../images/src/main/webapp/WEB-INF/web.xml | 24 ++++- .../logs/src/main/webapp/WEB-INF/web.xml | 34 +++---- .../mail/src/main/webapp/WEB-INF/web.xml | 32 ++++--- .../mailgun/src/main/webapp/WEB-INF/web.xml | 34 +++---- .../mailjet/src/main/webapp/WEB-INF/web.xml | 34 +++---- .../memcache/src/main/webapp/WEB-INF/web.xml | 34 +++---- .../src/main/webapp/WEB-INF/web.xml | 23 ++++- .../oauth2/src/main/webapp/WEB-INF/web.xml | 24 ++++- appengine-java8/pom.xml | 4 - .../src/main/webapp/WEB-INF/web.xml | 34 +++---- .../requests/src/main/webapp/WEB-INF/web.xml | 24 ++++- appengine-java8/search/pom.xml | 2 - .../search/src/main/webapp/WEB-INF/web.xml | 24 ++++- .../sendgrid/src/main/webapp/WEB-INF/web.xml | 34 +++---- .../deferred/src/main/webapp/WEB-INF/web.xml | 30 +++--- .../pull/src/main/webapp/WEB-INF/web.xml | 34 +++---- .../push/src/main/webapp/WEB-INF/web.xml | 10 +- .../twilio/src/main/webapp/WEB-INF/web.xml | 34 +++---- appengine-java8/unittests/README.md | 9 -- appengine-java8/unittests/pom.xml | 94 ------------------- .../src/main/webapp/WEB-INF/appengine-web.xml | 9 -- .../main/webapp/WEB-INF/logging.properties | 13 --- .../src/main/webapp/WEB-INF/queue.xml | 10 -- .../unittests/src/main/webapp/WEB-INF/web.xml | 7 -- .../appengine/samples/AuthenticationTest.java | 54 ----------- .../appengine/samples/DeferredTaskTest.java | 76 --------------- ...LocalCustomPolicyHighRepDatastoreTest.java | 81 ---------------- .../appengine/samples/LocalDatastoreTest.java | 70 -------------- .../samples/LocalHighRepDatastoreTest.java | 66 ------------- .../appengine/samples/LocalMemcacheTest.java | 72 -------------- .../appengine/samples/LocalUrlFetchTest.java | 77 --------------- .../google/appengine/samples/MyFirstTest.java | 31 ------ .../google/appengine/samples/ShortTest.java | 59 ------------ .../samples/TaskQueueConfigTest.java | 75 --------------- .../appengine/samples/TaskQueueTest.java | 73 -------------- .../example/appengine/UrlFetchServlet.java | 12 ++- .../urlfetch/src/main/webapp/WEB-INF/web.xml | 35 ++++--- .../webapp/{main.jsp => urlfetchresult.jsp} | 0 .../example/appengine/users/UsersServlet.java | 3 + .../users/src/main/webapp/WEB-INF/web.xml | 35 ++++--- 66 files changed, 459 insertions(+), 1338 deletions(-) rename appengine-java8/bigtable/src/main/webapp/{index.jsp => bigtable.jsp} (100%) delete mode 100644 appengine-java8/helloworld/README.md delete mode 100644 appengine-java8/helloworld/jenkins.sh delete mode 100644 appengine-java8/helloworld/pom.xml delete mode 100644 appengine-java8/helloworld/src/main/java/com/example/appengine/helloworld/HelloServlet.java delete mode 100644 appengine-java8/helloworld/src/main/webapp/WEB-INF/appengine-web.xml delete mode 100644 appengine-java8/helloworld/src/main/webapp/WEB-INF/web.xml delete mode 100644 appengine-java8/unittests/README.md delete mode 100644 appengine-java8/unittests/pom.xml delete mode 100644 appengine-java8/unittests/src/main/webapp/WEB-INF/appengine-web.xml delete mode 100644 appengine-java8/unittests/src/main/webapp/WEB-INF/logging.properties delete mode 100644 appengine-java8/unittests/src/main/webapp/WEB-INF/queue.xml delete mode 100644 appengine-java8/unittests/src/main/webapp/WEB-INF/web.xml delete mode 100644 appengine-java8/unittests/src/test/java/com/google/appengine/samples/AuthenticationTest.java delete mode 100644 appengine-java8/unittests/src/test/java/com/google/appengine/samples/DeferredTaskTest.java delete mode 100644 appengine-java8/unittests/src/test/java/com/google/appengine/samples/LocalCustomPolicyHighRepDatastoreTest.java delete mode 100644 appengine-java8/unittests/src/test/java/com/google/appengine/samples/LocalDatastoreTest.java delete mode 100644 appengine-java8/unittests/src/test/java/com/google/appengine/samples/LocalHighRepDatastoreTest.java delete mode 100644 appengine-java8/unittests/src/test/java/com/google/appengine/samples/LocalMemcacheTest.java delete mode 100644 appengine-java8/unittests/src/test/java/com/google/appengine/samples/LocalUrlFetchTest.java delete mode 100644 appengine-java8/unittests/src/test/java/com/google/appengine/samples/MyFirstTest.java delete mode 100644 appengine-java8/unittests/src/test/java/com/google/appengine/samples/ShortTest.java delete mode 100644 appengine-java8/unittests/src/test/java/com/google/appengine/samples/TaskQueueConfigTest.java delete mode 100644 appengine-java8/unittests/src/test/java/com/google/appengine/samples/TaskQueueTest.java rename appengine-java8/urlfetch/src/main/webapp/{main.jsp => urlfetchresult.jsp} (100%) diff --git a/appengine-java8/analytics/src/main/java/com/example/appengine/analytics/AnalyticsServlet.java b/appengine-java8/analytics/src/main/java/com/example/appengine/analytics/AnalyticsServlet.java index 4fd2d6186b6..702580ba3b0 100644 --- a/appengine-java8/analytics/src/main/java/com/example/appengine/analytics/AnalyticsServlet.java +++ b/appengine-java8/analytics/src/main/java/com/example/appengine/analytics/AnalyticsServlet.java @@ -27,12 +27,15 @@ import java.net.URL; import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; // [START example] @SuppressWarnings("serial") +@WebServlet(name = "analytics", description = "Analytics: Send Analytics Event to Google Analytics", + urlPatterns = "/analytics") public class AnalyticsServlet extends HttpServlet { @Override diff --git a/appengine-java8/analytics/src/main/webapp/WEB-INF/web.xml b/appengine-java8/analytics/src/main/webapp/WEB-INF/web.xml index cb3033ed531..074cd62c393 100644 --- a/appengine-java8/analytics/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/analytics/src/main/webapp/WEB-INF/web.xml @@ -13,17 +13,12 @@ limitations under the License. --> - - - analytics - com.example.appengine.analytics.AnalyticsServlet - - - analytics - / - + + + analytics + diff --git a/appengine-java8/appidentity/src/main/java/com/example/appengine/appidentity/IdentityServlet.java b/appengine-java8/appidentity/src/main/java/com/example/appengine/appidentity/IdentityServlet.java index d9d72a704c9..64016262140 100644 --- a/appengine-java8/appidentity/src/main/java/com/example/appengine/appidentity/IdentityServlet.java +++ b/appengine-java8/appidentity/src/main/java/com/example/appengine/appidentity/IdentityServlet.java @@ -20,11 +20,14 @@ import java.io.IOException; +import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @SuppressWarnings("serial") +@WebServlet(name = "appidentity", description = "AppIdentity: Get the Host Name", + urlPatterns = "/appidentity/identity") public class IdentityServlet extends HttpServlet { // [START versioned_hostnames] diff --git a/appengine-java8/appidentity/src/main/java/com/example/appengine/appidentity/SignForAppServlet.java b/appengine-java8/appidentity/src/main/java/com/example/appengine/appidentity/SignForAppServlet.java index 3a9df0301fe..fabbcd0fa02 100644 --- a/appengine-java8/appidentity/src/main/java/com/example/appengine/appidentity/SignForAppServlet.java +++ b/appengine-java8/appidentity/src/main/java/com/example/appengine/appidentity/SignForAppServlet.java @@ -33,13 +33,17 @@ import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.util.Arrays; +import java.util.Calendar; import java.util.Collection; +import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @SuppressWarnings("serial") +@WebServlet(name = "signforapp", description = "AppIdentity: Sign 'abcdefg'", + urlPatterns = "/appidentity/sign") public class SignForAppServlet extends HttpServlet { private final AppIdentityService appIdentity; @@ -79,9 +83,9 @@ private boolean verifySignature(byte[] blob, byte[] blobSignature, PublicKey pk) private String simulateIdentityAssertion() throws CertificateException, UnsupportedEncodingException, NoSuchAlgorithmException, - InvalidKeyException, SignatureException { + InvalidKeyException, SignatureException { // Simulate the sending app. - String message = "abcdefg"; + String message = "abcdefg " + Calendar.getInstance().getTime().toString(); byte[] blob = message.getBytes(); byte[] blobSignature = signBlob(blob); byte[] publicCert = getPublicCertificate(); diff --git a/appengine-java8/appidentity/src/main/java/com/example/appengine/appidentity/UrlShortenerServlet.java b/appengine-java8/appidentity/src/main/java/com/example/appengine/appidentity/UrlShortenerServlet.java index 324b8dcd0a1..7c8b1e66d89 100644 --- a/appengine-java8/appidentity/src/main/java/com/example/appengine/appidentity/UrlShortenerServlet.java +++ b/appengine-java8/appidentity/src/main/java/com/example/appengine/appidentity/UrlShortenerServlet.java @@ -19,11 +19,14 @@ import java.io.IOException; import java.io.PrintWriter; +import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @SuppressWarnings("serial") +@WebServlet(name = "UrlShortener", description = "AppIdentity: Url Shortener", + urlPatterns = "/appidentity/shorten") public class UrlShortenerServlet extends HttpServlet { private final UrlShortener shortener; diff --git a/appengine-java8/appidentity/src/main/webapp/WEB-INF/web.xml b/appengine-java8/appidentity/src/main/webapp/WEB-INF/web.xml index 3296a0799f4..d07ac01365d 100644 --- a/appengine-java8/appidentity/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/appidentity/src/main/webapp/WEB-INF/web.xml @@ -1,30 +1,9 @@ - - - appidentity - com.example.appengine.appidentity.IdentityServlet - - - signforapp - com.example.appengine.appidentity.SignForAppServlet - - - urlshortener - com.example.appengine.appidentity.UrlShortenerServlet - - - appidentity - / - - - signforapp - /sign - - - urlshortener - /shorten - + + + appidentity/identity + diff --git a/appengine-java8/bigtable/src/main/webapp/WEB-INF/web.xml b/appengine-java8/bigtable/src/main/webapp/WEB-INF/web.xml index 66495223908..a830b6cf933 100644 --- a/appengine-java8/bigtable/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/bigtable/src/main/webapp/WEB-INF/web.xml @@ -21,7 +21,7 @@ limitations under the License. version="3.1"> - index.jsp + bigtable.jsp BIGTABLE_PROJECT diff --git a/appengine-java8/bigtable/src/main/webapp/index.jsp b/appengine-java8/bigtable/src/main/webapp/bigtable.jsp similarity index 100% rename from appengine-java8/bigtable/src/main/webapp/index.jsp rename to appengine-java8/bigtable/src/main/webapp/bigtable.jsp diff --git a/appengine-java8/cloudsql/src/main/java/com/example/appengine/cloudsql/CloudSqlServlet.java b/appengine-java8/cloudsql/src/main/java/com/example/appengine/cloudsql/CloudSqlServlet.java index 9e09fbede8e..97c5e60c7f3 100644 --- a/appengine-java8/cloudsql/src/main/java/com/example/appengine/cloudsql/CloudSqlServlet.java +++ b/appengine-java8/cloudsql/src/main/java/com/example/appengine/cloudsql/CloudSqlServlet.java @@ -30,12 +30,15 @@ import java.util.Date; import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; // [START example] @SuppressWarnings("serial") +@WebServlet(name = "CloudSQL", description = "CloudSQL: Write low order IP address to Cloud SQL", + urlPatterns = "/cloudsql") public class CloudSqlServlet extends HttpServlet { @Override diff --git a/appengine-java8/cloudsql/src/main/webapp/WEB-INF/web.xml b/appengine-java8/cloudsql/src/main/webapp/WEB-INF/web.xml index 2f5b0dfbd32..11d86d4034b 100644 --- a/appengine-java8/cloudsql/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/cloudsql/src/main/webapp/WEB-INF/web.xml @@ -13,16 +13,12 @@ limitations under the License. --> - - - cloudsql - com.example.appengine.cloudsql.CloudSqlServlet - - - cloudsql - / - + + + cloudsql + diff --git a/appengine-java8/datastore/indexes-exploding/src/main/webapp/WEB-INF/web.xml b/appengine-java8/datastore/indexes-exploding/src/main/webapp/WEB-INF/web.xml index 6af27edbd87..0be42c36f0c 100644 --- a/appengine-java8/datastore/indexes-exploding/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/datastore/indexes-exploding/src/main/webapp/WEB-INF/web.xml @@ -14,10 +14,11 @@ See the License for the specific language governing permissions and limitations under the License. --> - + indexes-servlet com.example.appengine.IndexesServlet diff --git a/appengine-java8/datastore/indexes-perfect/src/main/webapp/WEB-INF/web.xml b/appengine-java8/datastore/indexes-perfect/src/main/webapp/WEB-INF/web.xml index 6af27edbd87..0be42c36f0c 100644 --- a/appengine-java8/datastore/indexes-perfect/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/datastore/indexes-perfect/src/main/webapp/WEB-INF/web.xml @@ -14,10 +14,11 @@ See the License for the specific language governing permissions and limitations under the License. --> - + indexes-servlet com.example.appengine.IndexesServlet diff --git a/appengine-java8/datastore/indexes/src/main/webapp/WEB-INF/web.xml b/appengine-java8/datastore/indexes/src/main/webapp/WEB-INF/web.xml index 6af27edbd87..0be42c36f0c 100644 --- a/appengine-java8/datastore/indexes/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/datastore/indexes/src/main/webapp/WEB-INF/web.xml @@ -14,10 +14,11 @@ See the License for the specific language governing permissions and limitations under the License. --> - + indexes-servlet com.example.appengine.IndexesServlet diff --git a/appengine-java8/datastore/src/main/webapp/WEB-INF/web.xml b/appengine-java8/datastore/src/main/webapp/WEB-INF/web.xml index cf06f60d61e..6b22f8fbe65 100644 --- a/appengine-java8/datastore/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/datastore/src/main/webapp/WEB-INF/web.xml @@ -14,10 +14,11 @@ See the License for the specific language governing permissions and limitations under the License. --> - + guestbook-strong com.example.appengine.GuestbookStrongServlet diff --git a/appengine-java8/endpoints-frameworks-v2/backend/src/main/webapp/WEB-INF/web.xml b/appengine-java8/endpoints-frameworks-v2/backend/src/main/webapp/WEB-INF/web.xml index f8d1d03f98a..78661fb5d0a 100644 --- a/appengine-java8/endpoints-frameworks-v2/backend/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/endpoints-frameworks-v2/backend/src/main/webapp/WEB-INF/web.xml @@ -14,7 +14,11 @@ See the License for the specific language governing permissions and limitations under the License. --> - + EndpointsServlet diff --git a/appengine-java8/endpoints-frameworks-v2/migration-example/src/main/webapp/WEB-INF/web.xml b/appengine-java8/endpoints-frameworks-v2/migration-example/src/main/webapp/WEB-INF/web.xml index be7073d2745..7f42fd562d4 100644 --- a/appengine-java8/endpoints-frameworks-v2/migration-example/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/endpoints-frameworks-v2/migration-example/src/main/webapp/WEB-INF/web.xml @@ -1,4 +1,4 @@ - + + - + xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee + http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" + version="3.1"> com.example.gaefirebaseeventproxy.ServletContextListenerImpl diff --git a/appengine-java8/firebase-tictactoe/src/main/webapp/WEB-INF/web.xml b/appengine-java8/firebase-tictactoe/src/main/webapp/WEB-INF/web.xml index 772f32fc601..7bb9e2669cf 100644 --- a/appengine-java8/firebase-tictactoe/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/firebase-tictactoe/src/main/webapp/WEB-INF/web.xml @@ -14,10 +14,11 @@ See the License for the specific language governing permissions and limitations under the License. --> - + index diff --git a/appengine-java8/guestbook-cloud-datastore/src/main/webapp/WEB-INF/web.xml b/appengine-java8/guestbook-cloud-datastore/src/main/webapp/WEB-INF/web.xml index 110a5c42fbc..112b096897c 100644 --- a/appengine-java8/guestbook-cloud-datastore/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/guestbook-cloud-datastore/src/main/webapp/WEB-INF/web.xml @@ -1,8 +1,24 @@ - + + sign diff --git a/appengine-java8/guestbook-objectify/src/main/webapp/WEB-INF/web.xml b/appengine-java8/guestbook-objectify/src/main/webapp/WEB-INF/web.xml index d5a23626f0c..9f0f9d72568 100644 --- a/appengine-java8/guestbook-objectify/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/guestbook-objectify/src/main/webapp/WEB-INF/web.xml @@ -1,8 +1,24 @@ - + + sign diff --git a/appengine-java8/helloworld/README.md b/appengine-java8/helloworld/README.md deleted file mode 100644 index 204ac802e96..00000000000 --- a/appengine-java8/helloworld/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# Google App Engine Standard Environment Hello World Sample - -This sample demonstrates how to deploy an application on Google App Engine. - -See the [Google App Engine standard environment documentation][ae-docs] for more -detailed instructions. - -[ae-docs]: https://cloud.google.com/appengine/docs/java/ - -## Setup - - gcloud init - -## Running locally - $ mvn appengine:run - -## Deploying - $ mvn appengine:deploy diff --git a/appengine-java8/helloworld/jenkins.sh b/appengine-java8/helloworld/jenkins.sh deleted file mode 100644 index 22dfb5b12f4..00000000000 --- a/appengine-java8/helloworld/jenkins.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2017 Google Inc. -# -# 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. - -set -xe - -mvn clean appengine:deploy -DskipTests=true - -curl -f "http://${GOOGLE_VERSION_ID}-dot-${GOOGLE_PROJECT_ID}.appspot.com/" diff --git a/appengine-java8/helloworld/pom.xml b/appengine-java8/helloworld/pom.xml deleted file mode 100644 index ad046383886..00000000000 --- a/appengine-java8/helloworld/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - 4.0.0 - war - 1.0-SNAPSHOT - com.example.appengine - appengine-helloworld-j8 - - com.google.cloud - appengine-java8-samples - 1.0.0 - .. - - - - javax.servlet - javax.servlet-api - 3.1.0 - jar - provided - - - - - ${project.build.directory}/${project.build.finalName}/WEB-INF/classes - - - com.google.cloud.tools - appengine-maven-plugin - 1.3.1 - - true - true - - - - - - diff --git a/appengine-java8/helloworld/src/main/java/com/example/appengine/helloworld/HelloServlet.java b/appengine-java8/helloworld/src/main/java/com/example/appengine/helloworld/HelloServlet.java deleted file mode 100644 index 5868bf82f9d..00000000000 --- a/appengine-java8/helloworld/src/main/java/com/example/appengine/helloworld/HelloServlet.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright 2015 Google Inc. - * - * 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. - */ - -package com.example.appengine.helloworld; - -import java.io.IOException; -import java.io.PrintWriter; - -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -// [START example] -@SuppressWarnings("serial") -public class HelloServlet extends HttpServlet { - - @Override - public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - PrintWriter out = resp.getWriter(); - out.println("Hello, world"); - } -} -// [END example] diff --git a/appengine-java8/helloworld/src/main/webapp/WEB-INF/appengine-web.xml b/appengine-java8/helloworld/src/main/webapp/WEB-INF/appengine-web.xml deleted file mode 100644 index 1f8086c81f4..00000000000 --- a/appengine-java8/helloworld/src/main/webapp/WEB-INF/appengine-web.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - java8 - true - - diff --git a/appengine-java8/helloworld/src/main/webapp/WEB-INF/web.xml b/appengine-java8/helloworld/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 1a1704104a2..00000000000 --- a/appengine-java8/helloworld/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - hello - com.example.appengine.helloworld.HelloServlet - - - hello - / - - diff --git a/appengine-java8/images/src/main/webapp/WEB-INF/web.xml b/appengine-java8/images/src/main/webapp/WEB-INF/web.xml index 8ccba622877..3ab41c29a64 100644 --- a/appengine-java8/images/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/images/src/main/webapp/WEB-INF/web.xml @@ -1,8 +1,24 @@ - + + images com.example.appengine.images.ImagesServlet diff --git a/appengine-java8/logs/src/main/webapp/WEB-INF/web.xml b/appengine-java8/logs/src/main/webapp/WEB-INF/web.xml index 3b156c9b98c..5f039c7d869 100644 --- a/appengine-java8/logs/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/logs/src/main/webapp/WEB-INF/web.xml @@ -1,22 +1,24 @@ - - - + logs com.example.appengine.logs.LogsServlet diff --git a/appengine-java8/mail/src/main/webapp/WEB-INF/web.xml b/appengine-java8/mail/src/main/webapp/WEB-INF/web.xml index 393f67066ad..5fa0893782a 100644 --- a/appengine-java8/mail/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/mail/src/main/webapp/WEB-INF/web.xml @@ -1,20 +1,24 @@ - + mail com.example.appengine.mail.MailServlet diff --git a/appengine-java8/mailgun/src/main/webapp/WEB-INF/web.xml b/appengine-java8/mailgun/src/main/webapp/WEB-INF/web.xml index 9f22b168016..e43d571462f 100644 --- a/appengine-java8/mailgun/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/mailgun/src/main/webapp/WEB-INF/web.xml @@ -1,22 +1,24 @@ - - - + mailgun com.example.appengine.mailgun.MailgunServlet diff --git a/appengine-java8/mailjet/src/main/webapp/WEB-INF/web.xml b/appengine-java8/mailjet/src/main/webapp/WEB-INF/web.xml index 9d906fce8f8..0c196aef5e4 100644 --- a/appengine-java8/mailjet/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/mailjet/src/main/webapp/WEB-INF/web.xml @@ -1,22 +1,24 @@ - - - + mailjet com.example.appengine.mailjet.MailjetServlet diff --git a/appengine-java8/memcache/src/main/webapp/WEB-INF/web.xml b/appengine-java8/memcache/src/main/webapp/WEB-INF/web.xml index d4a7e38c981..afbd918d067 100644 --- a/appengine-java8/memcache/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/memcache/src/main/webapp/WEB-INF/web.xml @@ -1,22 +1,24 @@ - - - + memcache-best-practice com.example.appengine.memcache.MemcacheBestPracticeServlet diff --git a/appengine-java8/multitenancy/src/main/webapp/WEB-INF/web.xml b/appengine-java8/multitenancy/src/main/webapp/WEB-INF/web.xml index 92cf8deccd3..c8853530ceb 100644 --- a/appengine-java8/multitenancy/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/multitenancy/src/main/webapp/WEB-INF/web.xml @@ -1,7 +1,24 @@ - + + diff --git a/appengine-java8/oauth2/src/main/webapp/WEB-INF/web.xml b/appengine-java8/oauth2/src/main/webapp/WEB-INF/web.xml index 183e631c600..4aa5ce5ec15 100644 --- a/appengine-java8/oauth2/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/oauth2/src/main/webapp/WEB-INF/web.xml @@ -1,8 +1,24 @@ - + + Oauth2Filter com.example.appengine.Oauth2Filter diff --git a/appengine-java8/pom.xml b/appengine-java8/pom.xml index 07b9f6d7f24..dc39478adca 100644 --- a/appengine-java8/pom.xml +++ b/appengine-java8/pom.xml @@ -54,8 +54,6 @@ guestbook-cloud-datastore guestbook-objectify - helloworld - images logs mailgun @@ -78,8 +76,6 @@ twilio - unittests - urlfetch users diff --git a/appengine-java8/remote/remote-server/src/main/webapp/WEB-INF/web.xml b/appengine-java8/remote/remote-server/src/main/webapp/WEB-INF/web.xml index 0ec344f02b5..1e465028c5a 100644 --- a/appengine-java8/remote/remote-server/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/remote/remote-server/src/main/webapp/WEB-INF/web.xml @@ -1,22 +1,24 @@ - - - + Remote API Servlet diff --git a/appengine-java8/requests/src/main/webapp/WEB-INF/web.xml b/appengine-java8/requests/src/main/webapp/WEB-INF/web.xml index 7784c6a56c6..09f780f6a56 100644 --- a/appengine-java8/requests/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/requests/src/main/webapp/WEB-INF/web.xml @@ -1,8 +1,24 @@ - + + requests com.example.appengine.requests.RequestsServlet diff --git a/appengine-java8/search/pom.xml b/appengine-java8/search/pom.xml index 76973c9c88f..98aa9fc5f6e 100644 --- a/appengine-java8/search/pom.xml +++ b/appengine-java8/search/pom.xml @@ -79,8 +79,6 @@ Copyright 2015 Google Inc. - - ${project.build.directory}/${project.build.finalName}/WEB-INF/classes com.google.cloud.tools diff --git a/appengine-java8/search/src/main/webapp/WEB-INF/web.xml b/appengine-java8/search/src/main/webapp/WEB-INF/web.xml index d3e1e6f8ec3..8138d03c480 100644 --- a/appengine-java8/search/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/search/src/main/webapp/WEB-INF/web.xml @@ -1,8 +1,24 @@ - + + document com.example.appengine.search.DocumentServlet diff --git a/appengine-java8/sendgrid/src/main/webapp/WEB-INF/web.xml b/appengine-java8/sendgrid/src/main/webapp/WEB-INF/web.xml index 23a0e83b821..3a83edc0096 100644 --- a/appengine-java8/sendgrid/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/sendgrid/src/main/webapp/WEB-INF/web.xml @@ -1,22 +1,24 @@ - - - + sendemail com.example.appengine.sendgrid.SendEmailServlet diff --git a/appengine-java8/taskqueue/deferred/src/main/webapp/WEB-INF/web.xml b/appengine-java8/taskqueue/deferred/src/main/webapp/WEB-INF/web.xml index a8b724b5871..aa47a37f557 100644 --- a/appengine-java8/taskqueue/deferred/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/taskqueue/deferred/src/main/webapp/WEB-INF/web.xml @@ -1,24 +1,24 @@ - + defer-sample-servlet com.google.cloud.taskqueue.samples.DeferSampleServlet diff --git a/appengine-java8/taskqueue/pull/src/main/webapp/WEB-INF/web.xml b/appengine-java8/taskqueue/pull/src/main/webapp/WEB-INF/web.xml index 807f08387c2..87cd397fc0b 100644 --- a/appengine-java8/taskqueue/pull/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/taskqueue/pull/src/main/webapp/WEB-INF/web.xml @@ -1,22 +1,24 @@ - - - + taskqueue com.example.taskqueue.TaskqueueServlet diff --git a/appengine-java8/taskqueue/push/src/main/webapp/WEB-INF/web.xml b/appengine-java8/taskqueue/push/src/main/webapp/WEB-INF/web.xml index b1ab8458b5b..6f57f6b503d 100644 --- a/appengine-java8/taskqueue/push/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/taskqueue/push/src/main/webapp/WEB-INF/web.xml @@ -1,6 +1,6 @@ - + index.html diff --git a/appengine-java8/twilio/src/main/webapp/WEB-INF/web.xml b/appengine-java8/twilio/src/main/webapp/WEB-INF/web.xml index 4791ebe69c4..6cb4c65cf9b 100644 --- a/appengine-java8/twilio/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/twilio/src/main/webapp/WEB-INF/web.xml @@ -1,22 +1,24 @@ - - - + receivecall com.example.appengine.twilio.ReceiveCallServlet diff --git a/appengine-java8/unittests/README.md b/appengine-java8/unittests/README.md deleted file mode 100644 index cd62f828b4f..00000000000 --- a/appengine-java8/unittests/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# appengine-ndb-snippets - -## unittests - -This subdirectory contains code snippets for [Local Unit Testing for Java](https://cloud.google.com/appengine/docs/java/tools/localunittesting). - -App shows all the ways to unit test. - - mvn verify diff --git a/appengine-java8/unittests/pom.xml b/appengine-java8/unittests/pom.xml deleted file mode 100644 index a846a80f811..00000000000 --- a/appengine-java8/unittests/pom.xml +++ /dev/null @@ -1,94 +0,0 @@ - - - - 4.0.0 - war - 1.0-SNAPSHOT - - - - appengine-java8-samples - com.google.cloud - 1.0.0 - .. - - - com.google.appengine.samples - unittests-appengine-local-testing-samples-j8 - - - 1.9.52 - UTF-8 - 1.22.0 - - - - - - com.google.appengine - appengine-api-1.0-sdk - ${appengine.sdk.version} - - - - javax.servlet - javax.servlet-api - 3.1.0 - jar - provided - - - - jstl - jstl - 1.2 - - - - - junit - junit - 4.12 - test - - - com.google.appengine - appengine-testing - ${appengine.sdk.version} - test - - - com.google.appengine - appengine-api-stubs - ${appengine.sdk.version} - test - - - com.google.appengine - appengine-tools-sdk - ${appengine.sdk.version} - test - - - com.google.api-client - google-api-client-appengine - ${google-api-client.version} - test - - - - - - - com.google.cloud.tools - appengine-maven-plugin - 1.3.1 - - true - true - - - - - - diff --git a/appengine-java8/unittests/src/main/webapp/WEB-INF/appengine-web.xml b/appengine-java8/unittests/src/main/webapp/WEB-INF/appengine-web.xml deleted file mode 100644 index a921b3b65d8..00000000000 --- a/appengine-java8/unittests/src/main/webapp/WEB-INF/appengine-web.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - java8 - true - - - - - diff --git a/appengine-java8/unittests/src/main/webapp/WEB-INF/logging.properties b/appengine-java8/unittests/src/main/webapp/WEB-INF/logging.properties deleted file mode 100644 index a17206681f0..00000000000 --- a/appengine-java8/unittests/src/main/webapp/WEB-INF/logging.properties +++ /dev/null @@ -1,13 +0,0 @@ -# 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: -# -# -# -# -# - -# Set the default logging level for all loggers to WARNING -.level = WARNING diff --git a/appengine-java8/unittests/src/main/webapp/WEB-INF/queue.xml b/appengine-java8/unittests/src/main/webapp/WEB-INF/queue.xml deleted file mode 100644 index a0d8b77c060..00000000000 --- a/appengine-java8/unittests/src/main/webapp/WEB-INF/queue.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - default - 1/s - - - my-queue-name - 3/s - - diff --git a/appengine-java8/unittests/src/main/webapp/WEB-INF/web.xml b/appengine-java8/unittests/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 6a0e90311ab..00000000000 --- a/appengine-java8/unittests/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - diff --git a/appengine-java8/unittests/src/test/java/com/google/appengine/samples/AuthenticationTest.java b/appengine-java8/unittests/src/test/java/com/google/appengine/samples/AuthenticationTest.java deleted file mode 100644 index c300702fb20..00000000000 --- a/appengine-java8/unittests/src/test/java/com/google/appengine/samples/AuthenticationTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2015 Google Inc. - * - * 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. - */ - -package com.google.appengine.samples; - -// [START AuthenticationTest] - -import static org.junit.Assert.assertTrue; - -import com.google.appengine.api.users.UserService; -import com.google.appengine.api.users.UserServiceFactory; -import com.google.appengine.tools.development.testing.LocalServiceTestHelper; -import com.google.appengine.tools.development.testing.LocalUserServiceTestConfig; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class AuthenticationTest { - - private final LocalServiceTestHelper helper = - new LocalServiceTestHelper(new LocalUserServiceTestConfig()) - .setEnvIsAdmin(true).setEnvIsLoggedIn(true); - - @Before - public void setUp() { - helper.setUp(); - } - - @After - public void tearDown() { - helper.tearDown(); - } - - @Test - public void testIsAdmin() { - UserService userService = UserServiceFactory.getUserService(); - assertTrue(userService.isUserAdmin()); - } -} -// [END AuthenticationTest] diff --git a/appengine-java8/unittests/src/test/java/com/google/appengine/samples/DeferredTaskTest.java b/appengine-java8/unittests/src/test/java/com/google/appengine/samples/DeferredTaskTest.java deleted file mode 100644 index 3477305210e..00000000000 --- a/appengine-java8/unittests/src/test/java/com/google/appengine/samples/DeferredTaskTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2015 Google Inc. - * - * 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. - */ - -package com.google.appengine.samples; - -// [START DeferredTaskTest] - -import static org.junit.Assert.assertTrue; - -import com.google.appengine.api.taskqueue.DeferredTask; -import com.google.appengine.api.taskqueue.QueueFactory; -import com.google.appengine.api.taskqueue.TaskOptions; -import com.google.appengine.tools.development.testing.LocalServiceTestHelper; -import com.google.appengine.tools.development.testing.LocalTaskQueueTestConfig; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import java.util.concurrent.TimeUnit; - -public class DeferredTaskTest { - - // Unlike CountDownLatch, TaskCountDownlatch lets us reset. - private final LocalTaskQueueTestConfig.TaskCountDownLatch latch = - new LocalTaskQueueTestConfig.TaskCountDownLatch(1); - - private final LocalServiceTestHelper helper = - new LocalServiceTestHelper(new LocalTaskQueueTestConfig() - .setDisableAutoTaskExecution(false) - .setCallbackClass(LocalTaskQueueTestConfig.DeferredTaskCallback.class) - .setTaskExecutionLatch(latch)); - - private static class MyTask implements DeferredTask { - private static boolean taskRan = false; - - @Override - public void run() { - taskRan = true; - } - } - - @Before - public void setUp() { - helper.setUp(); - } - - @After - public void tearDown() { - MyTask.taskRan = false; - latch.reset(); - helper.tearDown(); - } - - @Test - public void testTaskGetsRun() throws InterruptedException { - QueueFactory.getDefaultQueue().add( - TaskOptions.Builder.withPayload(new MyTask())); - assertTrue(latch.await(5, TimeUnit.SECONDS)); - assertTrue(MyTask.taskRan); - } -} -// [END DeferredTaskTest] diff --git a/appengine-java8/unittests/src/test/java/com/google/appengine/samples/LocalCustomPolicyHighRepDatastoreTest.java b/appengine-java8/unittests/src/test/java/com/google/appengine/samples/LocalCustomPolicyHighRepDatastoreTest.java deleted file mode 100644 index ef889c7579e..00000000000 --- a/appengine-java8/unittests/src/test/java/com/google/appengine/samples/LocalCustomPolicyHighRepDatastoreTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2015 Google Inc. - * - * 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. - */ - -package com.google.appengine.samples; - -// [START LocalCustomPolicyHighRepDatastoreTest] - -import static com.google.appengine.api.datastore.FetchOptions.Builder.withLimit; -import static org.junit.Assert.assertEquals; - -import com.google.appengine.api.datastore.DatastoreService; -import com.google.appengine.api.datastore.DatastoreServiceFactory; -import com.google.appengine.api.datastore.Entity; -import com.google.appengine.api.datastore.Key; -import com.google.appengine.api.datastore.Query; -import com.google.appengine.api.datastore.dev.HighRepJobPolicy; -import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig; -import com.google.appengine.tools.development.testing.LocalServiceTestHelper; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class LocalCustomPolicyHighRepDatastoreTest { - private static final class CustomHighRepJobPolicy implements HighRepJobPolicy { - static int newJobCounter = 0; - static int existingJobCounter = 0; - - @Override - public boolean shouldApplyNewJob(Key entityGroup) { - // Every other new job fails to apply. - return newJobCounter++ % 2 == 0; - } - - @Override - public boolean shouldRollForwardExistingJob(Key entityGroup) { - // Every other existing job fails to apply. - return existingJobCounter++ % 2 == 0; - } - } - - private final LocalServiceTestHelper helper = - new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig() - .setAlternateHighRepJobPolicyClass(CustomHighRepJobPolicy.class)); - - @Before - public void setUp() { - helper.setUp(); - } - - @After - public void tearDown() { - helper.tearDown(); - } - - @Test - public void testEventuallyConsistentGlobalQueryResult() { - DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); - ds.put(new Entity("yam")); // applies - ds.put(new Entity("yam")); // does not apply - // First global query only sees the first Entity. - assertEquals(1, ds.prepare(new Query("yam")).countEntities(withLimit(10))); - // Second global query sees both Entities because we "groom" (attempt to - // apply unapplied jobs) after every query. - assertEquals(2, ds.prepare(new Query("yam")).countEntities(withLimit(10))); - } -} -// [END LocalCustomPolicyHighRepDatastoreTest] diff --git a/appengine-java8/unittests/src/test/java/com/google/appengine/samples/LocalDatastoreTest.java b/appengine-java8/unittests/src/test/java/com/google/appengine/samples/LocalDatastoreTest.java deleted file mode 100644 index 2b451c8d65b..00000000000 --- a/appengine-java8/unittests/src/test/java/com/google/appengine/samples/LocalDatastoreTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2015 Google Inc. - * - * 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. - */ - -package com.google.appengine.samples; - -// [START LocalDatastoreTest] - -import static com.google.appengine.api.datastore.FetchOptions.Builder.withLimit; -import static org.junit.Assert.assertEquals; - -import com.google.appengine.api.datastore.DatastoreService; -import com.google.appengine.api.datastore.DatastoreServiceFactory; -import com.google.appengine.api.datastore.Entity; -import com.google.appengine.api.datastore.Query; -import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig; -import com.google.appengine.tools.development.testing.LocalServiceTestHelper; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class LocalDatastoreTest { - - private final LocalServiceTestHelper helper = - new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig()); - - @Before - public void setUp() { - helper.setUp(); - } - - @After - public void tearDown() { - helper.tearDown(); - } - - // Run this test twice to prove we're not leaking any state across tests. - private void doTest() { - DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); - assertEquals(0, ds.prepare(new Query("yam")).countEntities(withLimit(10))); - ds.put(new Entity("yam")); - ds.put(new Entity("yam")); - assertEquals(2, ds.prepare(new Query("yam")).countEntities(withLimit(10))); - } - - @Test - public void testInsert1() { - doTest(); - } - - @Test - public void testInsert2() { - doTest(); - } -} - -// [END LocalDatastoreTest] diff --git a/appengine-java8/unittests/src/test/java/com/google/appengine/samples/LocalHighRepDatastoreTest.java b/appengine-java8/unittests/src/test/java/com/google/appengine/samples/LocalHighRepDatastoreTest.java deleted file mode 100644 index 8d696ad21d4..00000000000 --- a/appengine-java8/unittests/src/test/java/com/google/appengine/samples/LocalHighRepDatastoreTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2015 Google Inc. - * - * 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. - */ - -package com.google.appengine.samples; - -// [START LocalHighRepDatastoreTest] - -import static com.google.appengine.api.datastore.FetchOptions.Builder.withLimit; -import static org.junit.Assert.assertEquals; - -import com.google.appengine.api.datastore.DatastoreService; -import com.google.appengine.api.datastore.DatastoreServiceFactory; -import com.google.appengine.api.datastore.Entity; -import com.google.appengine.api.datastore.Key; -import com.google.appengine.api.datastore.KeyFactory; -import com.google.appengine.api.datastore.Query; -import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig; -import com.google.appengine.tools.development.testing.LocalServiceTestHelper; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class LocalHighRepDatastoreTest { - - // Maximum eventual consistency. - private final LocalServiceTestHelper helper = - new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig() - .setDefaultHighRepJobPolicyUnappliedJobPercentage(100)); - - @Before - public void setUp() { - helper.setUp(); - } - - @After - public void tearDown() { - helper.tearDown(); - } - - @Test - public void testEventuallyConsistentGlobalQueryResult() { - DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); - Key ancestor = KeyFactory.createKey("foo", 3); - ds.put(new Entity("yam", ancestor)); - ds.put(new Entity("yam", ancestor)); - // Global query doesn't see the data. - assertEquals(0, ds.prepare(new Query("yam")).countEntities(withLimit(10))); - // Ancestor query does see the data. - assertEquals(2, ds.prepare(new Query("yam", ancestor)).countEntities(withLimit(10))); - } -} -// [END LocalHighRepDatastoreTest] diff --git a/appengine-java8/unittests/src/test/java/com/google/appengine/samples/LocalMemcacheTest.java b/appengine-java8/unittests/src/test/java/com/google/appengine/samples/LocalMemcacheTest.java deleted file mode 100644 index 39186086cc2..00000000000 --- a/appengine-java8/unittests/src/test/java/com/google/appengine/samples/LocalMemcacheTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2015 Google Inc. - * - * 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. - */ - -package com.google.appengine.samples; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -// [START imports] - -import com.google.appengine.api.memcache.MemcacheService; -import com.google.appengine.api.memcache.MemcacheServiceFactory; -import com.google.appengine.tools.development.testing.LocalMemcacheServiceTestConfig; -import com.google.appengine.tools.development.testing.LocalServiceTestHelper; - -// [END imports] - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -// [START NameAndHelper] -public class LocalMemcacheTest { - - private final LocalServiceTestHelper helper = - new LocalServiceTestHelper(new LocalMemcacheServiceTestConfig()); - - // [END NameAndHelper] - - @Before - public void setUp() { - helper.setUp(); - } - - @After - public void tearDown() { - helper.tearDown(); - } - - // Run this test twice to prove we're not leaking any state across tests. - // [START doTest] - private void doTest() { - MemcacheService ms = MemcacheServiceFactory.getMemcacheService(); - assertFalse(ms.contains("yar")); - ms.put("yar", "foo"); - assertTrue(ms.contains("yar")); - } - // [END doTest] - - @Test - public void testInsert1() { - doTest(); - } - - @Test - public void testInsert2() { - doTest(); - } -} diff --git a/appengine-java8/unittests/src/test/java/com/google/appengine/samples/LocalUrlFetchTest.java b/appengine-java8/unittests/src/test/java/com/google/appengine/samples/LocalUrlFetchTest.java deleted file mode 100644 index b0e616f721e..00000000000 --- a/appengine-java8/unittests/src/test/java/com/google/appengine/samples/LocalUrlFetchTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * 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. - */ - -package com.google.appengine.samples; - -import static org.junit.Assert.assertEquals; - -import com.google.api.client.http.GenericUrl; -import com.google.api.client.http.HttpRequestFactory; -import com.google.api.client.http.HttpResponse; -import com.google.api.client.http.LowLevelHttpRequest; -import com.google.api.client.http.LowLevelHttpResponse; -import com.google.api.client.testing.http.MockHttpTransport; -import com.google.api.client.testing.http.MockLowLevelHttpRequest; -import com.google.api.client.testing.http.MockLowLevelHttpResponse; -import com.google.appengine.tools.development.testing.LocalServiceTestHelper; -import com.google.appengine.tools.development.testing.LocalURLFetchServiceTestConfig; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import java.io.IOException; - -public class LocalUrlFetchTest { - private final LocalServiceTestHelper helper = - new LocalServiceTestHelper(new LocalURLFetchServiceTestConfig()); - - @Before - public void setUp() { - helper.setUp(); - } - - @After - public void tearDown() { - helper.tearDown(); - } - - @Test - public void testMockUrlFetch() throws IOException { - // See http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing - MockHttpTransport mockHttpTransport = new MockHttpTransport() { - @Override - public LowLevelHttpRequest buildRequest(String method, String url) throws IOException { - assertEquals(method, "GET"); - assertEquals(url, "http://foo.bar"); - - return new MockLowLevelHttpRequest() { - @Override - public LowLevelHttpResponse execute() throws IOException { - MockLowLevelHttpResponse response = new MockLowLevelHttpResponse(); - response.setStatusCode(234); - return response; - } - }; - } - }; - - HttpRequestFactory requestFactory = mockHttpTransport.createRequestFactory(); - HttpResponse response = requestFactory.buildGetRequest(new GenericUrl("http://foo.bar")) - .execute(); - assertEquals(response.getStatusCode(), 234); - } -} diff --git a/appengine-java8/unittests/src/test/java/com/google/appengine/samples/MyFirstTest.java b/appengine-java8/unittests/src/test/java/com/google/appengine/samples/MyFirstTest.java deleted file mode 100644 index f60eed48e1c..00000000000 --- a/appengine-java8/unittests/src/test/java/com/google/appengine/samples/MyFirstTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2015 Google Inc. - * - * 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. - */ - -package com.google.appengine.samples; - -// [START MyFirstTest] - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class MyFirstTest { - @Test - public void testAddition() { - assertEquals(4, 2 + 2); - } -} -// [END MyFirstTest] diff --git a/appengine-java8/unittests/src/test/java/com/google/appengine/samples/ShortTest.java b/appengine-java8/unittests/src/test/java/com/google/appengine/samples/ShortTest.java deleted file mode 100644 index a024c08bcd3..00000000000 --- a/appengine-java8/unittests/src/test/java/com/google/appengine/samples/ShortTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2015 Google Inc. - * - * 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. - */ - -package com.google.appengine.samples; - -// [START ShortTest] - -import static org.junit.Assert.assertEquals; - -import com.google.appengine.api.capabilities.Capability; -import com.google.appengine.api.capabilities.CapabilityStatus; -import com.google.appengine.api.datastore.DatastoreService; -import com.google.appengine.api.datastore.DatastoreServiceFactory; -import com.google.appengine.api.datastore.FetchOptions; -import com.google.appengine.api.datastore.Query; -import com.google.appengine.tools.development.testing.LocalCapabilitiesServiceTestConfig; -import com.google.appengine.tools.development.testing.LocalServiceTestHelper; -import com.google.apphosting.api.ApiProxy; - -import org.junit.After; -import org.junit.Test; - -public class ShortTest { - private LocalServiceTestHelper helper; - - @After - public void tearDown() { - helper.tearDown(); - } - - @Test(expected = ApiProxy.CapabilityDisabledException.class) - public void testDisabledDatastore() { - Capability testOne = new Capability("datastore_v3"); - CapabilityStatus testStatus = CapabilityStatus.DISABLED; - // Initialize the test configuration. - LocalCapabilitiesServiceTestConfig config = - new LocalCapabilitiesServiceTestConfig().setCapabilityStatus(testOne, testStatus); - helper = new LocalServiceTestHelper(config); - helper.setUp(); - FetchOptions fo = FetchOptions.Builder.withLimit(10); - DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); - assertEquals(0, ds.prepare(new Query("yam")).countEntities(fo)); - } -} - -// [END ShortTest] diff --git a/appengine-java8/unittests/src/test/java/com/google/appengine/samples/TaskQueueConfigTest.java b/appengine-java8/unittests/src/test/java/com/google/appengine/samples/TaskQueueConfigTest.java deleted file mode 100644 index 84e5d91b15f..00000000000 --- a/appengine-java8/unittests/src/test/java/com/google/appengine/samples/TaskQueueConfigTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2015 Google Inc. - * - * 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. - */ - -package com.google.appengine.samples; - -import static org.junit.Assert.assertEquals; - -import com.google.appengine.api.taskqueue.QueueFactory; -import com.google.appengine.api.taskqueue.TaskOptions; -import com.google.appengine.api.taskqueue.dev.LocalTaskQueue; -import com.google.appengine.api.taskqueue.dev.QueueStateInfo; -import com.google.appengine.tools.development.testing.LocalServiceTestHelper; -import com.google.appengine.tools.development.testing.LocalTaskQueueTestConfig; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class TaskQueueConfigTest { - // [START LocalServiceTestHelper] - private final LocalServiceTestHelper helper = - new LocalServiceTestHelper(new LocalTaskQueueTestConfig() - .setQueueXmlPath("src/main/webapp/WEB-INF/queue.xml")); - //[END LocalServiceTestHelper] - - @Before - public void setUp() { - helper.setUp(); - } - - @After - public void tearDown() { - helper.tearDown(); - } - - // Run this test twice to demonstrate we're not leaking state across tests. - // If we _are_ leaking state across tests we'll get an exception on the - // second test because there will already be a task with the given name. - private void doTest() throws InterruptedException { - // [START QueueFactory] - QueueFactory.getQueue("my-queue-name").add(TaskOptions.Builder.withTaskName("task29")); - // [END QueueFactory] - // Give the task time to execute if tasks are actually enabled (which they - // aren't, but that's part of the test). - Thread.sleep(1000); - LocalTaskQueue ltq = LocalTaskQueueTestConfig.getLocalTaskQueue(); - QueueStateInfo qsi = - ltq.getQueueStateInfo().get(QueueFactory.getQueue("my-queue-name").getQueueName()); - assertEquals(1, qsi.getTaskInfo().size()); - assertEquals("task29", qsi.getTaskInfo().get(0).getTaskName()); - } - - @Test - public void testTaskGetsScheduled1() throws InterruptedException { - doTest(); - } - - @Test - public void testTaskGetsScheduled2() throws InterruptedException { - doTest(); - } -} diff --git a/appengine-java8/unittests/src/test/java/com/google/appengine/samples/TaskQueueTest.java b/appengine-java8/unittests/src/test/java/com/google/appengine/samples/TaskQueueTest.java deleted file mode 100644 index 3616fb035e2..00000000000 --- a/appengine-java8/unittests/src/test/java/com/google/appengine/samples/TaskQueueTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2015 Google Inc. - * - * 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. - */ - -package com.google.appengine.samples; - -// [START TaskQueueTest] - -import static org.junit.Assert.assertEquals; - -import com.google.appengine.api.taskqueue.QueueFactory; -import com.google.appengine.api.taskqueue.TaskOptions; -import com.google.appengine.api.taskqueue.dev.LocalTaskQueue; -import com.google.appengine.api.taskqueue.dev.QueueStateInfo; -import com.google.appengine.tools.development.testing.LocalServiceTestHelper; -import com.google.appengine.tools.development.testing.LocalTaskQueueTestConfig; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class TaskQueueTest { - - private final LocalServiceTestHelper helper = - new LocalServiceTestHelper(new LocalTaskQueueTestConfig()); - - @Before - public void setUp() { - helper.setUp(); - } - - @After - public void tearDown() { - helper.tearDown(); - } - - // Run this test twice to demonstrate we're not leaking state across tests. - // If we _are_ leaking state across tests we'll get an exception on the - // second test because there will already be a task with the given name. - private void doTest() throws InterruptedException { - QueueFactory.getDefaultQueue().add(TaskOptions.Builder.withTaskName("task29")); - // Give the task time to execute if tasks are actually enabled (which they - // aren't, but that's part of the test). - Thread.sleep(1000); - LocalTaskQueue ltq = LocalTaskQueueTestConfig.getLocalTaskQueue(); - QueueStateInfo qsi = ltq.getQueueStateInfo().get(QueueFactory.getDefaultQueue().getQueueName()); - assertEquals(1, qsi.getTaskInfo().size()); - assertEquals("task29", qsi.getTaskInfo().get(0).getTaskName()); - } - - @Test - public void testTaskGetsScheduled1() throws InterruptedException { - doTest(); - } - - @Test - public void testTaskGetsScheduled2() throws InterruptedException { - doTest(); - } -} -// [END TaskQueueTest] diff --git a/appengine-java8/urlfetch/src/main/java/com/example/appengine/UrlFetchServlet.java b/appengine-java8/urlfetch/src/main/java/com/example/appengine/UrlFetchServlet.java index f0052655408..e81d6ee1af6 100644 --- a/appengine-java8/urlfetch/src/main/java/com/example/appengine/UrlFetchServlet.java +++ b/appengine-java8/urlfetch/src/main/java/com/example/appengine/UrlFetchServlet.java @@ -23,12 +23,16 @@ import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; + import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @SuppressWarnings("serial") +@WebServlet(name = "URLFetch", description = "URLFetch: Write low order IP address to Cloud SQL", + urlPatterns = "/urlfetch") public class UrlFetchServlet extends HttpServlet { @Override @@ -49,7 +53,7 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) JSONObject jo = new JSONObject(json.toString()); req.setAttribute("joke", jo.getJSONObject("value").getString("joke")); - req.getRequestDispatcher("/main.jsp").forward(req, resp); + req.getRequestDispatcher("/urlfetchresult.jsp").forward(req, resp); } @Override @@ -61,12 +65,12 @@ public void doPost(HttpServletRequest req, HttpServletResponse resp) if (id == null || text == null || id == "" || text == "") { req.setAttribute("error", "invalid input"); - req.getRequestDispatcher("/main.jsp").forward(req, resp); + req.getRequestDispatcher("/urlfetchresult.jsp").forward(req, resp); return; } JSONObject jsonObj = new JSONObject() - .put("userId", 33) + .put("userId", 1) .put("id", id) .put("title", text) .put("body", text); @@ -97,7 +101,7 @@ public void doPost(HttpServletRequest req, HttpServletResponse resp) req.setAttribute("error", conn.getResponseCode() + " " + conn.getResponseMessage()); } // [END complex] - req.getRequestDispatcher("/main.jsp").forward(req, resp); + req.getRequestDispatcher("/urlfetchresult.jsp").forward(req, resp); } } diff --git a/appengine-java8/urlfetch/src/main/webapp/WEB-INF/web.xml b/appengine-java8/urlfetch/src/main/webapp/WEB-INF/web.xml index ddc5cfb4c46..e63b3c46193 100644 --- a/appengine-java8/urlfetch/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/urlfetch/src/main/webapp/WEB-INF/web.xml @@ -1,14 +1,25 @@ - - - hello - com.example.appengine.UrlFetchServlet - - - hello - / - + + + + urlfetch + diff --git a/appengine-java8/urlfetch/src/main/webapp/main.jsp b/appengine-java8/urlfetch/src/main/webapp/urlfetchresult.jsp similarity index 100% rename from appengine-java8/urlfetch/src/main/webapp/main.jsp rename to appengine-java8/urlfetch/src/main/webapp/urlfetchresult.jsp diff --git a/appengine-java8/users/src/main/java/com/example/appengine/users/UsersServlet.java b/appengine-java8/users/src/main/java/com/example/appengine/users/UsersServlet.java index d654fc78384..b9905f3bf1d 100644 --- a/appengine-java8/users/src/main/java/com/example/appengine/users/UsersServlet.java +++ b/appengine-java8/users/src/main/java/com/example/appengine/users/UsersServlet.java @@ -21,10 +21,13 @@ import java.io.IOException; +import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +@WebServlet(name = "UserAPI", description = "UserAPI: Login / Logout with UserService", + urlPatterns = "/userapi") public class UsersServlet extends HttpServlet { @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) diff --git a/appengine-java8/users/src/main/webapp/WEB-INF/web.xml b/appengine-java8/users/src/main/webapp/WEB-INF/web.xml index 4b2b77234dc..37a18127a34 100644 --- a/appengine-java8/users/src/main/webapp/WEB-INF/web.xml +++ b/appengine-java8/users/src/main/webapp/WEB-INF/web.xml @@ -1,14 +1,25 @@ - - - users - com.example.appengine.users.UsersServlet - - - users - / - + + + + userapi +