user9010316
user9010316

Reputation:

Wicket error pages not working

Problems with error pages in the Wicket. We use the Wiket(8.0.0-M8) and spring security(4.2.3.RELEASE).

I have an idea about how to set up my error pages, but standard pages also do not work (I get error pages tomcat, instead of mine).

    getApplicationSettings().setInternalErrorPage(InternalErrorPage.class);
    getApplicationSettings().setAccessDeniedPage(AccessDeniedPage.class);

The peculiarity is that the page 500 (Internal Error) can be specified. But the rest do not.

Spring Security does not have a page 403 (access denied page), and if you specify in spring and mountPage in the Wicket, it will send to 404. How to declare 404 is also not entirely clear.

UPD: web.xml:

<display-name>project</display-name>

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<filter>
    <filter-name>transactionFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    <init-param>
        <param-name>targetBeanName</param-name>
        <param-value>transactionFilter</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>transactionFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
    <filter-name>wicket.project</filter-name>
    <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
    <init-param>
        <param-name>applicationFactoryClassName</param-name>
        <param-value>org.apache.wicket.spring.SpringWebApplicationFactory</param-value>
    </init-param>
    <init-param>
        <param-name>applicationClassName</param-name>
        <param-value>ru.company.project.web.WicketApplication</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>wicket.project</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

Upvotes: 0

Views: 1071

Answers (1)

martin-g
martin-g

Reputation: 17533

Here is how to do it with Spring Boot:

import org.springframework.boot.web.servlet.ErrorPage;
import org.springframework.boot.web.servlet.ErrorPageRegistrar;
import org.springframework.boot.web.servlet.ErrorPageRegistry;
import org.springframework.http.HttpStatus;

public class MyErrorPageRegistrar implements ErrorPageRegistrar {
    @Override
    public void registerErrorPages(final ErrorPageRegistry registry) {
         registry.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND,
              MyApplication.PAGE_NOT_FOUND_MOUNT_PATH));
    }
}

In MySpringConfiguration.java:

@Bean
public ErrorPageRegistrar errorPageRegistrar(){
    return new MyErrorPageRegistrar();
}

In MyApplication.java:

String PAGE_NOT_FOUND_MOUNT_PATH = "/not/found";   
...
@Override public void init() {
   super.init();
   ...
   mountPage(PAGE_NOT_FOUND_MOUNT_PATH, Error404Page.class);
}

Upvotes: 1

Related Questions