Skip to content

Commit

Permalink
[Endpoints] Add skeleton v2 sample (#916)
Browse files Browse the repository at this point in the history
* Add skeleton endpoints-frameworks v2 sample

* Rename README

* Fix version

* Add region tag for web.xml

* Add region tag around appengine-web.xml

* Remove basic scaling

* Add skeleton sample to parent pom

* Add explicit instructions to update project id

* Added more information into the MyApi.java class

* Remove versions plugin from pom.xml
  • Loading branch information
frankyn committed Nov 14, 2017
1 parent f663975 commit ea4abcf
Show file tree
Hide file tree
Showing 8 changed files with 330 additions and 0 deletions.
7 changes: 7 additions & 0 deletions appengine-java8/endpoints-v2-skeleton/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# App Engine Standard & Endpoints Frameworks skeleton

This is a skeleton example for getting setup with Endpoints Framework v2 for
Java.

For a more complete example of using Endpoints Framework v2 for Java review
the [backend example](/appengine-java8/endpoints-v2-backend).
85 changes: 85 additions & 0 deletions appengine-java8/endpoints-v2-skeleton/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// 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.import org.apache.tools.ant.filters.ReplaceTokens

// [START build_script]
buildscript {
repositories {
mavenCentral()
}

dependencies {
classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.2'
classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.3.3'
}
}
// [END build_script]

repositories {
mavenCentral()
}

// [START plugin_applys]
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'com.google.cloud.tools.endpoints-framework-server'
apply plugin: 'com.google.cloud.tools.appengine'
// [END plugin_applys]

// [START dependencies]
dependencies {
compile 'com.google.endpoints:endpoints-framework:2.0.9'
compile 'com.google.appengine:appengine-api-1.0-sdk:1.9.59'

compile 'javax.inject:javax.inject:1'
compileOnly 'javax.servlet:javax.servlet-api:3.1.0'
}
// [END dependencies]

// You must replace YOUR_PROJECT_ID with your Google Cloud Project Id
def projectId = 'YOUR_PROJECT_ID'

// [START endpoints_server_configuration]
endpointsServer {
// Endpoints Framework Plugin server-side configuration
hostname = "${projectId}.appspot.com"
}
// [END endpoints_server_configuration]

appengine { // App Engine tasks configuration
deploy { // deploy configuration
version = findProperty("appengine.deploy.version")

def promoteProp = findProperty("appengine.deploy.promote")
if (promoteProp != null) {
promote = new Boolean(promoteProp)
}
}
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

task wrapper(type: Wrapper) {
gradleVersion = '3.5'
}

// this replaces the ${endpoints.project.id} in appengine-web.xml and web.xml
task replaceProjectId(type: Copy) {
from 'src/main/webapp/WEB-INF/'
include '*.xml'
into "build/exploded-${archivesBaseName}/WEB-INF"
expand(endpoints:[project:[id:projectId]])
filteringCharset = 'UTF-8'
}
assemble.dependsOn replaceProjectId
110 changes: 110 additions & 0 deletions appengine-java8/endpoints-v2-skeleton/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<!--
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.
-->
<project>
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>

<groupId>com.example.skeleton</groupId>
<artifactId>endpoints-j8-skeleton</artifactId>

<parent>
<artifactId>appengine-java8-samples</artifactId>
<groupId>com.google.cloud</groupId>
<version>1.0.0</version>
<relativePath>..</relativePath>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>

<!-- [START pom_dependencies] -->
<dependencies>
<!-- Compile/runtime dependencies -->
<dependency>
<groupId>com.google.endpoints</groupId>
<artifactId>endpoints-framework</artifactId>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>1.9.59</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
</dependencies>
<!-- [END pom_dependencies] -->

<!-- [START pom_build] -->
<build>
<!-- for hot reload of the web application-->
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<webResources>
<resources>
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
<filtering>true</filtering>
<targetPath>WEB-INF</targetPath>
</resources>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<!-- deploy configuration -->
</configuration>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>endpoints-framework-maven-plugin</artifactId>
<version>1.0.2</version>
<configuration>
<!-- plugin configuration -->
<!--
You must replace YOUR_PROJECT_ID with your
Google Cloud Project Id
-->
<hostname>YOUR_PROJECT_ID.appspot.com</hostname>
</configuration>
</plugin>
</plugins>
</build>
<!-- [END pom_build] -->
</project>
<!-- [END pom] -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 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.
*/

package com.example.skeleton;

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

/**
* MyApi skeleton endpoints sample
* Add your first API methods in this class, or you may create another class.
* In that case, update the src/main/webapp/WEB-INF/web.xml and modify
* the class set to the services param as a comma separated list.
*
* For example:
* <init-param>
* <param-name>services</param-name>
* <param-value>com.example.skeleton.FirstApi, com.example.skeleton.SecondApi</param-value>
* </init-param>
*
*/
@Api(name = "skeleton-api",
version = "v1")
public class MyApi {
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<!-- [START appengine_web_xml] -->
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<runtime>java8</runtime>
<threadsafe>true</threadsafe>

<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
</system-properties>
</appengine-web-app>
<!-- [END appengine_web_xml] -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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.

# 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!--
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.
-->
<!-- [START web_xml] -->
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<!-- Wrap the backend with Endpoints Frameworks v2. -->
<servlet>
<servlet-name>EndpointsServlet</servlet-name>
<servlet-class>com.google.api.server.spi.EndpointsServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value>com.example.skeleton.MyApi</param-value>
</init-param>
</servlet>
<!-- Route API method requests to the backend. -->
<servlet-mapping>
<servlet-name>EndpointsServlet</servlet-name>
<url-pattern>/_ah/api/*</url-pattern>
</servlet-mapping>
</web-app>
<!-- [END web_xml] -->
1 change: 1 addition & 0 deletions appengine-java8/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<module>endpoints-v2-backend</module>
<module>endpoints-v2-migration</module>
<module>endpoints-v2-guice</module>
<module>endpoints-v2-skeleton</module>

<module>firebase-event-proxy</module>

Expand Down

0 comments on commit ea4abcf

Please sign in to comment.