Fixes to appengine templates and update to v1.9.8

Automatically use https on endpoints calls from the browser
Documentation updates in Endpoints files

Change-Id: I10d6512f07e390522fab148b33eac33a99118a5e
diff --git a/resources/templates/GcmEndpoints/root/build.gradle.ftl b/resources/templates/GcmEndpoints/root/build.gradle.ftl
index cc39703..70ae1f9 100644
--- a/resources/templates/GcmEndpoints/root/build.gradle.ftl
+++ b/resources/templates/GcmEndpoints/root/build.gradle.ftl
@@ -1,6 +1,3 @@
-// Currently, the appengine gradle plugin's appengine devappserver launch doesn't interact well with Intellij/AndroidStudio's
-// Gradle integration.  As a temporary solution, please launch from the command line.
-// ./gradlew modulename:appengineRun
 // If you would like more information on the gradle-appengine-plugin please refer to the github page
 // https://github.com/GoogleCloudPlatform/gradle-appengine-plugin
 
diff --git a/resources/templates/GcmEndpoints/root/src/main/MessagingEndpoint.java.ftl b/resources/templates/GcmEndpoints/root/src/main/MessagingEndpoint.java.ftl
index 05a161a..09e8cc1 100644
--- a/resources/templates/GcmEndpoints/root/src/main/MessagingEndpoint.java.ftl
+++ b/resources/templates/GcmEndpoints/root/src/main/MessagingEndpoint.java.ftl
@@ -1,3 +1,9 @@
+/*
+   For step-by-step instructions on connecting your Android application to this backend module,
+   see "App Engine Backend with Google Cloud Messaging" template documentation at
+   https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/GcmEndpoints
+*/
+
 package ${packageName};
 
 import com.google.android.gcm.server.Constants;
diff --git a/resources/templates/GcmEndpoints/root/src/main/RegistrationEndpoint.java.ftl b/resources/templates/GcmEndpoints/root/src/main/RegistrationEndpoint.java.ftl
index 95fa77d..0f4d085 100644
--- a/resources/templates/GcmEndpoints/root/src/main/RegistrationEndpoint.java.ftl
+++ b/resources/templates/GcmEndpoints/root/src/main/RegistrationEndpoint.java.ftl
@@ -1,3 +1,9 @@
+/*
+   For step-by-step instructions on connecting your Android application to this backend module,
+   see "App Engine Backend with Google Cloud Messaging" template documentation at
+   https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/GcmEndpoints
+*/
+
 package ${packageName};
 
 import com.google.api.server.spi.config.Api;
@@ -73,4 +79,4 @@
         return ofy().load().type(RegistrationRecord.class).filter("regId", regId).first().now();
     }
 
-}
\ No newline at end of file
+}
diff --git a/resources/templates/GcmEndpoints/root/src/webapp/index.html.ftl b/resources/templates/GcmEndpoints/root/src/webapp/index.html.ftl
index 7070937..21e9927 100644
--- a/resources/templates/GcmEndpoints/root/src/webapp/index.html.ftl
+++ b/resources/templates/GcmEndpoints/root/src/webapp/index.html.ftl
@@ -101,8 +101,13 @@
     function init() {
       var apiName = 'messaging'
       var apiVersion = 'v1'
-      // set the apiRoot to work on a deployed app and locally
-      var apiRoot = '//' + window.location.host + '/_ah/api';
+      var apiRoot = 'https://' + window.location.host + '/_ah/api';
+      if (window.location.hostname == 'localhost'
+          || window.location.hostname == '127.0.0.1'
+          || ((window.location.port != "") && (window.location.port > 1023))) {
+            // We're probably running against the DevAppServer
+            apiRoot = 'http://' + window.location.host + '/_ah/api';
+      }
       var callback = function() {
         enableClick();
       }
diff --git a/resources/templates/GcmEndpoints/template.xml b/resources/templates/GcmEndpoints/template.xml
index d853856..deeab15 100644
--- a/resources/templates/GcmEndpoints/template.xml
+++ b/resources/templates/GcmEndpoints/template.xml
@@ -27,7 +27,7 @@
   <parameter id="endpointOwnerDomain" name="Endpoint Owner Domain" type="string" constraints="package" default="mycompany.com"/>
   <parameter id="endpointPackagePath" name="Endpoint Package Path" type="string" constraints="package" default="myapp"/>
   <parameter id="apiKey" name="Gcm Api Key" type="string" default="REPLACE WITH YOUR API KEY"/>
-  <parameter id="appEngineVersion" name="AppEngine Version" type="string" default="1.9.6" />
+  <parameter id="appEngineVersion" name="AppEngine Version" type="string" default="1.9.8" />
   <parameter id="docUrl" name="Doc URL" type="string" visibility="false"
              default="https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/GcmEndpoints"/>
   <parameter id="sideIconPath" name="Side icon path" type="string" visibility="false"
diff --git a/resources/templates/HelloEndpoints/root/build.gradle.ftl b/resources/templates/HelloEndpoints/root/build.gradle.ftl
index cfa6468..f77265d 100644
--- a/resources/templates/HelloEndpoints/root/build.gradle.ftl
+++ b/resources/templates/HelloEndpoints/root/build.gradle.ftl
@@ -1,6 +1,3 @@
-// Currently, the appengine gradle plugin's appengine devappserver launch doesn't interact well with Intellij/AndroidStudio's
-// Gradle integration.  As a temporary solution, please launch from the command line.
-// ./gradlew modulename:appengineRun
 // If you would like more information on the gradle-appengine-plugin please refer to the github page
 // https://github.com/GoogleCloudPlatform/gradle-appengine-plugin
 
diff --git a/resources/templates/HelloEndpoints/root/src/main/MyEndpoint.java.ftl b/resources/templates/HelloEndpoints/root/src/main/MyEndpoint.java.ftl
index 9a4c188..b420697 100644
--- a/resources/templates/HelloEndpoints/root/src/main/MyEndpoint.java.ftl
+++ b/resources/templates/HelloEndpoints/root/src/main/MyEndpoint.java.ftl
@@ -1,3 +1,9 @@
+/*
+   For step-by-step instructions on connecting your Android application to this backend module,
+   see "App Engine Java Endpoints Module" template documentation at
+   https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/HelloEndpoints
+*/
+
 package ${packageName};
 
 import com.google.api.server.spi.config.Api;
@@ -19,4 +25,4 @@
         return response;
     }
 
