Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix servlet error mapping #40359

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.jboss.metadata.web.spec.CookieConfigMetaData;
import org.jboss.metadata.web.spec.DispatcherType;
import org.jboss.metadata.web.spec.EmptyRoleSemanticType;
import org.jboss.metadata.web.spec.ErrorPageMetaData;
import org.jboss.metadata.web.spec.FilterMappingMetaData;
import org.jboss.metadata.web.spec.FilterMetaData;
import org.jboss.metadata.web.spec.FiltersMetaData;
Expand Down Expand Up @@ -651,6 +652,16 @@ public ServletDeploymentManagerBuildItem build(List<ServletBuildItem> servlets,
recorder.addServletContainerInitializer(deployment,
(Class<? extends ServletContainerInitializer>) context.classProxy(sci.sciClass), handlesTypes);
}
if (webMetaData.getErrorPages() != null) {
for (ErrorPageMetaData errorPage : webMetaData.getErrorPages()) {
if (errorPage.getErrorCode() != null && !errorPage.getErrorCode().isBlank()) {
recorder.addErrorPage(deployment, errorPage.getLocation(), Integer.parseInt(errorPage.getErrorCode()));
} else if (errorPage.getExceptionType() != null && !errorPage.getExceptionType().isBlank()) {
recorder.addErrorPage(deployment, errorPage.getLocation(),
(Class<? extends Throwable>) context.classProxy(errorPage.getExceptionType()));
}
}
}
SessionConfigMetaData sessionConfig = webMetaData.getSessionConfig();
if (sessionConfig != null) {
if (sessionConfig.getSessionTimeoutSet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ public class ServletWebXmlTestCase {
" <mime-mapping>\n" +
" <extension>wasm</extension>\n" +
" <mime-type>application/wasm</mime-type>\n" +
" </mime-mapping>" +
" </mime-mapping>\n" +
" <error-page>\n" +
" <error-code>404</error-code>\n" +
" <location>/mapped</location>\n" +
" </error-page>\n" +
"</web-app>";

@RegisterExtension
Expand All @@ -56,4 +60,11 @@ public void testMimeMapping() {
.statusCode(200)
.contentType(is("application/wasm"));
}

@Test
public void test404Mapping() {
RestAssured.when().get("/missing").then()
.statusCode(404)
.body(is("web xml servlet"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,16 @@ public void setSessionCookieConfig(ServletSessionConfig config, String name, Str
}
}

public void addErrorPage(RuntimeValue<DeploymentInfo> deployment, String location, int errorCode) {
deployment.getValue().addErrorPage(new ErrorPage(location, errorCode));

}

public void addErrorPage(RuntimeValue<DeploymentInfo> deployment, String location,
Class<? extends Throwable> exceptionType) {
deployment.getValue().addErrorPage(new ErrorPage(location, exceptionType));
}

/**
* we can't have SecureRandom in the native image heap, so we need to lazy init
*/
Expand Down
Loading