Tomcat error page using bookmarked pages in Wicket

I have such a problem.

I need to show a customized error page when you get a 404 HTTP error. I am using Wicket 1.4 and Tomcat6. I implemented these things in web.xml for example

 <filter-name>wicket.filter</filter-name>
    <url-pattern>/*</url-pattern>         
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>ERROR</dispatcher>
 </filter-mapping>

<error-page>
    <error-code>404</error-code>
    <location>/404</location>
</error-page>

and fits into this code in my WebApplication application:

mount(new HybridUrlCodingStrategy("/404", PageNotFound.class));

PageNotFound class isErrorPage set true, isVersioned false and

    @Override
    protected void configureResponse() {
       super.configureResponse();   
       getWebRequestCycle().getWebResponse().getHttpServletResponse().setStatus(HttpServletResponse.SC_NOT_FOUND);
    }

Now the problem is that when I enter some kind of invalid URL, for example http://localhost:8080/myApp-war/invalidUrl, I can see my PageNotFound. But when I enter something like http://localhost:8080/myApp-war/?wicket:bookmarkablePage=:com.mypackage.invalidUrl, I just get a blank, clear page without any data.

, tomcat "HTTP Status 404 -/myApp-war/invalidUrl" : "HTTP Status 404 - "

? , <error-page> ? , .

+4
1

. Wicket Tomcat, 404. , Wicket 1.4.x.

, AbstractRequestCycleProcessor, factory WebApplication:

@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;
    }

};

}

Wicket14 https://repo.twinstone.org/projects/WISTF/repos/wicket-examples-1.4/browse

+1

Source: https://habr.com/ru/post/1523335/


All Articles