Skip to content

Commit 4932176

Browse files
authored
move appengine v1 sample here (GoogleCloudPlatform#860)
* move appengine v1 sample here * fix readme * fix the right README
1 parent 6539664 commit 4932176

File tree

12 files changed

+583
-0
lines changed

12 files changed

+583
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
endpoints-skeleton
2+
==================
3+
4+
# DEPRECATED
5+
6+
### This sample uses endpoints v1 the preferred strategy for new development is to use Endpoints v2
7+
8+
A skeleton application for Google Cloud Endpoints in Java.
9+
10+
- [App Engine][1]
11+
12+
- [Java][2]
13+
14+
- [Google Cloud Endpoints][3]
15+
- [Google App Engine Maven plugin][4]
16+
17+
18+
1. Update the value of `application` in `appengine-web.xml` to the app
19+
ID you have registered in the App Engine admin console and would
20+
like to use to host your instance of this sample.
21+
22+
1. Add your API method to `src/main/java/com/example/helloworld/YourFirstAPI.java`.
23+
24+
1. Optional step: These sub steps are not required but you need this
25+
if you want to have auth protected methods.
26+
27+
1. Update the values in `src/main/java/com/example/helloworld/Constants.java`
28+
to reflect the respective client IDs you have registered in the
29+
[APIs Console][6].
30+
31+
1. You also need to supply the web client ID you have registered
32+
in the [APIs Console][4] to your client of choice (web, Android,
33+
iOS).
34+
35+
1. Run the application with `mvn appengine:devserver`, and ensure it's
36+
running by visiting your local server's api explorer's address (by
37+
default [localhost:8080/_ah/api/explorer][5].)
38+
39+
1. Get the client library with
40+
41+
$ mvn appengine:endpoints_get_client_lib
42+
43+
It will generate a client library jar file under the
44+
`target/endpoints-client-libs/<api-name>/target` directory of your
45+
project, as well as install the artifact into your local maven
46+
repository.
47+
48+
1. Deploy your application to Google App Engine with
49+
50+
$ mvn appengine:update
51+
52+
[1]: https://developers.google.com/appengine
53+
[2]: http://java.com/en/
54+
[3]: https://developers.google.com/appengine/docs/java/endpoints/
55+
[4]: https://developers.google.com/appengine/docs/java/tools/maven
56+
[5]: https://localhost:8080/_ah/api/explorer
57+
[6]: https://console.developers.google.com/
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright 2016 Google Inc. All Rights Reserved.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6+
in compliance with the License. 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 distributed under the License
11+
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12+
or implied. See the License for the specific language governing permissions and limitations under
13+
the License.
14+
-->
15+
<project>
16+
17+
<modelVersion>4.0.0</modelVersion>
18+
<packaging>war</packaging>
19+
<version>1.0-SNAPSHOT</version>
20+
21+
<groupId>com.example.helloworld</groupId>
22+
<artifactId>helloworld</artifactId>
23+
24+
<parent>
25+
<groupId>com.google.cloud</groupId>
26+
<artifactId>appengine-doc-samples</artifactId>
27+
<version>1.0.0</version>
28+
<relativePath>..</relativePath>
29+
</parent>
30+
31+
<properties>
32+
<appengine.app.version>1</appengine.app.version>
33+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
34+
35+
<appengine.plugin.version>1.9.56</appengine.plugin.version>
36+
<maven.compiler.source>1.7</maven.compiler.source>
37+
<maven.compiler.target>1.7</maven.compiler.target>
38+
</properties>
39+
40+
<prerequisites>
41+
<maven>3.1.0</maven>
42+
</prerequisites>
43+
44+
<dependencies>
45+
<!-- Compile/runtime dependencies -->
46+
<dependency>
47+
<groupId>com.google.appengine</groupId>
48+
<artifactId>appengine-api-1.0-sdk</artifactId>
49+
<version>${appengine.plugin.version}</version>
50+
</dependency>
51+
<dependency>
52+
<groupId>com.google.appengine</groupId>
53+
<artifactId>appengine-endpoints</artifactId>
54+
<version>${appengine.plugin.version}</version>
55+
</dependency>
56+
<dependency>
57+
<groupId>javax.servlet</groupId>
58+
<artifactId>servlet-api</artifactId>
59+
<version>2.5</version>
60+
<scope>provided</scope>
61+
</dependency>
62+
<dependency>
63+
<groupId>javax.inject</groupId>
64+
<artifactId>javax.inject</artifactId>
65+
<version>1</version>
66+
</dependency>
67+
68+
<!-- Test Dependencies -->
69+
<dependency>
70+
<groupId>junit</groupId>
71+
<artifactId>junit</artifactId>
72+
<version>4.11</version>
73+
<scope>test</scope>
74+
</dependency>
75+
<dependency>
76+
<groupId>org.mockito</groupId>
77+
<artifactId>mockito-all</artifactId>
78+
<version>1.9.5</version>
79+
<scope>test</scope>
80+
</dependency>
81+
<dependency>
82+
<groupId>com.google.appengine</groupId>
83+
<artifactId>appengine-testing</artifactId>
84+
<version>${appengine.plugin.version}</version>
85+
<scope>test</scope>
86+
</dependency>
87+
<dependency>
88+
<groupId>com.google.appengine</groupId>
89+
<artifactId>appengine-api-stubs</artifactId>
90+
<version>${appengine.plugin.version}</version>
91+
<scope>test</scope>
92+
</dependency>
93+
</dependencies>
94+
95+
<build>
96+
<!-- for hot reload of the web application-->
97+
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
98+
<plugins>
99+
<plugin>
100+
<groupId>org.codehaus.mojo</groupId>
101+
<artifactId>versions-maven-plugin</artifactId>
102+
<version>2.2</version>
103+
<executions>
104+
<execution>
105+
<phase>compile</phase>
106+
<goals>
107+
<goal>display-dependency-updates</goal>
108+
<goal>display-plugin-updates</goal>
109+
</goals>
110+
</execution>
111+
</executions>
112+
</plugin>
113+
114+
<plugin>
115+
<groupId>org.apache.maven.plugins</groupId>
116+
<artifactId>maven-war-plugin</artifactId>
117+
<version>2.6</version>
118+
<configuration>
119+
<webXml>${project.build.directory}/generated-sources/appengine-endpoints/WEB-INF/web.xml</webXml>
120+
<webResources>
121+
<resource>
122+
<!-- this is relative to the pom.xml directory -->
123+
<directory>${project.build.directory}/generated-sources/appengine-endpoints</directory>
124+
<!-- the list has a default value of ** -->
125+
<includes>
126+
<include>WEB-INF/*.discovery</include>
127+
<include>WEB-INF/*.api</include>
128+
</includes>
129+
</resource>
130+
</webResources>
131+
</configuration>
132+
</plugin>
133+
134+
<plugin>
135+
<groupId>com.google.appengine</groupId>
136+
<artifactId>appengine-maven-plugin</artifactId>
137+
<version>${appengine.plugin.version}</version>
138+
<configuration>
139+
<enableJarClasses>false</enableJarClasses>
140+
<!-- Comment in the below snippet to bind to all IPs instead of just localhost -->
141+
<!-- address>0.0.0.0</address>
142+
<port>8080</port -->
143+
<!-- Comment in the below snippet to enable local debugging with a remove debugger
144+
like those included with Eclipse or IntelliJ -->
145+
<!-- jvmFlags>
146+
<jvmFlag>-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n</jvmFlag>
147+
</jvmFlags -->
148+
</configuration>
149+
<executions>
150+
<execution>
151+
<goals>
152+
<goal>endpoints_get_discovery_doc</goal>
153+
</goals>
154+
</execution>
155+
</executions>
156+
</plugin>
157+
</plugins>
158+
</build>
159+
160+
</project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
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 http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.example.helloworld;
15+
16+
import com.google.api.server.spi.config.ApiTransformer;
17+
18+
// [START all]
19+
@ApiTransformer(BarTransformer.class)
20+
public class Bar {
21+
private final int x;
22+
private final int y;
23+
24+
public Bar(int x, int y) {
25+
this.x = x;
26+
this.y = y;
27+
}
28+
29+
public int getX() {
30+
return x;
31+
}
32+
33+
public int getY() {
34+
return y;
35+
}
36+
}
37+
// [END all]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
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 http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.example.helloworld;
15+
16+
import com.google.api.server.spi.config.Transformer;
17+
18+
// [START all]
19+
public class BarTransformer implements Transformer<Bar, String> {
20+
public String transformTo(Bar in) {
21+
return in.getX() + "," + in.getY();
22+
}
23+
24+
public Bar transformFrom(String in) {
25+
String[] xy = in.split(",");
26+
return new Bar(Integer.parseInt(xy[0]), Integer.parseInt(xy[1]));
27+
}
28+
}
29+
// [END all]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright 2016 Google Inc. All Rights Reserved.
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+
17+
package com.example.helloworld;
18+
19+
// [START all]
20+
/**
21+
* Contains the client IDs and scopes for allowed clients consuming your API.
22+
*/
23+
public class Constants {
24+
public static final String WEB_CLIENT_ID = "replace this with your web client ID";
25+
public static final String ANDROID_CLIENT_ID = "replace this with your Android client ID";
26+
public static final String IOS_CLIENT_ID = "replace this with your iOS client ID";
27+
public static final String ANDROID_AUDIENCE = WEB_CLIENT_ID;
28+
29+
public static final String EMAIL_SCOPE = "https://www.googleapis.com/auth/userinfo.email";
30+
}
31+
// [END all]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. 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 distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
package com.example.helloworld;
15+
16+
//[START all]
17+
18+
/** The object model for the data we are sending through endpoints */
19+
public class MyBean {
20+
21+
private String myData;
22+
23+
public String getData() {
24+
return myData;
25+
}
26+
27+
public void setData(String data) {
28+
myData = data;
29+
}
30+
}
31+
//[END all]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
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 http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.example.helloworld;
15+
16+
// [START all]
17+
import com.google.api.server.spi.ServiceException;
18+
19+
// Exceptions must inherit from ServiceException
20+
public class RequestTimeoutException extends ServiceException {
21+
public RequestTimeoutException(String message) {
22+
super(408, message);
23+
}
24+
}
25+
// [END all]

0 commit comments

Comments
 (0)