Skip to content

Commit d00ca72

Browse files
authored
Merge branch 'master' into tswast-patch-1
2 parents c367fd0 + 2ec36ec commit d00ca72

File tree

26 files changed

+1499
-960
lines changed

26 files changed

+1499
-960
lines changed

appengine-java8/endpoints-v2-backend/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
<plugin>
101101
<groupId>com.google.cloud.tools</groupId>
102102
<artifactId>endpoints-framework-maven-plugin</artifactId>
103-
<version>1.0.0</version>
103+
<version>1.0.1</version>
104104
<configuration>
105105
<!-- plugin configuration -->
106106
<hostname>${endpoints.project.id}.appspot.com</hostname>

appengine-java8/endpoints-v2-guice/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ To add the project ID:
1717
0. For `<endpoints.project.id>`, replace the value `YOUR_PROJECT_ID` with
1818
your project ID.
1919

20-
0. Edit the file `src/main/java/com/example/echo/Echo.java`.
20+
0. Edit the file `src/main/java/com/example/echo/Echo.java` and
21+
`src/main/java/com/example/echo/EchoEndpointModule.java`.
2122

2223
0. Replace the value `YOUR-PROJECT-ID` with your project ID.
2324

@@ -82,7 +83,8 @@ You will get a 200 response with the following data:
8283
0. For `def projectId = 'YOUR_PROJECT_ID'`, replace the value `YOUR_PROJECT_ID`
8384
with your project ID.
8485

85-
0. Edit the file `src/main/java/com/example/echo/Echo.java
86+
0. Edit the file `src/main/java/com/example/echo/Echo.java` and
87+
`src/main/java/com/example/echo/EchoEndpointModule.java`.
8688

8789
0. Replace the value `YOUR-PROJECT-ID` with your project ID.
8890

appengine-java8/endpoints-v2-guice/src/main/java/com/example/echo/EchoEndpointModule.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,32 @@
1616

1717
package com.example.echo;
1818

19+
import com.google.api.control.ServiceManagementConfigFilter;
20+
import com.google.api.control.extensions.appengine.GoogleAppEngineControlFilter;
21+
import com.google.api.server.spi.EndpointsServlet;
1922
import com.google.api.server.spi.guice.EndpointsModule;
2023
import com.google.common.collect.ImmutableList;
24+
import com.google.inject.servlet.GuiceFilter;
25+
import java.util.HashMap;
26+
import java.util.Map;
27+
import javax.inject.Singleton;
2128

2229
// [START endpoints_module]
2330
public class EchoEndpointModule extends EndpointsModule {
2431
@Override
2532
public void configureServlets() {
33+
super.configureServlets();
34+
35+
bind(ServiceManagementConfigFilter.class).in(Singleton.class);
36+
filter("/_ah/api/*").through(ServiceManagementConfigFilter.class);
37+
38+
Map<String, String> apiController = new HashMap<String, String>();
39+
apiController.put("endpoints.projectId", "YOUR-PROJECT-ID");
40+
apiController.put("endpoints.serviceName", "YOUR-PROJECT-ID.appspot.com");
41+
42+
bind(GoogleAppEngineControlFilter.class).in(Singleton.class);
43+
filter("/_ah/api/*").through(GoogleAppEngineControlFilter.class, apiController);
44+
2645
bind(Echo.class).toInstance(new Echo());
2746
configureEndpoints("/_ah/api/*", ImmutableList.of(Echo.class));
2847
}

appengine-java8/endpoints-v2-guice/src/main/webapp/WEB-INF/web.xml

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
2323
</filter>
2424

25+
<!--
26+
URL Pattern /_ah/api/* instead of /* because a legacy v1 servlet uses
27+
the route /_ah/api/ and using /* will erronously use the legacy v1
28+
servlet instead of routing to your API.
29+
-->
2530
<filter-mapping>
2631
<filter-name>guiceFilter</filter-name>
2732
<url-pattern>/_ah/api/*</url-pattern>
@@ -35,33 +40,4 @@
3540
<welcome-file>index.html</welcome-file>
3641
</welcome-file-list>
3742

38-
<!-- Add a filter that fetches the service config from service management. -->
39-
<filter>
40-
<filter-name>endpoints-api-configuration</filter-name>
41-
<filter-class>com.google.api.control.ServiceManagementConfigFilter</filter-class>
42-
</filter>
43-
44-
<!-- Add a filter that performs Endpoints logging and monitoring. -->
45-
<filter>
46-
<filter-name>endpoints-api-controller</filter-name>
47-
<filter-class>com.google.api.control.extensions.appengine.GoogleAppEngineControlFilter</filter-class>
48-
<init-param>
49-
<param-name>endpoints.projectId</param-name>
50-
<param-value>${endpoints.project.id}</param-value>
51-
</init-param>
52-
<init-param>
53-
<param-name>endpoints.serviceName</param-name>
54-
<param-value>${endpoints.project.id}.appspot.com</param-value>
55-
</init-param>
56-
</filter>
57-
58-
<filter-mapping>
59-
<filter-name>endpoints-api-configuration</filter-name>
60-
<servlet-name>EndpointsServlet</servlet-name>
61-
</filter-mapping>
62-
63-
<filter-mapping>
64-
<filter-name>endpoints-api-controller</filter-name>
65-
<servlet-name>EndpointsServlet</servlet-name>
66-
</filter-mapping>
6743
</web-app>

appengine/endpoints-frameworks-v2/backend/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
<plugin>
8686
<groupId>com.google.cloud.tools</groupId>
8787
<artifactId>endpoints-framework-maven-plugin</artifactId>
88-
<version>1.0.0</version>
88+
<version>1.0.1</version>
8989
<configuration>
9090
<!-- plugin configuration -->
9191
<hostname>${endpoints.project.id}.appspot.com</hostname>

appengine/endpoints-frameworks-v2/guice-example/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ To add the project ID:
1717
0. For `<endpoints.project.id>`, replace the value `YOUR_PROJECT_ID` with
1818
your project ID.
1919

20-
0. Edit the file `src/main/java/com/example/echo/Echo.java`.
20+
0. Edit the file `src/main/java/com/example/echo/Echo.java` and
21+
`src/main/java/com/example/echo/EchoEndpointModule.java`.
2122

2223
0. Replace the value `YOUR-PROJECT-ID` with your project ID.
2324

@@ -82,7 +83,8 @@ You will get a 200 response with the following data:
8283
0. For `def projectId = 'YOUR_PROJECT_ID'`, replace the value `YOUR_PROJECT_ID`
8384
with your project ID.
8485

85-
0. Edit the file `src/main/java/com/example/echo/Echo.java
86+
0. Edit the file `src/main/java/com/example/echo/Echo.java` and
87+
`src/main/java/com/example/echo/EchoEndpointModule.java`
8688

