-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Adding new Doc Samples for Java25 #10193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+2,979
−7
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a95fcc5
Adding new Doc Samples for Java25
maigovannon eda1ac6
Minor: Fixing tag for appengine-java25/helloworld/build.gradle
maigovannon 97a4342
Fixing PR comments
maigovannon b8e0569
Fixing Lint.
maigovannon e53571c
Fixing checkstyle for Lint.
maigovannon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Google Analytics sample for Google App Engine | ||
|
|
||
| <a href="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"> | ||
| <img alt="Open in Cloud Shell" src ="https://gstatic.com/cloudssh/images/open-btn.png"></a> | ||
|
|
||
| Integrating App Engine with Google Analytics using EE11. | ||
|
|
||
| ## Project setup, installation, and configuration | ||
|
|
||
| - Register for [Google Analytics](http://www.google.com/analytics/), create | ||
| an application, and get a tracking Id. | ||
| - [Find your tracking Id](https://support.google.com/analytics/answer/1008080?hl=en) | ||
| and set it as an environment variable in [`appengine-web.xml`](src/main/webapp/WEB-INF/appengine-web.xml). | ||
|
|
||
| ## Running locally | ||
| This example uses the | ||
| [Maven Cloud CLI based plugin](https://cloud.google.com/appengine/docs/java/tools/using-maven). | ||
| To run this sample locally: | ||
|
|
||
| $ mvn appengine:run | ||
|
|
||
| ## Deploying | ||
|
|
||
| $ mvn clean package appengine:deploy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| <!-- | ||
| Copyright 2017 Google LLC | ||
|
|
||
| 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 xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 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"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <packaging>war</packaging> | ||
| <version>1.0-SNAPSHOT</version> | ||
| <groupId>com.example.appengine</groupId> | ||
| <artifactId>appengine-analytics-j25-ee11</artifactId> | ||
|
|
||
| <!-- | ||
| The parent pom defines common style checks and testing strategies for our samples. | ||
| Removing or replacing it should not effect the execution of the samples in anyway. | ||
| --> | ||
| <parent> | ||
| <groupId>com.google.cloud.samples</groupId> | ||
| <artifactId>shared-configuration</artifactId> | ||
| <version>1.2.0</version> | ||
| </parent> | ||
|
|
||
| <properties> | ||
| <maven.compiler.target>25</maven.compiler.target> | ||
| <maven.compiler.source>25</maven.compiler.source> | ||
| <appengine.sdk.version>3.0.1</appengine.sdk.version> | ||
| </properties> | ||
|
|
||
| <dependencyManagement> | ||
| <dependencies> | ||
| <dependency> | ||
| <artifactId>libraries-bom</artifactId> | ||
| <groupId>com.google.cloud</groupId> | ||
| <scope>import</scope> | ||
| <type>pom</type> | ||
| <version>26.28.0</version> | ||
| </dependency> | ||
| </dependencies> | ||
| </dependencyManagement> | ||
|
|
||
| <dependencies> | ||
| <!-- Compile/runtime dependencies --> | ||
| <dependency> | ||
| <groupId>com.google.appengine</groupId> | ||
| <artifactId>appengine-api-1.0-sdk</artifactId> | ||
| <version>${appengine.sdk.version}</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>jstl</groupId> | ||
| <artifactId>jstl</artifactId> | ||
| <version>1.2</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.apache.httpcomponents</groupId> | ||
| <artifactId>httpclient</artifactId> | ||
| <version>4.5.14</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>jakarta.servlet</groupId> | ||
| <artifactId>jakarta.servlet-api</artifactId> | ||
| <version>6.0.0</version> | ||
| <type>jar</type> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
|
|
||
| <!-- Test Dependencies --> | ||
| <dependency> | ||
| <groupId>com.google.appengine</groupId> | ||
| <artifactId>appengine-testing</artifactId> | ||
| <version>${appengine.sdk.version}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.appengine</groupId> | ||
| <artifactId>appengine-api-stubs</artifactId> | ||
| <version>${appengine.sdk.version}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <version>4.13.2</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.mockito</groupId> | ||
| <artifactId>mockito-core</artifactId> | ||
| <version>4.11.0</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.truth</groupId> | ||
| <artifactId>truth</artifactId> | ||
| <version>1.1.5</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <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-compiler-plugin</artifactId> | ||
| <version>3.13.0</version> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-war-plugin</artifactId> | ||
| <version>3.4.0</version> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>com.google.cloud.tools</groupId> | ||
| <artifactId>appengine-maven-plugin</artifactId> | ||
| <version>2.7.0</version> | ||
| <configuration> | ||
| <projectId>GCLOUD_CONFIG</projectId> | ||
| <version>analytics</version> | ||
| <deploy.promote>true</deploy.promote> | ||
| <deploy.stopPreviousVersion>true</deploy.stopPreviousVersion> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> |
71 changes: 71 additions & 0 deletions
71
...java25/ee11/analytics/src/main/java/com/example/appengine/analytics/AnalyticsServlet.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* | ||
| * Copyright 2015 Google LLC | ||
| * | ||
| * 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.appengine.analytics; | ||
|
|
||
| // [START gae_java25_analytics_track] | ||
|
|
||
| import com.google.appengine.api.urlfetch.URLFetchService; | ||
| import com.google.appengine.api.urlfetch.URLFetchServiceFactory; | ||
| import jakarta.servlet.ServletException; | ||
| import jakarta.servlet.annotation.WebServlet; | ||
| import jakarta.servlet.http.HttpServlet; | ||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import jakarta.servlet.http.HttpServletResponse; | ||
| import java.io.IOException; | ||
| import java.net.URI; | ||
| import java.net.URISyntaxException; | ||
| import java.net.URL; | ||
| import org.apache.http.client.utils.URIBuilder; | ||
|
|
||
| @SuppressWarnings("serial") | ||
| // With @WebServlet annotation the webapp/WEB-INF/web.xml is no longer required. | ||
| @WebServlet( | ||
| name = "analytics", | ||
| description = "Analytics: Send Analytics Event to Google Analytics", | ||
| urlPatterns = "/analytics") | ||
| public class AnalyticsServlet extends HttpServlet { | ||
|
|
||
| @Override | ||
| public void doGet(HttpServletRequest req, HttpServletResponse resp) | ||
| throws IOException, ServletException { | ||
| String trackingId = System.getenv("GA_TRACKING_ID"); | ||
| URIBuilder builder = new URIBuilder(); | ||
| builder | ||
| .setScheme("http") | ||
| .setHost("www.google-analytics.com") | ||
| .setPath("/collect") | ||
| .addParameter("v", "1") // API Version. | ||
| .addParameter("tid", trackingId) // Tracking ID / Property ID. | ||
| // Anonymous Client Identifier. Ideally, this should be a UUID that | ||
| // is associated with particular user, device, or browser instance. | ||
| .addParameter("cid", "555") | ||
| .addParameter("t", "event") // Event hit type. | ||
| .addParameter("ec", "example") // Event category. | ||
| .addParameter("ea", "test action"); // Event action. | ||
| URI uri = null; | ||
| try { | ||
| uri = builder.build(); | ||
| } catch (URISyntaxException e) { | ||
| throw new ServletException("Problem building URI", e); | ||
| } | ||
| URLFetchService fetcher = URLFetchServiceFactory.getURLFetchService(); | ||
| URL url = uri.toURL(); | ||
| fetcher.fetch(url); | ||
| resp.getWriter().println("Event tracked."); | ||
| } | ||
| } | ||
| // [END gae_java25_analytics_track] | ||
26 changes: 26 additions & 0 deletions
26
appengine-java25/ee11/analytics/src/main/webapp/WEB-INF/appengine-web.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- [START_EXCLUDE] --> | ||
| <!-- | ||
| Copyright 2015 Google LLC | ||
| 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. | ||
| --> | ||
| <!-- [END_EXCLUDE] --> | ||
| <appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> | ||
| <runtime>java25</runtime> | ||
| <app-engine-apis>true</app-engine-apis> | ||
| <service>appengine-analytics-j25-ee11</service> | ||
| <system-properties> | ||
| <property name="appengine.use.EE11" value="true"/> | ||
| </system-properties> | ||
| <env-variables> | ||
| <env-var name="GA_TRACKING_ID" value="YOUR-GA-TRACKING-ID" /> | ||
| </env-variables> | ||
| </appengine-web-app> |
23 changes: 23 additions & 0 deletions
23
appengine-java25/ee11/analytics/src/main/webapp/WEB-INF/web.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- [START_EXCLUDE] --> | ||
| <!-- | ||
| Copyright 2015 Google LLC | ||
| 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. | ||
| --> | ||
| <!-- [END_EXCLUDE] --> | ||
| <web-app xmlns="https://jakarta.ee/xml/ns/jakartaee" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd" | ||
| version="6.0"> | ||
| <welcome-file-list> | ||
| <welcome-file>analytics</welcome-file> | ||
| </welcome-file-list> | ||
| </web-app> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||
| # Google Analytics sample for Google App Engine | ||||||
|
|
||||||
| <a href="https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/java-docs-samples&page=editor&open_in_editor=appengine-java21/analytics/README.md"> | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||
| <img alt="Open in Cloud Shell" src ="https://gstatic.com/cloudssh/images/open-btn.png"></a> | ||||||
|
|
||||||
| Integrating App Engine with Google Analytics using EE8. | ||||||
|
|
||||||
| ## Project setup, installation, and configuration | ||||||
|
|
||||||
| - Register for [Google Analytics](http://www.google.com/analytics/), create | ||||||
| an application, and get a tracking Id. | ||||||
| - [Find your tracking Id](https://support.google.com/analytics/answer/1008080?hl=en) | ||||||
| and set it as an environment variable in [`appengine-web.xml`](src/main/webapp/WEB-INF/appengine-web.xml). | ||||||
|
|
||||||
| ## Running locally | ||||||
| This example uses the | ||||||
| [Maven Cloud CLI based plugin](https://cloud.google.com/appengine/docs/java/tools/using-maven). | ||||||
| To run this sample locally: | ||||||
|
|
||||||
| $ mvn appengine:run | ||||||
|
|
||||||
| ## Deploying | ||||||
|
|
||||||
| $ mvn clean package appengine:deploy | ||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.