Skip to content

Commit 820ce92

Browse files
committed
JaxRS sample application code without web.xml and for EE8.
1 parent 405322b commit 820ce92

4 files changed

Lines changed: 83 additions & 3 deletions

File tree

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\n",
66+
RESPONSE_200);
67+
68+
}
69+
70+
}

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

Lines changed: 7 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,
@@ -353,6 +357,8 @@ protected void connectContainer() throws Exception {
353357
} else {
354358
server = new Server();
355359
}
360+
server.setDumpAfterStart(true);
361+
356362
try {
357363
NetworkTrafficServerConnector connector =
358364
new NetworkTrafficServerConnector(

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,11 @@ public void exitScope(
192192
// Set the location of deployment descriptor. This value might be null,
193193
// which is fine, it just means Jetty will look for it in the default
194194
// location (WEB-INF/web.xml).
195-
context.setDescriptor(webXmlLocation == null ? null : webXmlLocation.getAbsolutePath());
196-
195+
// Jetty 12 throws an IllegalArgumentException if the descriptor path is invalid.
196+
if (webXmlLocation != null && webXmlLocation.exists()) {
197+
context.setDescriptor(webXmlLocation.getAbsolutePath());
198+
}
199+
197200
// Override the web.xml that Jetty automatically prepends to other
198201
// web.xml files. This is where the DefaultServlet is registered,
199202
// which serves static files. We override it to disable some

0 commit comments

Comments
 (0)