8789
0. Replace the value `YOUR-PROJECT-ID` with your project ID.
8890

appengine/endpoints-frameworks-v2/guice-example/src/main/java/com/example/echo/EchoEndpointModule.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,34 @@
1616

1717
package com.example.echo;
1818

19+
import com.google.api.control.ServiceManagementConfigFilter;
20+
import com.google.api.control.extensions.appengine.GoogleAppEngineControlFilter;
21+
import com.google.api.server.spi.EndpointsServlet;
1922
import com.google.api.server.spi.guice.EndpointsModule;
2023
import com.google.common.collect.ImmutableList;
24+
import com.google.inject.servlet.GuiceFilter;
25+
import java.util.HashMap;
26+
import java.util.Map;
27+
import javax.inject.Singleton;
2128

2229
// [START endpoints_module]
2330
public class EchoEndpointModule extends EndpointsModule {
2431
@Override
2532
public void configureServlets() {
33+
super.configureServlets();
34+
35+
bind(ServiceManagementConfigFilter.class).in(Singleton.class);
36+
filter("/_ah/api/*").through(ServiceManagementConfigFilter.class);
37+
38+
Map<String, String> apiController = new HashMap<String, String>();
39+
apiController.put("endpoints.projectId", "YOUR-PROJECT-ID");
40+
apiController.put("endpoints.serviceName", "YOUR-PROJECT-ID.appspot.com");
41+
42+
bind(GoogleAppEngineControlFilter.class).in(Singleton.class);
43+
filter("/_ah/api/*").through(GoogleAppEngineControlFilter.class, apiController);
44+
2645
bind(Echo.class).toInstance(new Echo());
2746
configureEndpoints("/_ah/api/*", ImmutableList.of(Echo.class));
28-
super.configureServlets();
2947
}
3048
}
3149
// [END endpoints_module]

