Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdc863ea

Browse files
authored
feat: add GAE Standard samples for Java25 (GoogleCloudPlatform#10195)
* feat: add appengine-java25 samples* Addressing auto-review comments and taking comments from previous PRGoogleCloudPlatform#10193* Adding Lint suggestions.* Update jacoco-maven-plugin to 0.8.14 and maven-war-plugin to 3.4.0Add maven-failsafe-plugin with version 3.3.1* Changing GAE Java 25 samples to have bytecode compiled to Java21.
1 parentdb6bef7 commitdc863ea

File tree

22 files changed

+1403
-0
lines changed

22 files changed

+1403
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#Google Analytics sample for Google App Engine
2+
3+
<ahref="https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/java-docs-samples&page=editor&open_in_editor=appengine-java25/ee11/analytics/README.md">
4+
<imgalt="Open in Cloud Shell"src ="https://gstatic.com/cloudssh/images/open-btn.png"></a>
5+
6+
Integrating App Engine with Google Analytics using EE11.
7+
8+
##Project setup, installation, and configuration
9+
10+
- Register for[Google Analytics](http://www.google.com/analytics/), create
11+
an application, and get a tracking Id.
12+
-[Find your tracking Id](https://support.google.com/analytics/answer/1008080?hl=en)
13+
and set it as an environment variable in[`appengine-web.xml`](src/main/webapp/WEB-INF/appengine-web.xml).
14+
15+
##Running locally
16+
This example uses the
17+
[Maven Cloud CLI based plugin](https://cloud.google.com/appengine/docs/java/tools/using-maven).
18+
To run this sample locally:
19+
20+
$ mvn appengine:run
21+
22+
##Deploying
23+
24+
$ mvn clean package appengine:deploy
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<!--
2+
Copyright 2017 Google LLC
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+
<projectxmlns="http://maven.apache.org/POM/4.0.0"
17+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
18+
<modelVersion>4.0.0</modelVersion>
19+
<packaging>war</packaging>
20+
<version>1.0-SNAPSHOT</version>
21+
<groupId>com.example.appengine</groupId>
22+
<artifactId>appengine-analytics-j25-ee11</artifactId>
23+
24+
<!--
25+
The parent pom defines common style checks and testing strategies for our samples.
26+
Removing or replacing it should not effect the execution of the samples in anyway.
27+
-->
28+
<parent>
29+
<groupId>com.google.cloud.samples</groupId>
30+
<artifactId>shared-configuration</artifactId>
31+
<version>1.2.0</version>
32+
</parent>
33+
34+
<properties>
35+
<!--Change this to 25 in your workspace-->
36+
<maven.compiler.target>21</maven.compiler.target>
37+
<maven.compiler.source>21</maven.compiler.source>
38+
<appengine.sdk.version>3.0.1</appengine.sdk.version>
39+
</properties>
40+
41+
<dependencyManagement>
42+
<dependencies>
43+
<dependency>
44+
<artifactId>libraries-bom</artifactId>
45+
<groupId>com.google.cloud</groupId>
46+
<scope>import</scope>
47+
<type>pom</type>
48+
<version>26.28.0</version>
49+
</dependency>
50+
</dependencies>
51+
</dependencyManagement>
52+
53+
<dependencies>
54+
<!-- Compile/runtime dependencies-->
55+
<dependency>
56+
<groupId>com.google.appengine</groupId>
57+
<artifactId>appengine-api-1.0-sdk</artifactId>
58+
<version>${appengine.sdk.version}</version>
59+
</dependency>
60+
61+
<dependency>
62+
<groupId>jstl</groupId>
63+
<artifactId>jstl</artifactId>
64+
<version>1.2</version>
65+
</dependency>
66+
67+
<dependency>
68+
<groupId>org.apache.httpcomponents</groupId>
69+
<artifactId>httpclient</artifactId>
70+
<version>4.5.14</version>
71+
</dependency>
72+
73+
<dependency>
74+
<groupId>jakarta.servlet</groupId>
75+
<artifactId>jakarta.servlet-api</artifactId>
76+
<version>6.1.0</version>
77+
<type>jar</type>
78+
<scope>provided</scope>
79+
</dependency>
80+
81+
<!-- Test Dependencies-->
82+
<dependency>
83+
<groupId>com.google.appengine</groupId>
84+
<artifactId>appengine-testing</artifactId>
85+
<version>${appengine.sdk.version}</version>
86+
<scope>test</scope>
87+
</dependency>
88+
<dependency>
89+
<groupId>com.google.appengine</groupId>
90+
<artifactId>appengine-api-stubs</artifactId>
91+
<version>${appengine.sdk.version}</version>
92+
<scope>test</scope>
93+
</dependency>
94+
95+
<dependency>
96+
<groupId>junit</groupId>
97+
<artifactId>junit</artifactId>
98+
<version>4.13.2</version>
99+
<scope>test</scope>
100+
</dependency>
101+
<dependency>
102+
<groupId>org.mockito</groupId>
103+
<artifactId>mockito-core</artifactId>
104+
<version>4.11.0</version>
105+
<scope>test</scope>
106+
</dependency>
107+
<dependency>
108+
<groupId>com.google.truth</groupId>
109+
<artifactId>truth</artifactId>
110+
<version>1.1.5</version>
111+
<scope>test</scope>
112+
</dependency>
113+
</dependencies>
114+
115+
<build>
116+
<!-- for hot reload of the web application-->
117+
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
118+
<plugins>
119+
<plugin>
120+
<groupId>org.apache.maven.plugins</groupId>
121+
<artifactId>maven-compiler-plugin</artifactId>
122+
<version>3.13.0</version>
123+
</plugin>
124+
<plugin>
125+
<groupId>org.apache.maven.plugins</groupId>
126+
<artifactId>maven-war-plugin</artifactId>
127+
<version>3.4.0</version>
128+
</plugin>
129+
<plugin>
130+
<groupId>com.google.cloud.tools</groupId>
131+
<artifactId>appengine-maven-plugin</artifactId>
132+
<version>2.7.0</version>
133+
<configuration>
134+
<projectId>GCLOUD_CONFIG</projectId>
135+
<version>analytics</version>
136+
<deploy.promote>true</deploy.promote>
137+
<deploy.stopPreviousVersion>true</deploy.stopPreviousVersion>
138+
</configuration>
139+
</plugin>
140+
</plugins>
141+
</build>
142+
</project>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2015 Google LLC
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+
packagecom.example.appengine.analytics;
18+
19+
// [START gae_java25_ee11_analytics_track]
20+
21+
importcom.google.appengine.api.urlfetch.URLFetchService;
22+
importcom.google.appengine.api.urlfetch.URLFetchServiceFactory;
23+
importjakarta.servlet.ServletException;
24+
importjakarta.servlet.annotation.WebServlet;
25+
importjakarta.servlet.http.HttpServlet;
26+
importjakarta.servlet.http.HttpServletRequest;
27+
importjakarta.servlet.http.HttpServletResponse;
28+
importjava.io.IOException;
29+
importjava.net.URI;
30+
importjava.net.URISyntaxException;
31+
importjava.net.URL;
32+
importorg.apache.http.client.utils.URIBuilder;
33+
34+
@SuppressWarnings("serial")
35+
// With @WebServlet annotation the webapp/WEB-INF/web.xml is no longer required.
36+
@WebServlet(
37+
name ="analytics",
38+
description ="Analytics: Send Analytics Event to Google Analytics",
39+
urlPatterns ="/analytics")
40+
publicclassAnalyticsServletextendsHttpServlet {
41+
42+
@Override
43+
publicvoiddoGet(HttpServletRequestreq,HttpServletResponseresp)
44+
throwsIOException,ServletException {
45+
StringtrackingId =System.getenv("GA_TRACKING_ID");
46+
URIBuilderbuilder =newURIBuilder();
47+
builder
48+
.setScheme("http")
49+
.setHost("www.google-analytics.com")
50+
.setPath("/collect")
51+
.addParameter("v","1")// API Version.
52+
.addParameter("tid",trackingId)// Tracking ID / Property ID.
53+
// Anonymous Client Identifier. Ideally, this should be a UUID that
54+
// is associated with particular user, device, or browser instance.
55+
.addParameter("cid","555")
56+
.addParameter("t","event")// Event hit type.
57+
.addParameter("ec","example")// Event category.
58+
.addParameter("ea","test action");// Event action.
59+
URIuri =null;
60+
try {
61+
uri =builder.build();
62+
}catch (URISyntaxExceptione) {
63+
thrownewServletException("Problem building URI",e);
64+
}
65+
URLFetchServicefetcher =URLFetchServiceFactory.getURLFetchService();
66+
URLurl =uri.toURL();
67+
fetcher.fetch(url);
68+
resp.getWriter().println("Event tracked.");
69+
}
70+
}
71+
// [END gae_java25_ee11_analytics_track]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- [START_EXCLUDE]-->
3+
<!--
4+
Copyright 2015 Google LLC
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+
http://www.apache.org/licenses/LICENSE-2.0
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.
14+
-->
15+
<!-- [END_EXCLUDE]-->
16+
<appengine-web-appxmlns="http://appengine.google.com/ns/1.0">
17+
<runtime>java25</runtime>
18+
<app-engine-apis>true</app-engine-apis>
19+
<service>appengine-analytics-j25-ee11</service>
20+
<system-properties>
21+
<propertyname="appengine.use.EE11"value="true"/>
22+
</system-properties>
23+
<env-variables>
24+
<env-varname="GA_TRACKING_ID"value="YOUR-GA-TRACKING-ID" />
25+
</env-variables>
26+
</appengine-web-app>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- [START_EXCLUDE]-->
3+
<!--
4+
Copyright 2015 Google LLC
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+
http://www.apache.org/licenses/LICENSE-2.0
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.
14+
-->
15+
<!-- [END_EXCLUDE]-->
16+
<web-appxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="https://jakarta.ee/xml/ns/jakartaee"
17+
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_1.xsd"
18+
version="6.1">
19+
<welcome-file-list>
20+
<welcome-file>analytics</welcome-file>
21+
</welcome-file-list>
22+
</web-app>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#Google Analytics sample for Google App Engine
2+
3+
<ahref="https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/java-docs-samples&page=editor&open_in_editor=appengine-java25/ee8/analytics/README.md">
4+
<imgalt="Open in Cloud Shell"src ="https://gstatic.com/cloudssh/images/open-btn.png"></a>
5+
6+
Integrating App Engine with Google Analytics using EE8.
7+
8+
##Project setup, installation, and configuration
9+
10+
- Register for[Google Analytics](http://www.google.com/analytics/), create
11+
an application, and get a tracking Id.
12+
-[Find your tracking Id](https://support.google.com/analytics/answer/1008080?hl=en)
13+
and set it as an environment variable in[`appengine-web.xml`](src/main/webapp/WEB-INF/appengine-web.xml).
14+
15+
##Running locally
16+
This example uses the
17+
[Maven Cloud CLI based plugin](https://cloud.google.com/appengine/docs/java/tools/using-maven).
18+
To run this sample locally:
19+
20+
$ mvn appengine:run
21+
22+
##Deploying
23+
24+
$ mvn clean package appengine:deploy

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp