-
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.
Merge pull request #324 from GoogleCloudPlatform:error-page-test
PiperOrigin-RevId: 707557613 Change-Id: I9e7f4ec95af64183890458da5fb2000bbf2295d1
- Loading branch information
Showing
21 changed files
with
610 additions
and
0 deletions.
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
runtime/test/src/test/java/com/google/apphosting/runtime/jetty9/SendErrorTest.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,111 @@ | ||
/* | ||
* 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 org.hamcrest.CoreMatchers.containsString; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import org.eclipse.jetty.client.api.ContentResponse; | ||
import org.eclipse.jetty.http.HttpStatus; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.eclipse.jetty.client.HttpClient; | ||
|
||
|
||
@RunWith(Parameterized.class) | ||
public class SendErrorTest extends JavaRuntimeViaHttpBase { | ||
|
||
@Parameterized.Parameters | ||
public static Collection<Object[]> parameters() { | ||
return Arrays.asList( | ||
new Object[][] { | ||
{"jetty94", false}, | ||
{"jetty94", true}, | ||
{"ee8", false}, | ||
{"ee8", true}, | ||
{"ee10", false}, | ||
{"ee10", true}, | ||
}); | ||
} | ||
|
||
@Rule public TemporaryFolder temp = new TemporaryFolder(); | ||
private final HttpClient httpClient = new HttpClient(); | ||
private final boolean httpMode; | ||
private final String environment; | ||
private RuntimeContext<?> runtime; | ||
|
||
|
||
public SendErrorTest(String environment, boolean httpMode) { | ||
this.environment = environment; | ||
this.httpMode = httpMode; | ||
System.setProperty("appengine.use.HttpConnector", Boolean.toString(httpMode)); | ||
} | ||
|
||
@Before | ||
public void start() throws Exception { | ||
String app = "com/google/apphosting/runtime/jetty9/senderrorapp/" + environment; | ||
copyAppToDir(app, temp.getRoot().toPath()); | ||
httpClient.start(); | ||
runtime = runtimeContext(); | ||
System.err.println("==== Using Environment: " + environment + " " + httpMode + " ===="); | ||
} | ||
|
||
@After | ||
public void after() throws Exception { | ||
httpClient.stop(); | ||
runtime.close(); | ||
} | ||
|
||
@Test | ||
public void testSendError() throws Exception { | ||
String url = runtime.jettyUrl("/send-error"); | ||
ContentResponse response = httpClient.GET(url); | ||
assertEquals(HttpStatus.OK_200, response.getStatus()); | ||
assertThat(response.getContentAsString(), containsString("<h1>Hello, welcome to App Engine Java Standard!</h1>")); | ||
|
||
url = runtime.jettyUrl("/send-error?errorCode=404"); | ||
response = httpClient.GET(url); | ||
assertEquals(HttpStatus.NOT_FOUND_404, response.getStatus()); | ||
assertThat(response.getContentAsString(), containsString("<h1>404 - Page Not Found (App Engine Java Standard)</h1>")); | ||
|
||
url = runtime.jettyUrl("/send-error?errorCode=500"); | ||
response = httpClient.GET(url); | ||
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, response.getStatus()); | ||
assertThat(response.getContentAsString(), containsString("<h1>500 - Internal Server Error (App Engine Java Standard)</h1>")); | ||
|
||
url = runtime.jettyUrl("/send-error?errorCode=503"); | ||
response = httpClient.GET(url); | ||
assertEquals(HttpStatus.SERVICE_UNAVAILABLE_503, response.getStatus()); | ||
assertThat(response.getContentAsString(), containsString("<h1>Unhandled Error - Service Temporarily Unavailable (App Engine Java Standard)</h1>")); | ||
|
||
} | ||
|
||
private RuntimeContext<?> runtimeContext() throws Exception { | ||
RuntimeContext.Config<?> config = | ||
RuntimeContext.Config.builder().setApplicationPath(temp.getRoot().toString()).build(); | ||
return RuntimeContext.create(config); | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
...src/main/java/com/google/apphosting/runtime/jetty9/senderrorapp/SendErrorServletEE10.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,50 @@ | ||
/* | ||
* 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.senderrorapp; | ||
|
||
import java.io.IOException; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServlet; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
|
||
public class SendErrorServletEE10 extends HttpServlet { | ||
@Override | ||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
int errorCode; | ||
if (req.getParameter( | ||
"errorCode") == null) { | ||
errorCode = 0; | ||
} else { | ||
try { | ||
errorCode = Integer.parseInt(req.getParameter("errorCode")); | ||
} catch (NumberFormatException e) { | ||
errorCode = -1; | ||
} | ||
} | ||
switch (errorCode) { | ||
case -1: | ||
throw new RuntimeException("try to handle me"); | ||
case 0: | ||
req.getRequestDispatcher("/hello.html").forward(req, resp); | ||
break; | ||
default: | ||
resp.sendError(errorCode); | ||
break; | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
.../src/main/java/com/google/apphosting/runtime/jetty9/senderrorapp/SendErrorServletEE8.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,49 @@ | ||
/* | ||
* 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.senderrorapp; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
public class SendErrorServletEE8 extends HttpServlet { | ||
@Override | ||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
int errorCode; | ||
if (req.getParameter("errorCode") == null) { | ||
errorCode = 0; | ||
} else { | ||
try { | ||
errorCode = Integer.parseInt(req.getParameter("errorCode")); | ||
} catch (NumberFormatException e) { | ||
errorCode = -1; | ||
} | ||
} | ||
switch (errorCode) { | ||
case -1: | ||
throw new RuntimeException("try to handle me"); | ||
case 0: | ||
req.getRequestDispatcher("/hello.html").forward(req, resp); | ||
break; | ||
default: | ||
resp.sendError(errorCode); | ||
break; | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...stapps/src/main/resources/com/google/apphosting/runtime/jetty9/senderrorapp/ee10/404.html
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,16 @@ | ||
<!-- | ||
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. | ||
--> | ||
<h1>404 - Page Not Found (App Engine Java Standard)</h1> |
16 changes: 16 additions & 0 deletions
16
...stapps/src/main/resources/com/google/apphosting/runtime/jetty9/senderrorapp/ee10/500.html
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,16 @@ | ||
<!-- | ||
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. | ||
--> | ||
<h1>500 - Internal Server Error (App Engine Java Standard)</h1> |
25 changes: 25 additions & 0 deletions
25
...esources/com/google/apphosting/runtime/jetty9/senderrorapp/ee10/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,25 @@ | ||
<?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"> | ||
<runtime>java21</runtime> | ||
<application>senderror</application> | ||
<version>1</version> | ||
<system-properties> | ||
<property name="appengine.use.EE10" value="true"/> | ||
</system-properties> | ||
</appengine-web-app> |
44 changes: 44 additions & 0 deletions
44
...src/main/resources/com/google/apphosting/runtime/jetty9/senderrorapp/ee10/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,44 @@ | ||
<?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://xmlns.jcp.org/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_4_0.xsd" | ||
version="4.0"> | ||
<servlet> | ||
<servlet-name>Main</servlet-name> | ||
<servlet-class>com.google.apphosting.runtime.jetty9.senderrorapp.SendErrorServletEE10</servlet-class> | ||
</servlet> | ||
<servlet-mapping> | ||
<servlet-name>Main</servlet-name> | ||
<url-pattern>/send-error</url-pattern> | ||
</servlet-mapping> | ||
|
||
<error-page> | ||
<error-code>404</error-code> | ||
<location>/404.html</location> | ||
</error-page> | ||
<error-page> | ||
<error-code>500</error-code> | ||
<location>/500.html</location> | ||
</error-page> | ||
<error-page> | ||
<!-- No error-code or exception-type, i.e. this will match any other HTTP status than defined above --> | ||
<location>/unhandled-error.html</location> | ||
</error-page> | ||
</web-app> |
16 changes: 16 additions & 0 deletions
16
...apps/src/main/resources/com/google/apphosting/runtime/jetty9/senderrorapp/ee10/hello.html
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,16 @@ | ||
<!-- | ||
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. | ||
--> | ||
<h1>Hello, welcome to App Engine Java Standard!</h1> |
16 changes: 16 additions & 0 deletions
16
...ain/resources/com/google/apphosting/runtime/jetty9/senderrorapp/ee10/unhandled-error.html
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,16 @@ | ||
<!-- | ||
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. | ||
--> | ||
<h1>Unhandled Error - Service Temporarily Unavailable (App Engine Java Standard)</h1> |
16 changes: 16 additions & 0 deletions
16
...estapps/src/main/resources/com/google/apphosting/runtime/jetty9/senderrorapp/ee8/404.html
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,16 @@ | ||
<!-- | ||
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. | ||
--> | ||
<h1>404 - Page Not Found (App Engine Java Standard)</h1> |
16 changes: 16 additions & 0 deletions
16
...estapps/src/main/resources/com/google/apphosting/runtime/jetty9/senderrorapp/ee8/500.html
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,16 @@ | ||
<!-- | ||
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. | ||
--> | ||
<h1>500 - Internal Server Error (App Engine Java Standard)</h1> |
Oops, something went wrong.