appengine/endpoints-frameworks-v2/guice-example/src/main/main74.iml

Lines changed: 0 additions & 12 deletions
This file was deleted.

appengine/endpoints-frameworks-v2/guice-example/src/main/webapp/WEB-INF/web.xml

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
2323
</filter>
2424

25+
<!--
26+
URL Pattern /_ah/api/* instead of /* because a legacy v1 servlet uses
27+
the route /_ah/api/ and using /* will erronously use the legacy v1
28+
servlet instead of routing to your API.
29+
-->
2530
<filter-mapping>
2631
<filter-name>guiceFilter</filter-name>
2732
<url-pattern>/_ah/api/*</url-pattern>
@@ -35,33 +40,4 @@
3540
<welcome-file>index.html</welcome-file>
3641
</welcome-file-list>
3742

38-
<!-- Add a filter that fetches the service config from service management. -->
39-
<filter>
40-
<filter-name>endpoints-api-configuration</filter-name>
41-
<filter-class>com.google.api.control.ServiceManagementConfigFilter</filter-class>
42-
</filter>
43-
44-
<!-- Add a filter that performs Endpoints logging and monitoring. -->
45-
<filter>
46-
<filter-name>endpoints-api-controller</filter-name>
47-
<filter-class>com.google.api.control.extensions.appengine.GoogleAppEngineControlFilter</filter-class>
48-
<init-param>
49-
<param-name>endpoints.projectId</param-name>
50-
<param-value>${endpoints.project.id}</param-value>
51-
</init-param>
52-
<init-param>
53-
<param-name>endpoints.serviceName</param-name>
54-
<param-value>${endpoints.project.id}.appspot.com</param-value>
55-
</init-param>
56-
</filter>
57-
58-
<filter-mapping>
59-
<filter-name>endpoints-api-configuration</filter-name>
60-
<servlet-name>EndpointsServlet</servlet-name>
61-
</filter-mapping>
62-
63-
<filter-mapping>
64-
<filter-name>endpoints-api-controller</filter-name>
65-
<servlet-name>EndpointsServlet</servlet-name>
66-
</filter-mapping>
6743
</web-app>

iot/api-client/manager/README.md

Lines changed: 107 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ PubSub topic for Cloud IoT as described in [the parent README](../README.md).
1010
Manually install [the provided client library](https://cloud.google.com/iot/resources/java/cloud-iot-core-library.jar)
1111
for Cloud IoT Core to Maven:
1212

13-
mvn install:install-file -Dfile=cloud-iot-core-library.jar -DgroupId=com.google.apis \
13+
mvn install:install-file -Dfile=cloud-iot-core-library.jar -DgroupId=com.example.apis \
1414
-DartifactId=google-api-services-cloudiot -Dversion=v1beta1-rev20170418-1.22.0-SNAPSHOT \
1515
-Dpackaging=jar
1616

@@ -21,23 +21,116 @@ mvn clean compile assembly:single
2121

2222
## Running the sample
2323

24-
The following command summarizes the sample usage:
24+
The following description summarizes the sample usage:
2525

26-
mvn exec:java \
27-
-Dexec.mainClass="com.google.cloud.iot.examples.DeviceRegistryExample" \
28-
-Dexec.args="-project_id=my-project-id \
29-
-pubsub_topic=projects/my-project-id/topics/my-topic-id \
30-
-ec_public_key_file=/path/to/ec_public.pem \
31-
-rsa_certificate_file=/path/to/rsa_cert.pem"
26+
usage: DeviceRegistryExample [--cloud_region <arg>] --command <arg>
27+
[--ec_public_key_file <arg>] --project_id <arg> --pubsub_topic
28+
<arg> --registry_name <arg> [--rsa_certificate_file <arg>]
29+
30+
Cloud IoT Core Commandline Example (Device / Registry management):
31+
32+
--cloud_region <arg> GCP cloud region.
33+
--command <arg> Command to run:
34+
create-iot-topic
35+
create-rsa
36+
create-es
37+
create-unauth
38+
create-registry
39+
delete-device
40+
delete-registry
41+
get-device
42+
get-registry
43+
list-devices
44+
list-registries
45+
patch-device-es
46+
patch-device-rsa
47+
--ec_public_key_file <arg> Path to ES256 public key file.
48+
--project_id <arg> GCP cloud project name.
49+
--pubsub_topic <arg> Pub/Sub topic to create registry in.
50+
--registry_name <arg> Name for your Device Registry.
51+
--rsa_certificate_file <arg> Path to RS256 certificate file.
52+
53+
https://cloud.google.com/iot-core
3254

3355
For example, if your project ID is `blue-jet-123`, your service account
3456
credentials are stored in your home folder in creds.json and you have generated
3557
your credentials using the shell script provided in the parent folder, you can
3658
run the sample as:
3759

38-
mvn exec:java \
39-
-Dexec.mainClass="com.google.cloud.iot.examples.DeviceRegistryExample" \
40-
-Dexec.args="-project_id=blue-jet-123 \
41-
-pubsub_topic=projects/blue-jet-123/topics/device-events \
42-
-ec_public_key_file=../ec_public.pem \
43-
-rsa_certificate_file=../rsa_cert.pem"
60+
61+
## Usage Examples
62+
63+
Create a PubSub topic, `hello-java`, for the project, `blue-jet-123`:
64+
65+
java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
66+
com.example.cloud.iot.examples.DeviceRegistryExample \
67+
-project_id=blue-jet-123 -pubsub_topic=hello-java
68+
-command=create-iot-topic
69+
70+
Create an ES device:
71+
72+
java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
73+
com.example.cloud.iot.examples.DeviceRegistryExample \
74+
-project_id=blue-jet-123 -pubsub_topic=hello-java \
75+
-registry_name=hello-java -ec_public_key_file ../ec_public.pem \
76+
-device_id="java-device-0" -command=create-es
77+
78+
Create an RSA device:
79+
80+
java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
81+
com.example.cloud.iot.examples.DeviceRegistryExample \
82+
-project_id=blue-jet-123 -pubsub_topic=hello-java \
83+
-registry_name=hello-java -rsa_certificate_file ../rsa_cert.pem \
84+
-device_id="java-device-1" -command=create-rsa
85+
86+
Create a device without authorization:
87+
88+
java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
89+
com.example.cloud.iot.examples.DeviceRegistryExample \
90+
-project_id=blue-jet-123 -pubsub_topic=hello-java \
91+
-registry_name=hello-java -device_id="java-device-3" \
92+
-command=create-unauth
93+
94+
Create a device registry:
95+
96+
java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
97+
com.example.cloud.iot.examples.DeviceRegistryExample \
98+
-project_id=blue-jet-123 -pubsub_topic=hello-java \
99+
-registry_name=hello-java -command=create-registry \
100+
101+
Get a device registry:
102+
103+
java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
104+
com.example.cloud.iot.examples.DeviceRegistryExample \
105+
-project_id=blue-jet-123 -pubsub_topic=hello-java \
106+
-registry_name=hello-java -command=get-registry
107+
108+
List devices:
109+
110+
java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
111+
com.example.cloud.iot.examples.DeviceRegistryExample \
112+
-project_id=blue-jet-123 -pubsub_topic=hello-java \
113+
-registry_name=hello-java -command=list-devices
114+
115+
List device registries:
116+
117+
java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
118+
com.example.cloud.iot.examples.DeviceRegistryExample \
119+
-project_id=blue-jet-123 -pubsub_topic=hello-java \
120+
-registry_name=hello-java -command=list-registries
121+
122+
Patch a device with ES:
123+
124+
java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
125+
com.example.cloud.iot.examples.DeviceRegistryExample \
126+
-project_id=blue-jet-123 -pubsub_topic=hello-java \
127+
-registry_name=hello-java -ec_public_key_file ../ec_public.pem \
128+
-device_id="java-device-1" -command=patch-device-es
129+
130+
Patch a device with RSA:
131+
132+
java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
133+
com.example.cloud.iot.examples.DeviceRegistryExample \
134+
-project_id=blue-jet-123 -pubsub_topic=hello-java \
135+
-registry_name=hello-java -rsa_certificate_file ../rsa_cert.pem \
136+
-device_id="java-device-0" -command=patch-device-rsa

0 commit comments

Comments
 (0)