Skip to content

Commit 421d1cc

Browse files
ludochgae-java-bot
authored andcommitted
Move servlet filter init failure test to open source.
PiperOrigin-RevId: 447853756 Change-Id: I9d6ba66c23c72c53c68b5d22a1f8147ecb1d35d2
1 parent 3cc3566 commit 421d1cc

8 files changed

Lines changed: 255 additions & 3 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
<project xmlns="http://maven.apache.org/POM/4.0.0"
18+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
21+
<modelVersion>4.0.0</modelVersion>
22+
<packaging>war</packaging>
23+
<version>1.0</version>
24+
25+
<groupId>com.google.appengine.demos</groupId>
26+
<artifactId>failinitfilterwebapp</artifactId>
27+
<name>AppEngine :: failinitfilterwebapp</name>
28+
29+
<properties>
30+
<appengine.app.version>1</appengine.app.version>
31+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
32+
</properties>
33+
34+
<dependencies>
35+
<dependency>
36+
<groupId>javax.servlet</groupId>
37+
<artifactId>servlet-api</artifactId>
38+
<version>2.5</version>
39+
<scope>provided</scope>
40+
</dependency>
41+
</dependencies>
42+
<build>
43+
<outputDirectory>target/${project.artifactId}-${project.version}/WEB-INF/classes</outputDirectory>
44+
<plugins>
45+
<plugin>
46+
<groupId>org.apache.maven.plugins</groupId>
47+
<artifactId>maven-war-plugin</artifactId>
48+
<version>3.3.2</version>
49+
<configuration>
50+
<archiveClasses>true</archiveClasses>
51+
<webResources>
52+
<!-- in order to interpolate version from pom into appengine-web.xml -->
53+
<resource>
54+
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
55+
<filtering>true</filtering>
56+
<targetPath>WEB-INF</targetPath>
57+
</resource>
58+
</webResources>
59+
</configuration>
60+
</plugin>
61+
<plugin>
62+
<artifactId>maven-compiler-plugin</artifactId>
63+
<version>3.10.1</version>
64+
<configuration>
65+
<source>1.8</source>
66+
<target>1.8</target>
67+
</configuration>
68+
</plugin>
69+
<plugin>
70+
<groupId>com.google.cloud.tools</groupId>
71+
<artifactId>appengine-maven-plugin</artifactId>
72+
<version>2.4.1</version>
73+
<configuration>
74+
<projectId>ludo-in-in</projectId>
75+
<version>failinitfilter</version>
76+
<promote>false</promote>
77+
<automaticRestart>true</automaticRestart>
78+
</configuration>
79+
</plugin>
80+
</plugins>
81+
</build>
82+
83+
</project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
17+
import javax.servlet.Filter;
18+
import javax.servlet.FilterChain;
19+
import javax.servlet.FilterConfig;
20+
import javax.servlet.ServletException;
21+
import javax.servlet.ServletRequest;
22+
import javax.servlet.ServletResponse;
23+
24+
public class FailInitializationFilter implements Filter {
25+
@Override
26+
public void init(FilterConfig config) throws ServletException {
27+
throw new ServletException("Intentionally failing to initialize.");
28+
}
29+
30+
@Override
31+
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
32+
throws ServletException {
33+
throw new ServletException("Unexpectedly got a request.");
34+
}
35+
36+
@Override
37+
public void destroy() {}
38+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
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+
runtime: java8
16+
inbound_services:
17+
- warmup
18+
threadsafe: True
19+
auto_id_policy: default
20+
api_version: 'user_defined'
21+
handlers:
22+
- url: /.*
23+
script: unused
24+
login: optional
25+
secure: optional
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
18+
<threadsafe>true</threadsafe>
19+
<runtime>java8</runtime>
20+
</appengine-web-app>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
<web-app
18+
xmlns="http://java.sun.com/xml/ns/javaee"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
21+
version="2.5">
22+
<filter>
23+
<filter-name>FailInitializationFilter</filter-name>
24+
<filter-class>FailInitializationFilter</filter-class>
25+
</filter>
26+
<filter-mapping>
27+
<filter-name>FailInitializationFilter</filter-name>
28+
<url-pattern>/*</url-pattern>
29+
</filter-mapping>
30+
</web-app>

runtime/nogaeapiswebapp/src/main/webapp/WEB-INF/web.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
-->
17-
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_2_5.xsd">
18-
19-
<servlet>
17+
<web-app
18+
xmlns="http://java.sun.com/xml/ns/javaee"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
21+
version="2.5">
22+
<servlet>
2023
<servlet-name>NoGaeApisServlet</servlet-name>
2124
<servlet-class>NoGaeApisServlet</servlet-class>
2225
</servlet>

runtime/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<module>deployment</module>
3636
<module>local</module>
3737
<module>nogaeapiswebapp</module>
38+
<module>failinitfilterwebapp</module>
3839
<module>test</module>
3940
<module>testapps</module>
4041
</modules>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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.apphosting.runtime.jetty9;
17+
18+
import static com.google.common.truth.Truth.assertThat;
19+
20+
import java.io.File;
21+
import java.io.IOException;
22+
import org.junit.BeforeClass;
23+
import org.junit.Test;
24+
import org.junit.runner.RunWith;
25+
import org.junit.runners.JUnit4;
26+
27+
@RunWith(JUnit4.class)
28+
public final class FailureFilterTest extends JavaRuntimeViaHttpBase {
29+
30+
private static File appRoot;
31+
32+
@BeforeClass
33+
public static void beforeClass() throws IOException, InterruptedException {
34+
File currentDirectory = new File("").getAbsoluteFile();
35+
appRoot = new File(currentDirectory, "../failinitfilterwebapp/target/failinitfilterwebapp-1.0");
36+
assertThat(appRoot.isDirectory()).isTrue();
37+
}
38+
39+
private RuntimeContext<DummyApiServer> runtimeContext() throws IOException, InterruptedException {
40+
RuntimeContext.Config<DummyApiServer> config =
41+
RuntimeContext.Config.builder().setApplicationPath(appRoot.toString()).build();
42+
return RuntimeContext.create(config);
43+
}
44+
45+
@Test
46+
public void testFilterInitFailed() throws Exception {
47+
try (RuntimeContext<DummyApiServer> runtime = runtimeContext()) {
48+
assertThat(runtime.executeHttpGet("/", 500))
49+
.contains("javax.servlet.ServletException: Intentionally failing to initialize.");
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)