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