WebRequestCycle.onRuntimeException, перенаправляющий на страницу ошибки по умолчанию - PullRequest
0 голосов
/ 17 мая 2011

У меня есть 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 имеет некоторые проблемы, поэтому я удаляю GeneralRunTimeExceptionPage из else и помещаю туда UserActionPortInitializationExceptionPage, затем я увидел эту страницу.

Теперь UserActionPortInitializationException:исключение:

    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 голосов
/ 18 мая 2011

Ваш вывод начинается с «Причины»:

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

Из-за этого я предполагаю, что ваше Исключение обернуто другим.И если он обернут, ваше предложение if не сможет распознать его как UserActionPortInitializationException.

Если вы опубликуете трассировку полного стека, я мог бы проверить мое предположение.

...