use of org.apache.wicket.request.http.handler.ErrorCodeRequestHandler in project wicket by apache.
the class DefaultExceptionMapperResourceBlockedDevModeTest method packageResourceBlockedExceptionDevMode.
/**
* In development mode return http status 500 when a resource is blocked
* so the developer can see the problem early (the exception will be displayed
* on the screen)
*/
@Test
public void packageResourceBlockedExceptionDevMode() {
DefaultExceptionMapper mapper = new DefaultExceptionMapper();
PackageResource.PackageResourceBlockedException x = new PackageResource.PackageResourceBlockedException("test");
IRequestHandler handler = mapper.map(x);
assertThat(handler, instanceOf(ErrorCodeRequestHandler.class));
ErrorCodeRequestHandler errorCodeRequestHandler = (ErrorCodeRequestHandler) handler;
assertThat(errorCodeRequestHandler.getErrorCode(), is(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
}
use of org.apache.wicket.request.http.handler.ErrorCodeRequestHandler in project wicket by apache.
the class DefaultUnauthorizedResourceRequestListener method onUnauthorizedRequest.
@Override
public void onUnauthorizedRequest(IResource resource, PageParameters parameters) {
RequestCycle cycle = RequestCycle.get();
if (cycle != null) {
IRequestHandler handler = new ErrorCodeRequestHandler(HttpServletResponse.SC_FORBIDDEN, createErrorMessage(resource, parameters));
cycle.replaceAllRequestHandlers(handler);
}
}
use of org.apache.wicket.request.http.handler.ErrorCodeRequestHandler in project wicket by apache.
the class DefaultExceptionMapper method internalMap.
/**
* Maps exceptions to their corresponding {@link IRequestHandler}.
*
* @param e
* the current exception
* @return the {@link IRequestHandler} for the current exception
*/
private IRequestHandler internalMap(Exception e) {
final Application application = Application.get();
// check if we are processing an Ajax request and if we want to invoke the failure handler
if (isProcessingAjaxRequest()) {
switch(application.getExceptionSettings().getAjaxErrorHandlingStrategy()) {
case INVOKE_FAILURE_HANDLER:
return new ErrorCodeRequestHandler(500);
}
}
IRequestHandler handleExpectedExceptions = mapExpectedExceptions(e, application);
if (handleExpectedExceptions != null) {
return handleExpectedExceptions;
}
return mapUnexpectedExceptions(e, application);
}
use of org.apache.wicket.request.http.handler.ErrorCodeRequestHandler in project wicket by apache.
the class DefaultExceptionMapperResourceBlockedProdModeTest method packageResourceBlockedException.
/**
* In production mode return http status 404 when a resource is blocked
*/
@Test
public void packageResourceBlockedException() {
DefaultExceptionMapper mapper = new DefaultExceptionMapper();
PackageResource.PackageResourceBlockedException x = new PackageResource.PackageResourceBlockedException("test");
IRequestHandler handler = mapper.map(x);
assertThat(handler, instanceOf(ErrorCodeRequestHandler.class));
ErrorCodeRequestHandler errorCodeRequestHandler = (ErrorCodeRequestHandler) handler;
assertThat(errorCodeRequestHandler.getErrorCode(), is(HttpServletResponse.SC_NOT_FOUND));
}
use of org.apache.wicket.request.http.handler.ErrorCodeRequestHandler in project wicket by apache.
the class SourcesPage method getPageTargetClass.
private Class<? extends Page> getPageTargetClass() {
if (page == null) {
String pageParam = getPageParameters().get(PAGE_CLASS).toOptionalString();
if (pageParam == null) {
log.error("key: {} is null.", PAGE_CLASS);
getRequestCycle().replaceAllRequestHandlers(new ErrorCodeRequestHandler(404, "Could not find sources for the page you requested"));
} else if (!pageParam.startsWith("org.apache.wicket.examples")) {
log.error("user is trying to access class: {} which is not in the scope of org.apache.wicket.examples", pageParam);
throw new UnauthorizedInstantiationException(getClass());
}
page = WicketObjects.resolveClass(pageParam);
if (page == null) {
getRequestCycle().replaceAllRequestHandlers(new ErrorCodeRequestHandler(404, "Could not find sources for the page you requested"));
}
}
return page;
}
Aggregations