Your code and your expectations are perfect. It is just a Wicket bug or Tomcat wrong understanding of 404 Exception. I guess it is just in Wicket prior to 1.4.x version.
The fix is to override the code in AbstractRequestCycleProcessor, you can override it just in the factory method of your WebApplication class:
@Override
protected IRequestCycleProcessor newRequestCycleProcessor() {
return new WebRequestCycleProcessor() {
@Override
protected IRequestTarget resolveBookmarkablePage(final RequestCycle requestCycle,
final RequestParameters requestParameters) {
IRequestTarget target = super.resolveBookmarkablePage(requestCycle, requestParameters);
if(target == null) {
return target;
}
if(target instanceof WebErrorCodeResponseTarget) {
WebErrorCodeResponseTarget errorResponse = (WebErrorCodeResponseTarget) target;
if(HttpServletResponse.SC_NOT_FOUND == errorResponse.getErrorCode()) {
return null;
}
}
return target;
}
};
}
I place the full working example into my Wicket14 testing repository https://repo.twinstone.org/projects/WISTF/repos/wicket-examples-1.4/browse