/** * Determine the fallback locale for this context. * <p>The default implementation checks for a JSTL locale attribute in request, session * or application scope; if not found, returns the {@code HttpServletRequest.getLocale()}. * @return the fallback locale (never {@code null}) * @see javax.servlet.http.HttpServletRequest#getLocale() */ protected Locale getFallbackLocale() { if (jstlPresent) { Locale locale = JstlLocaleResolver.getJstlLocale(getRequest(), getServletContext()); if (locale != null) { return locale; } } return getRequest().getLocale(); }
/** * Determine the fallback time zone for this context. * <p>The default implementation checks for a JSTL time zone attribute in request, * session or application scope; returns {@code null} if not found. * @return the fallback time zone (or {@code null} if none derivable from the request) */ @Nullable protected TimeZone getFallbackTimeZone() { if (jstlPresent) { TimeZone timeZone = JstlLocaleResolver.getJstlTimeZone(getRequest(), getServletContext()); if (timeZone != null) { return timeZone; } } return null; }
/** * Determine the fallback locale for this context. * <p>The default implementation checks for a JSTL locale attribute in request, session * or application scope; if not found, returns the {@code HttpServletRequest.getLocale()}. * @return the fallback locale (never {@code null}) * @see javax.servlet.http.HttpServletRequest#getLocale() */ protected Locale getFallbackLocale() { if (jstlPresent) { Locale locale = JstlLocaleResolver.getJstlLocale(getRequest(), getServletContext()); if (locale != null) { return locale; } } return getRequest().getLocale(); }
/** * Exposes JSTL-specific request attributes specifying locale * and resource bundle for JSTL's formatting and message tags, * using Spring's locale and MessageSource. * @param requestContext the context for the current HTTP request, * including the ApplicationContext to expose as MessageSource */ public static void exposeLocalizationContext(RequestContext requestContext) { Config.set(requestContext.getRequest(), Config.FMT_LOCALE, requestContext.getLocale()); TimeZone timeZone = requestContext.getTimeZone(); if (timeZone != null) { Config.set(requestContext.getRequest(), Config.FMT_TIME_ZONE, timeZone); } MessageSource messageSource = getJstlAwareMessageSource( requestContext.getServletContext(), requestContext.getMessageSource()); LocalizationContext jstlContext = new SpringLocalizationContext(messageSource, requestContext.getRequest()); Config.set(requestContext.getRequest(), Config.FMT_LOCALIZATION_CONTEXT, jstlContext); }
/** * Determine the fallback theme for this context. * <p>The default implementation returns the default theme (with name "theme"). * @return the fallback theme (never {@code null}) */ protected Theme getFallbackTheme() { ThemeSource themeSource = RequestContextUtils.getThemeSource(getRequest()); if (themeSource == null) { themeSource = new ResourceBundleThemeSource(); } Theme theme = themeSource.getTheme(DEFAULT_THEME_NAME); if (theme == null) { throw new IllegalStateException("No theme defined and no fallback theme found"); } return theme; }
/** * Determine the fallback time zone for this context. * <p>The default implementation checks for a JSTL time zone attribute in request, * session or application scope; returns {@code null} if not found. * @return the fallback time zone (or {@code null} if none derivable from the request) */ @Nullable protected TimeZone getFallbackTimeZone() { if (jstlPresent) { TimeZone timeZone = JstlLocaleResolver.getJstlTimeZone(getRequest(), getServletContext()); if (timeZone != null) { return timeZone; } } return null; }
/** * Determine the fallback theme for this context. * <p>The default implementation returns the default theme (with name "theme"). * @return the fallback theme (never {@code null}) */ protected Theme getFallbackTheme() { ThemeSource themeSource = RequestContextUtils.getThemeSource(getRequest()); if (themeSource == null) { themeSource = new ResourceBundleThemeSource(); } Theme theme = themeSource.getTheme(DEFAULT_THEME_NAME); if (theme == null) { throw new IllegalStateException("No theme defined and no fallback theme found"); } return theme; }
/** * Exposes JSTL-specific request attributes specifying locale * and resource bundle for JSTL's formatting and message tags, * using Spring's locale and MessageSource. * @param requestContext the context for the current HTTP request, * including the ApplicationContext to expose as MessageSource */ public static void exposeLocalizationContext(RequestContext requestContext) { Config.set(requestContext.getRequest(), Config.FMT_LOCALE, requestContext.getLocale()); TimeZone timeZone = requestContext.getTimeZone(); if (timeZone != null) { Config.set(requestContext.getRequest(), Config.FMT_TIME_ZONE, timeZone); } MessageSource messageSource = getJstlAwareMessageSource( requestContext.getServletContext(), requestContext.getMessageSource()); LocalizationContext jstlContext = new SpringLocalizationContext(messageSource, requestContext.getRequest()); Config.set(requestContext.getRequest(), Config.FMT_LOCALIZATION_CONTEXT, jstlContext); }
public class BlackListFilter extends ZuulFilter { @Override public String filterType() { return "pre"; } ... @Override public Object run() { RequestContext ctx = RequestContext.getCurrentContext(); String uri = ctx.getRequest().getRequestURI(); String appId = uri.split("/")[1]; if (blackList.contains(appId)) { ctx.setSendZuulResponse(false); LOG.info("Request '{}' from {}:{} is blocked", uri, ctx.getRequest().getRemoteHost(), ctx.getRequest().getRemotePort()); } return null; } }
/** * Determine the fallback locale for this context. * <p>The default implementation checks for a JSTL locale attribute in request, session * or application scope; if not found, returns the {@code HttpServletRequest.getLocale()}. * @return the fallback locale (never {@code null}) * @see javax.servlet.http.HttpServletRequest#getLocale() */ protected Locale getFallbackLocale() { if (jstlPresent) { Locale locale = JstlLocaleResolver.getJstlLocale(getRequest(), getServletContext()); if (locale != null) { return locale; } } return getRequest().getLocale(); }
/** * Exposes JSTL-specific request attributes specifying locale * and resource bundle for JSTL's formatting and message tags, * using Spring's locale and MessageSource. * @param requestContext the context for the current HTTP request, * including the ApplicationContext to expose as MessageSource */ public static void exposeLocalizationContext(RequestContext requestContext) { Config.set(requestContext.getRequest(), Config.FMT_LOCALE, requestContext.getLocale()); TimeZone timeZone = requestContext.getTimeZone(); if (timeZone != null) { Config.set(requestContext.getRequest(), Config.FMT_TIME_ZONE, timeZone); } MessageSource messageSource = getJstlAwareMessageSource( requestContext.getServletContext(), requestContext.getMessageSource()); LocalizationContext jstlContext = new SpringLocalizationContext(messageSource, requestContext.getRequest()); Config.set(requestContext.getRequest(), Config.FMT_LOCALIZATION_CONTEXT, jstlContext); }