WebRequestCycle.onRuntimeException重定向到默认错误页面

时间:2011-05-17 14:58:10

标签: java exception wicket

我的wicket应用程序有4个不同的错误页面。 WebRequestCycle.onRuntimeException方法是:

@Override
public final Page onRuntimeException(Page cause, RuntimeException runtimeException) {
    if (runtimeException instanceof EMSUserNotFoundException) {
        return new EMSUserNotFoundExceptionPage(runtimeException);
    } else if (runtimeException instanceof EMSUnreachableException) {
        return new EMSUnreachableExceptionPage(runtimeException);
    } else if (runtimeException instanceof UserActionPortInitializationException) {
        return new UserActionPortInitializationExceptionPage(runtimeException);
    } else {
        return new GeneralRunTimeExceptionPage(runtimeException);
    }       
}

在运行时EMSUserNotFoundExceptionPage中,EMSUnreachableExceptionPage,GeneralRunTimeExceptionPage正在显示相应的案例。但请求循环不会重定向到UserActionPortInitializationExceptionPage。我以为UserActionPortInitializationExceptionPage有一些问题所以我从else中删除了GeneralRunTimeExceptionPage并将UserActionPortInitializationExceptionPage放在那里,然后我看到了那个页面。

现在UserActionPortInitializationException是:

public class UserActionPortInitializationException extends RuntimeException {

    private static final long serialVersionUID = 10129L;

    private final static String message = "UserActionPort initialization failed";

    public UserActionPortInitializationException() {
        super(message);
    }
}

抛出此异常的代码段是:

    public static String getUserActionPortAddress() {
        String userActionPortAddress = null;
        ClassPathResource userActionPortAddressResource = new ClassPathResource("port-address.properties");
        Properties properties = null;
        try {
            properties = loadProperties(userActionPortAddressResource.getFile());
        } catch (Exception e) {
            throw new UserActionPortInitializationException();
        }

        if (properties != null) {
            userActionPortAddress = properties.getProperty("port");
        }

        if (userActionPortAddress == null) {
            throw new UserActionPortInitializationException();
        }

        return userActionPortAddress;
    }

    private static Properties loadProperties(File file) throws Exception {
        InputStream is = null;
        Properties props = new Properties();
        try {
            is = new FileInputStream(file);
            props.load(is);
        } finally {
            is.close();
        }
        return props;
    }

当控制台中的应用程序抛出UserActionPortInitializationException时,我得到:

Caused by: release.exception.UserActionPortInitializationException: UserActionPort initialization failed

这意味着该代码段会抛出异常,但我无法理解为什么页面没有重定向。

了解更多信息:

UserActionPortInitializationExceptionPage.java:

public class UserActionPortInitializationExceptionPage extends ExceptionBasePage {

public UserActionPortInitializationExceptionPage(RuntimeException runtimeException) {
    super(runtimeException);
}

}

UserActionPortInitializationExceptionPage.html:

<html xmlns:wicket>
<body>
    <wicket:extend>
        <h1 style="font-size: 1.5em; color: red;">UserActionPort initialization failed</h1>
        <i>Please contact administrator</i>
    </wicket:extend>
</body>

谢谢和问候。

1 个答案:

答案 0 :(得分:0)

您的输出以“引起”:

开头
Caused by: release.exception.UserActionPortInitializationException: UserActionPort initialization failed

因此我认为你的异常被另一个包裹。如果它被包装,你的if子句就无法将其识别为UserActionPortInitializationException

如果您发布完整的堆栈跟踪,我可以验证我的假设。