Skip to content

Commit ea4abcf

Browse files
authored
[Endpoints] Add skeleton v2 sample (GoogleCloudPlatform#916)
* 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
1 parent f663975 commit ea4abcf

File tree

8 files changed

+330
-0
lines changed

8 files changed

+330
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# App Engine Standard & Endpoints Frameworks skeleton
2+
3+
This is a skeleton example for getting setup with Endpoints Framework v2 for
4+
Java.
5+
6+
For a more complete example of using Endpoints Framework v2 for Java review
7+
the [backend example](/appengine-java8/endpoints-v2-backend).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright 2017 Google Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.import org.apache.tools.ant.filters.ReplaceTokens
14+
15+
// [START build_script]
16+
buildscript {
17+
repositories {
18+
mavenCentral()
19+
}
20+
21+
dependencies {
22+
classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.2'
23+
classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.3.3'
24+
}
25+
}
26+
// [END build_script]
27+
28+
repositories {
29+
mavenCentral()
30+
}
31+
32+
// [START plugin_applys]
33+
apply plugin: 'java'
34+
apply plugin: 'war'
35+
apply plugin: 'com.google.cloud.tools.endpoints-framework-server'
36+
apply plugin: 'com.google.cloud.tools.appengine'
37+
// [END plugin_applys]
38+
39+
// [START dependencies]
40+
dependencies {
41+
compile 'com.google.endpoints:endpoints-framework:2.0.9'
42+
compile 'com.google.appengine:appengine-api-1.0-sdk:1.9.59'
43+
44+
compile 'javax.inject:javax.inject:1'
45+
compileOnly 'javax.servlet:javax.servlet-api:3.1.0'
46+
}
47+
// [END dependencies]
48+
49+
// You must replace YOUR_PROJECT_ID with your Google Cloud Project Id
50+
def projectId = 'YOUR_PROJECT_ID'
51+
52+
// [START endpoints_server_configuration]
53+
endpointsServer {
54+
// Endpoints Framework Plugin server-side configuration
55+
hostname = "${projectId}.appspot.com"
56+
}
57+
// [END endpoints_server_configuration]
58+
59+
appengine { // App Engine tasks configuration
60+
deploy { // deploy configuration
61+
version = findProperty("appengine.deploy.version")
62+
63+
def promoteProp = findProperty("appengine.deploy.promote")
64+
if (promoteProp != null) {
65+
promote = new Boolean(promoteProp)
66+
}
67+
}
68+
}
69+
70+
sourceCompatibility = 1.8
71+
targetCompatibility = 1.8
72+
73+
task wrapper(type: Wrapper) {
74+
gradleVersion = '3.5'
75+
}
76+
77+
// this replaces the ${endpoints.project.id} in appengine-web.xml and web.xml
78+
task replaceProjectId(type: Copy) {
79+
from 'src/main/webapp/WEB-INF/'
80+
include '*.xml'
81+
into "build/exploded-${archivesBaseName}/WEB-INF"
82+
expand(endpoints:[project:[id:projectId]])
83+
filteringCharset = 'UTF-8'
84+
}
85+
assemble.dependsOn replaceProjectId
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<!--
2+
Copyright 2017 Google Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
<project>
17+
<modelVersion>4.0.0</modelVersion>
18+
<packaging>war</packaging>
19+
<version>1.0-SNAPSHOT</version>
20+
21+
<groupId>com.example.skeleton</groupId>
22+
<artifactId>endpoints-j8-skeleton</artifactId>
23+
24+
<parent>
25+
<artifactId>appengine-java8-samples</artifactId>
26+
<groupId>com.google.cloud</groupId>
27+
<version>1.0.0</version>
28+
<relativePath>..</relativePath>
29+
</parent>
30+
31+
<properties>
32+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
33+
34+
<maven.compiler.target>1.8</maven.compiler.target>
35+
<maven.compiler.source>1.8</maven.compiler.source>
36+
</properties>
37+
38+
<!-- [START pom_dependencies] -->
39+
<dependencies>
40+
<!-- Compile/runtime dependencies -->
41+
<dependency>
42+
<groupId>com.google.endpoints</groupId>
43+
<artifactId>endpoints-framework</artifactId>
44+
<version>2.0.9</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>com.google.appengine</groupId>
48+
<artifactId>appengine-api-1.0-sdk</artifactId>
49+
<version>1.9.59</version>
50+
</dependency>
51+
<dependency>
52+
<groupId>javax.servlet</groupId>
53+
<artifactId>javax.servlet-api</artifactId>
54+
<version>3.1.0</version>
55+
<type>jar</type>
56+
<scope>provided</scope>
57+
</dependency>
58+
<dependency>
59+
<groupId>javax.inject</groupId>
60+
<artifactId>javax.inject</artifactId>
61+
<version>1</version>
62+
</dependency>
63+
</dependencies>
64+
<!-- [END pom_dependencies] -->
65+
66+
<!-- [START pom_build] -->
67+
<build>
68+
<!-- for hot reload of the web application-->
69+
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
70+
<plugins>
71+
<plugin>
72+
<groupId>org.apache.maven.plugins</groupId>
73+
<artifactId>maven-war-plugin</artifactId>
74+
<version>2.6</version>
75+
<configuration>
76+
<webResources>
77+
<resources>
78+
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
79+
<filtering>true</filtering>
80+
<targetPath>WEB-INF</targetPath>
81+
</resources>
82+
</webResources>
83+
</configuration>
84+
</plugin>
85+
<plugin>
86+
<groupId>com.google.cloud.tools</groupId>
87+
<artifactId>appengine-maven-plugin</artifactId>
88+
<version>1.3.2</version>
89+
<configuration>
90+
<!-- deploy configuration -->
91+
</configuration>
92+
</plugin>
93+
<plugin>
94+
<groupId>com.google.cloud.tools</groupId>
95+
<artifactId>endpoints-framework-maven-plugin</artifactId>
96+
<version>1.0.2</version>
97+
<configuration>
98+
<!-- plugin configuration -->
99+
<!--
100+
You must replace YOUR_PROJECT_ID with your
101+
Google Cloud Project Id
102+
-->
103+
<hostname>YOUR_PROJECT_ID.appspot.com</hostname>
104+
</configuration>
105+
</plugin>
106+
</plugins>
107+
</build>
108+
<!-- [END pom_build] -->
109+
</project>
110+
<!-- [END pom] -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2017 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
* not use this file except in compliance with the License. You may obtain a
6+
* copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
package com.example.skeleton;
18+
19+
import com.google.api.server.spi.config.Api;
20+
21+
/**
22+
* MyApi skeleton endpoints sample
23+
* Add your first API methods in this class, or you may create another class.
24+
* In that case, update the src/main/webapp/WEB-INF/web.xml and modify
25+
* the class set to the services param as a comma separated list.
26+
*
27+
* For example:
28+
* <init-param>
29+
* <param-name>services</param-name>
30+
* <param-value>com.example.skeleton.FirstApi, com.example.skeleton.SecondApi</param-value>
31+
* </init-param>
32+
*
33+
*/
34+
@Api(name = "skeleton-api",
35+
version = "v1")
36+
public class MyApi {
37+
}
38+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2017 Google Inc.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<!-- [START appengine_web_xml] -->
18+
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
19+
<runtime>java8</runtime>
20+
<threadsafe>true</threadsafe>
21+
22+
<system-properties>
23+
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
24+
</system-properties>
25+
</appengine-web-app>
26+
<!-- [END appengine_web_xml] -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2017 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4+
# in compliance with the License. You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software distributed under the License
9+
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10+
# or implied. See the License for the specific language governing permissions and limitations under
11+
# the License.
12+
13+
# A default java.util.logging configuration.
14+
# (All App Engine logging is through java.util.logging by default).
15+
#
16+
# To use this configuration, copy it into your application's WEB-INF
17+
# folder and add the following to your appengine-web.xml:
18+
#
19+
# <system-properties>
20+
# <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
21+
# </system-properties>
22+
#
23+
24+
# Set the default logging level for all loggers to WARNING
25+
.level = WARNING
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="utf-8" standalone="no"?>
2+
<!--
3+
Copyright 2017 Google Inc.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<!-- [START web_xml] -->
18+
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
21+
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
22+
version="3.1">
23+
<!-- Wrap the backend with Endpoints Frameworks v2. -->
24+
<servlet>
25+
<servlet-name>EndpointsServlet</servlet-name>
26+
<servlet-class>com.google.api.server.spi.EndpointsServlet</servlet-class>
27+
<init-param>
28+
<param-name>services</param-name>
29+
<param-value>com.example.skeleton.MyApi</param-value>
30+
</init-param>
31+
</servlet>
32+
<!-- Route API method requests to the backend. -->
33+
<servlet-mapping>
34+
<servlet-name>EndpointsServlet</servlet-name>
35+
<url-pattern>/_ah/api/*</url-pattern>
36+
</servlet-mapping>
37+
</web-app>
38+
<!-- [END web_xml] -->

appengine-java8/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<module>endpoints-v2-backend</module>
4949
<module>endpoints-v2-migration</module>
5050
<module>endpoints-v2-guice</module>
51+
<module>endpoints-v2-skeleton</module>
5152

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

0 commit comments

Comments
 (0)