-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move servlet filter init failure test to open source.
PiperOrigin-RevId: 447853756 Change-Id: I9d6ba66c23c72c53c68b5d22a1f8147ecb1d35d2
- Loading branch information
1 parent
3cc3566
commit 421d1cc
Showing
8 changed files
with
255 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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,83 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright 2021 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 | ||
https://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</version> | ||
|
||
<groupId>com.google.appengine.demos</groupId> | ||
<artifactId>failinitfilterwebapp</artifactId> | ||
<name>AppEngine :: failinitfilterwebapp</name> | ||
|
||
<properties> | ||
<appengine.app.version>1</appengine.app.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>servlet-api</artifactId> | ||
<version>2.5</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<outputDirectory>target/${project.artifactId}-${project.version}/WEB-INF/classes</outputDirectory> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<version>3.3.2</version> | ||
<configuration> | ||
<archiveClasses>true</archiveClasses> | ||
<webResources> | ||
<!-- in order to interpolate version from pom into appengine-web.xml --> | ||
<resource> | ||
<directory>${basedir}/src/main/webapp/WEB-INF</directory> | ||
<filtering>true</filtering> | ||
<targetPath>WEB-INF</targetPath> | ||
</resource> | ||
</webResources> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.10.1</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.google.cloud.tools</groupId> | ||
<artifactId>appengine-maven-plugin</artifactId> | ||
<version>2.4.1</version> | ||
<configuration> | ||
<projectId>ludo-in-in</projectId> | ||
<version>failinitfilter</version> | ||
<promote>false</promote> | ||
<automaticRestart>true</automaticRestart> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
38 changes: 38 additions & 0 deletions
38
runtime/failinitfilterwebapp/src/main/java/FailInitializationFilter.java
This file contains 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,38 @@ | ||
/* | ||
* Copyright 2021 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 | ||
* | ||
* https://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. | ||
*/ | ||
|
||
import javax.servlet.Filter; | ||
import javax.servlet.FilterChain; | ||
import javax.servlet.FilterConfig; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
|
||
public class FailInitializationFilter implements Filter { | ||
@Override | ||
public void init(FilterConfig config) throws ServletException { | ||
throw new ServletException("Intentionally failing to initialize."); | ||
} | ||
|
||
@Override | ||
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) | ||
throws ServletException { | ||
throw new ServletException("Unexpectedly got a request."); | ||
} | ||
|
||
@Override | ||
public void destroy() {} | ||
} |
25 changes: 25 additions & 0 deletions
25
runtime/failinitfilterwebapp/src/main/webapp/WEB-INF/appengine-generated/app.yaml
This file contains 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,25 @@ | ||
# Copyright 2021 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 | ||
# | ||
# https://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. | ||
# | ||
runtime: java8 | ||
inbound_services: | ||
- warmup | ||
threadsafe: True | ||
auto_id_policy: default | ||
api_version: 'user_defined' | ||
handlers: | ||
- url: /.* | ||
script: unused | ||
login: optional | ||
secure: optional |
20 changes: 20 additions & 0 deletions
20
runtime/failinitfilterwebapp/src/main/webapp/WEB-INF/appengine-web.xml
This file contains 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,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright 2021 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 | ||
https://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. | ||
--> | ||
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> | ||
<threadsafe>true</threadsafe> | ||
<runtime>java8</runtime> | ||
</appengine-web-app> |
30 changes: 30 additions & 0 deletions
30
runtime/failinitfilterwebapp/src/main/webapp/WEB-INF/web.xml
This file contains 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,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2021 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 | ||
https://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. | ||
--> | ||
<web-app | ||
xmlns="http://java.sun.com/xml/ns/javaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | ||
version="2.5"> | ||
<filter> | ||
<filter-name>FailInitializationFilter</filter-name> | ||
<filter-class>FailInitializationFilter</filter-class> | ||
</filter> | ||
<filter-mapping> | ||
<filter-name>FailInitializationFilter</filter-name> | ||
<url-pattern>/*</url-pattern> | ||
</filter-mapping> | ||
</web-app> |
This file contains 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 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
52 changes: 52 additions & 0 deletions
52
runtime/test/src/test/java/com/google/apphosting/runtime/jetty9/FailureFilterTest.java
This file contains 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,52 @@ | ||
/* | ||
* Copyright 2021 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 | ||
* | ||
* https://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.google.apphosting.runtime.jetty9; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
@RunWith(JUnit4.class) | ||
public final class FailureFilterTest extends JavaRuntimeViaHttpBase { | ||
|
||
private static File appRoot; | ||
|
||
@BeforeClass | ||
public static void beforeClass() throws IOException, InterruptedException { | ||
File currentDirectory = new File("").getAbsoluteFile(); | ||
appRoot = new File(currentDirectory, "../failinitfilterwebapp/target/failinitfilterwebapp-1.0"); | ||
assertThat(appRoot.isDirectory()).isTrue(); | ||
} | ||
|
||
private RuntimeContext<DummyApiServer> runtimeContext() throws IOException, InterruptedException { | ||
RuntimeContext.Config<DummyApiServer> config = | ||
RuntimeContext.Config.builder().setApplicationPath(appRoot.toString()).build(); | ||
return RuntimeContext.create(config); | ||
} | ||
|
||
@Test | ||
public void testFilterInitFailed() throws Exception { | ||
try (RuntimeContext<DummyApiServer> runtime = runtimeContext()) { | ||
assertThat(runtime.executeHttpGet("/", 500)) | ||
.contains("javax.servlet.ServletException: Intentionally failing to initialize."); | ||
} | ||
} | ||
} |