Java Code Examples for org.springframework.context.ApplicationContext#getMessage()

The following examples show how to use org.springframework.context.ApplicationContext#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApiError.java    From etf-webapp with European Union Public License 1.2 5 votes vote down vote up
public ApiError(final Throwable e, final String url, final ApplicationContext applicationContext) {
    logger.error("EXID-" + timestamp + ": An exception occurred while trying to invoke \"" +
            url + "\"", e);
    final LocalizableApiError localizableApiError;
    if (e instanceof LocalizableApiError) {
        localizableApiError = (LocalizableApiError) e;
    } else if (e.getCause() instanceof LocalizableApiError) {
        localizableApiError = (LocalizableApiError) e.getCause();
    } else {
        localizableApiError = null;
    }
    if (localizableApiError != null) {
        this.id = localizableApiError.getId();
        final String err = applicationContext.getMessage(localizableApiError.getId(),
                localizableApiError.getArgumentValueArr(), null,
                // localizableApiError.getUserLocale());
                LocaleContextHolder.getLocale());
        if (err == null) {
            // Unknown
            this.error = ExceptionUtils.getRootCause(e).getMessage();
        } else {
            this.error = err;
        }
    } else {
        this.id = null;
        if (e != null) {
            final Throwable rootCause = ExceptionUtils.getRootCause(e);
            this.error = rootCause != null ? rootCause.getMessage() : e.getMessage();
        } else {
            this.error = "Internal error";
        }
    }
    stacktrace = ExceptionUtils.getRootCauseStackTrace(e);
    this.url = url;
}
 
Example 2
Source File: CLIUtil.java    From ranger with Apache License 2.0 5 votes vote down vote up
public static String getMessage(String messagekey,HttpServletRequest request){
	ServletContext servletContext = request.getSession().getServletContext();
	ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
	Object[] args = new Object[] {};
	String messageValue=ctx.getMessage(messagekey, args, Locale.getDefault());
	return messageValue;
}