Search in sources :

Example 1 with MalformedHeaderException

use of org.forgerock.http.header.MalformedHeaderException in project OpenAM by OpenRock.

the class AuthenticationServiceV1 method getLocalizedMessage.

/**
     * Get the localized message for the requested language if the given exception or its cause
     * is an instance of <code>L10NMessage</code>.
     *
     * @param exception The exception that contains the localized message.
     *
     * @return The localized message.
     */
protected String getLocalizedMessage(Request request, Exception exception) {
    AcceptLanguageHeader languages = null;
    try {
        languages = request.getHeaders().get(AcceptLanguageHeader.class);
    } catch (MalformedHeaderException e) {
        DEBUG.warning("Could not parse accept language header", e);
    }
    String message = null;
    L10NMessage localizedException = null;
    if (exception instanceof L10NMessage) {
        localizedException = (L10NMessage) exception;
    } else if (exception.getCause() instanceof L10NMessage) {
        localizedException = (L10NMessage) exception.getCause();
    }
    if (localizedException != null) {
        if (languages == null) {
            message = localizeMessage(localizedException, Locale.getDefaultLocale());
        } else {
            for (java.util.Locale language : languages.getLocales().getLocales()) {
                message = localizeMessage(localizedException, language);
                if (message != null) {
                    break;
                }
            }
        }
    }
    if (message == null) {
        message = exception.getMessage();
    }
    return message;
}
Also used : L10NMessage(com.sun.identity.shared.locale.L10NMessage) AcceptLanguageHeader(org.forgerock.http.header.AcceptLanguageHeader) MalformedHeaderException(org.forgerock.http.header.MalformedHeaderException)

Aggregations

L10NMessage (com.sun.identity.shared.locale.L10NMessage)1 AcceptLanguageHeader (org.forgerock.http.header.AcceptLanguageHeader)1 MalformedHeaderException (org.forgerock.http.header.MalformedHeaderException)1