Skip to content

Commit 0bcbd79

Browse files
committed
Merge pull request #470 from GoogleCloudPlatform:jaxrs
PiperOrigin-RevId: 866034244 Change-Id: Ie776c0dd4161695dd60dc98c2adfb385f88404f3
2 parents 99cf256 + 3ac5923 commit 0bcbd79

File tree

12 files changed

+355
-3
lines changed

12 files changed

+355
-3
lines changed

applications/jaxrs/pom.xml

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2021 Google LLC
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+
https://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+
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
22+
<modelVersion>4.0.0</modelVersion>
23+
<packaging>war</packaging>
24+
<parent>
25+
<groupId>com.google.appengine</groupId>
26+
<artifactId>applications</artifactId>
27+
<version>4.0.1-SNAPSHOT</version>
28+
</parent>
29+
<groupId>com.google.appengine.demos</groupId>
30+
<artifactId>jaxrs</artifactId>
31+
<name>AppEngine :: jaxrs</name>
32+
<url>https://github.com/GoogleCloudPlatform/appengine-java-standard/</url>
33+
<description>A jaxrs sample application.</description>
34+
35+
<prerequisites>
36+
<maven>3.6.0</maven>
37+
</prerequisites>
38+
39+
<properties>
40+
<maven.deploy.skip>true</maven.deploy.skip>
41+
<appengine.target.version>4.0.1-SNAPSHOT</appengine.target.version>
42+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
43+
<maven.compiler.target>1.8</maven.compiler.target>
44+
<maven.compiler.source>1.8</maven.compiler.source>
45+
</properties>
46+
47+
<dependencies>
48+
<!-- Compile/runtime dependencies -->
49+
<dependency>
50+
<groupId>javax.servlet</groupId>
51+
<artifactId>javax.servlet-api</artifactId>
52+
<scope>provided</scope>
53+
</dependency>
54+
<dependency>
55+
<groupId>org.glassfish.jersey.containers</groupId>
56+
<artifactId>jersey-container-servlet</artifactId>
57+
<version>2.47</version>
58+
</dependency>
59+
60+
<dependency>
61+
<groupId>org.glassfish.jersey.inject</groupId>
62+
<artifactId>jersey-hk2</artifactId>
63+
<version>2.47</version>
64+
</dependency>
65+
66+
<dependency>
67+
<groupId>org.glassfish.jersey.connectors</groupId>
68+
<artifactId>jersey-jetty-connector</artifactId>
69+
<version>2.47</version>
70+
</dependency>
71+
</dependencies>
72+
73+
<build>
74+
<outputDirectory>target/${project.artifactId}-${project.version}/WEB-INF/classes</outputDirectory>
75+
76+
<plugins>
77+
<plugin>
78+
<groupId>org.eclipse.jetty.ee8</groupId>
79+
<artifactId>jetty-ee8-maven-plugin</artifactId>
80+
<version>12.1.5</version>
81+
<configuration>
82+
<scan>10</scan>
83+
<dumpOnStart>true</dumpOnStart>
84+
<webApp>
85+
<contextPath>/test</contextPath>
86+
</webApp>
87+
</configuration>
88+
</plugin>
89+
<plugin>
90+
<groupId>org.apache.maven.plugins</groupId>
91+
<artifactId>maven-surefire-plugin</artifactId>
92+
<version>3.5.4</version>
93+
<configuration>
94+
<argLine>
95+
--add-opens java.base/java.lang=ALL-UNNAMED
96+
--add-opens java.base/java.nio.charset=ALL-UNNAMED
97+
--add-opens java.base/java.util=ALL-UNNAMED
98+
--add-opens java.base/java.util.concurrent=ALL-UNNAMED
99+
</argLine>
100+
</configuration>
101+
</plugin>
102+
<plugin>
103+
<groupId>org.apache.maven.plugins</groupId>
104+
<artifactId>maven-war-plugin</artifactId>
105+
<version>3.5.1</version>
106+
<configuration>
107+
<archiveClasses>true</archiveClasses>
108+
<webResources>
109+
<!-- in order to interpolate version from pom into appengine-web.xml -->
110+
<resource>
111+
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
112+
<filtering>true</filtering>
113+
<targetPath>WEB-INF</targetPath>
114+
</resource>
115+
</webResources>
116+
</configuration>
117+
</plugin>
118+
119+
<plugin>
120+
<groupId>com.google.cloud.tools</groupId>
121+
<artifactId>appengine-maven-plugin</artifactId>
122+
<version>2.8.6</version>
123+
<configuration>
124+
<projectId>ludo-in-in</projectId>
125+
<version>jaxrs</version>
126+
<promote>false</promote>
127+
<automaticRestart>true</automaticRestart>
128+
<jvmFlags>
129+
<jvmFlag>-Xdebug</jvmFlag>
130+
<jvmFlag>-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n</jvmFlag>
131+
</jvmFlags>
132+
<cloudSdkVersion>553.0.0</cloudSdkVersion>
133+
</configuration>
134+
</plugin>
135+
</plugins>
136+
</build>
137+
138+
</project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2021 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+
* https://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+
package org.example;
17+
18+
import javax.ws.rs.ApplicationPath;
19+
import org.glassfish.jersey.server.ResourceConfig;
20+
21+
@ApplicationPath("/")
22+
public class AppConfig extends ResourceConfig {
23+
public AppConfig() {
24+
register(RootResource.class);
25+
}
26+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2021 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+
* https://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+
package org.example;
17+
18+
import javax.ws.rs.GET;
19+
import javax.ws.rs.Produces;
20+
import javax.ws.rs.core.MediaType;
21+
22+
public class HelloResource {
23+
@GET
24+
@Produces(MediaType.TEXT_PLAIN)
25+
public String hello() {
26+
return "hello";
27+
}
28+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2021 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+
* https://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+
package org.example;
17+
18+
import javax.ws.rs.Path;
19+
20+
@Path("/")
21+
public class RootResource {
22+
@Path("hello")
23+
public HelloResource getHelloResource() {
24+
return new HelloResource();
25+
}
26+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2021 Google LLC
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+
https://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+
18+
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
19+
<runtime>java17</runtime>
20+
<system-properties>
21+
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
22+
<property name="appengine.use.EE8" value="true"/>
23+
</system-properties>
24+
</appengine-web-app>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#
2+
# Copyright 2021 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+
# https://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+
# A default java.util.logging configuration.
17+
# (All App Engine logging is through java.util.logging by default).
18+
#
19+
# To use this configuration, copy it into your application's WEB-INF
20+
# folder and add the following to your appengine-web.xml:
21+
# <system-properties>
22+
# <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
23+
# </system-properties>
24+
#
25+
26+
# Set the default logging level for all loggers to WARNING
27+
.level = WARNING

applications/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@
3838
<module>guestbook_jakarta</module>
3939
<module>servletasyncapp</module>
4040
<module>servletasyncappjakarta</module>
41+
<module>jaxrs</module>
4142
</modules>
4243
</project>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2021 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+
* https://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+
package com.google.appengine.tools.development;
17+
18+
19+
import java.io.File;
20+
import java.io.IOException;
21+
import java.util.Arrays;
22+
import java.util.List;
23+
import org.junit.Before;
24+
import org.junit.Test;
25+
import org.junit.runner.RunWith;
26+
import org.junit.runners.Parameterized;
27+
28+
@RunWith(Parameterized.class)
29+
public class JaxRsTest extends DevAppServerTestBase {
30+
31+
@Parameterized.Parameters
32+
public static List<Object[]> version() {
33+
// Only EE8 app.
34+
return Arrays.asList(
35+
new Object[][] {
36+
{"java17", "9.4", "EE6"},
37+
{"java17", "12.0", "EE8"},
38+
{"java21", "12.0", "EE8"},
39+
{"java25", "12.1", "EE8"},
40+
41+
});
42+
43+
}
44+
public JaxRsTest(String runtimeVersion, String jettyVersion, String jakartaVersion) {
45+
super(runtimeVersion, jettyVersion, jakartaVersion);
46+
}
47+
48+
@Before
49+
public void setUpClass() throws IOException, InterruptedException {
50+
File currentDirectory = new File("").getAbsoluteFile();
51+
File appRoot =
52+
new File(
53+
currentDirectory,
54+
"../../applications/jaxrs/target/jaxrs"
55+
+ "-"
56+
+ System.getProperty("appengine.projectversion"));
57+
setUpClass(appRoot);
58+
}
59+
60+
@Test
61+
public void testJaxRs() throws Exception {
62+
// App Engine Memcache access.
63+
executeHttpGet(
64+
"/hello",
65+
"hello",
66+
RESPONSE_200);
67+
68+
}
69+
70+
}

runtime/local_jetty121/src/main/java/com/google/appengine/tools/development/jetty/AppEngineAnnotationConfiguration.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public class AppEngineAnnotationConfiguration extends AnnotationConfiguration {
3131
@Override
3232
public List<ServletContainerInitializer> getNonExcludedInitializers(WebAppContext context)
3333
throws Exception {
34+
// TODO: remove this line when https://github.com/jetty/jetty.project/issues/14431 is resolved.
35+
context.getMetaData().orderFragments();
36+
3437
ArrayList<ServletContainerInitializer> nonExcludedInitializers =
3538
new ArrayList<>(super.getNonExcludedInitializers(context));
3639
for (ServletContainerInitializer sci : nonExcludedInitializers) {

runtime/local_jetty121/src/main/java/com/google/appengine/tools/development/jetty/JettyContainerService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,11 @@ public void exitScope(ContextHandler.APIContext context, Request request) {
186186
// Set the location of deployment descriptor. This value might be null,
187187
// which is fine, it just means Jetty will look for it in the default
188188
// location (WEB-INF/web.xml).
189-
context.setDescriptor(webXmlLocation == null ? null : webXmlLocation.getAbsolutePath());
189+
// Only set the descriptor if the web.xml file actually exists.
190+
// Jetty 12 throws an IllegalArgumentException if the descriptor path is invalid.
191+
if (webXmlLocation != null && webXmlLocation.exists()) {
192+
context.setDescriptor(webXmlLocation.getAbsolutePath());
193+
}
190194

191195
// Override the web.xml that Jetty automatically prepends to other
192196
// web.xml files. This is where the DefaultServlet is registered,

0 commit comments

Comments
 (0)