-}
\ No newline at end of file
+}
diff --git a/resources/templates/HelloEndpoints/root/src/webapp/index.html.ftl b/resources/templates/HelloEndpoints/root/src/webapp/index.html.ftl
index a75f804..6116784 100644
--- a/resources/templates/HelloEndpoints/root/src/webapp/index.html.ftl
+++ b/resources/templates/HelloEndpoints/root/src/webapp/index.html.ftl
@@ -92,7 +92,13 @@
     function init() {
       var apiName = 'myApi';
       var apiVersion = 'v1';
-      var apiRoot = '//' + window.location.host + '/_ah/api';
+      var apiRoot = 'https://' + window.location.host + '/_ah/api';
+      if (window.location.hostname == 'localhost'
+          || window.location.hostname == '127.0.0.1'
+          || ((window.location.port != "") && (window.location.port > 1023))) {
+            // We're probably running against the DevAppServer
+            apiRoot = 'http://' + window.location.host + '/_ah/api';
+      }
       var callback = function() {
         enableClick();
       }
diff --git a/resources/templates/HelloEndpoints/template.xml b/resources/templates/HelloEndpoints/template.xml
index 78ed749..e0b0ab1 100644
--- a/resources/templates/HelloEndpoints/template.xml
+++ b/resources/templates/HelloEndpoints/template.xml
@@ -26,7 +26,7 @@
   <parameter id="appId" name="Application Id" type="string" constraints="nonempty" default="myApplicationId"/>
   <parameter id="endpointOwnerDomain" name="Endpoint Owner Domain" type="string" constraints="package" default="mycompany.com"/>
   <parameter id="endpointPackagePath" name="Endpoint Package Path" type="string" constraints="package" default="myapp"/>
-  <parameter id="appEngineVersion" name="AppEngine Version" type="string" default="1.9.6" />
+  <parameter id="appEngineVersion" name="AppEngine Version" type="string" default="1.9.8" />
   <parameter id="docUrl" name="Doc URL" type="string" visibility="false"
              default="https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/HelloEndpoints"/>
 
diff --git a/resources/templates/HelloWorld/root/build.gradle.ftl b/resources/templates/HelloWorld/root/build.gradle.ftl
index 8cb5faa..6d73c1b 100644
--- a/resources/templates/HelloWorld/root/build.gradle.ftl
+++ b/resources/templates/HelloWorld/root/build.gradle.ftl
@@ -1,6 +1,3 @@
-// Currently, the appengine gradle plugin's appengine devappserver launch doesn't interact well with Intellij/AndroidStudio's
-// Gradle integration.  As a temporary solution, please launch from the command line.
-// ./gradlew modulename:appengineRun
 // If you would like more information on the gradle-appengine-plugin please refer to the github page
 // https://github.com/GoogleCloudPlatform/gradle-appengine-plugin
 
diff --git a/resources/templates/HelloWorld/root/src/main/MyServlet.java.ftl b/resources/templates/HelloWorld/root/src/main/MyServlet.java.ftl
index bf30f05..9f89f42 100644
--- a/resources/templates/HelloWorld/root/src/main/MyServlet.java.ftl
+++ b/resources/templates/HelloWorld/root/src/main/MyServlet.java.ftl
@@ -1,3 +1,9 @@
+/*
+   For step-by-step instructions on connecting your Android application to this backend module,
+   see "App Engine Java Servlet Module" template documentation at
+   https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/HelloWorld
+*/
+
 package ${packageName};
 
 import java.io.IOException;
@@ -21,4 +27,4 @@
         }
         resp.getWriter().println("Hello " + name);
     }
-}
\ No newline at end of file
+}
diff --git a/resources/templates/HelloWorld/template.xml b/resources/templates/HelloWorld/template.xml
index 8be72c9..6cada3e 100644
--- a/resources/templates/HelloWorld/template.xml
+++ b/resources/templates/HelloWorld/template.xml
@@ -24,7 +24,7 @@
 
   <parameter id="packageName" name="Package name" type="string" constraints="package|nonempty" default="com.mycompany.myapp"/>
   <parameter id="appId" name="Application Id" type="string" constraints="nonempty" default="myApplicationId"/>
-  <parameter id="appEngineVersion" name="AppEngine Version" type="string" default="1.9.6" />
+  <parameter id="appEngineVersion" name="AppEngine Version" type="string" default="1.9.8" />
   <parameter id="docUrl" name="Doc URL" type="string" visibility="false"
              default="https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/HelloWorld"/>
   <parameter id="sideIconPath" name="Side icon path" type="string" visibility="false"