Example usage for org.springframework.context.i18n LocaleContextHolder resetLocaleContext

List of usage examples for org.springframework.context.i18n LocaleContextHolder resetLocaleContext

Introduction

In this page you can find the example usage for org.springframework.context.i18n LocaleContextHolder resetLocaleContext.

Prototype

public static void resetLocaleContext() 

Source Link

Document

Reset the LocaleContext for the current thread.

Usage

From source file:sk.openhouse.web.filter.LocaleConfigurerFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {

    if (localeResolver != null) {
        Locale locale = localeResolver.resolveLocale(request);
        LocaleContextHolder.setLocale(locale);
    }//from  w  w  w.  j  a  v a 2 s. com

    filterChain.doFilter(request, response);

    if (localeResolver != null) {
        LocaleContextHolder.resetLocaleContext();
    }
}

From source file:org.vaadin.webinars.springandvaadin.i18n.ui.Servlet.java

@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    final Locale locale = localeResolver.resolveLocale(request);
    LocaleContextHolder.setLocale(locale);
    ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request);
    RequestContextHolder.setRequestAttributes(requestAttributes);
    try {/*from   w  w w . j  a  v a 2 s. co m*/
        super.service(new HttpServletRequestWrapper(request) {
            @Override
            public Locale getLocale() {
                return locale;
            }
        }, response);
    } finally {
        if (!locale.equals(LocaleContextHolder.getLocale())) {
            localeResolver.setLocale(request, response, LocaleContextHolder.getLocale());
        }
        LocaleContextHolder.resetLocaleContext();
        RequestContextHolder.resetRequestAttributes();
    }
}

From source file:io.neba.core.spring.web.filter.NebaRequestContextFilter.java

private void resetContextHolders() {
    LocaleContextHolder.resetLocaleContext();
    RequestContextHolder.resetRequestAttributes();
}

From source file:de.blizzy.documentr.web.FunctionsTest.java

@After
public void tearDown() {
    Functions.setGlobalRepositoryManager(null);
    Functions.setPageStore(null);//  w w w .j ava2s .  c  om
    Functions.setUserStore(null);
    Functions.setPageRenderer(null);
    Functions.setMarkdownProcessor(null);
    Functions.setMessageSource(null);
    Functions.setMacroFactory(null);
    SecurityContextHolder.clearContext();
    LocaleContextHolder.resetLocaleContext();
    RequestContextHolder.resetRequestAttributes();
}

From source file:com.github.peholmst.springsecuritydemo.servlet.SpringApplicationServlet.java

@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    /*/*  www.j av a2 s. c  o  m*/
     * Resolve the locale from the request
     */
    final Locale locale = localeResolver.resolveLocale(request);
    if (logger.isDebugEnabled()) {
        logger.debug("Resolved locale [" + locale + "]");
    }

    /*
     * Store the locale in the LocaleContextHolder, making it available to
     * Spring.
     */
    LocaleContextHolder.setLocale(locale);
    ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request);
    RequestContextHolder.setRequestAttributes(requestAttributes);
    try {
        /*
         * We need to override the request to return the locale resolved by
         * Spring.
         */
        super.service(new HttpServletRequestWrapper(request) {
            @Override
            public Locale getLocale() {
                return locale;
            }
        }, response);
    } finally {
        if (!locale.equals(LocaleContextHolder.getLocale())) {
            /*
             * The locale in LocaleContextHolder was changed during the
             * request, so we have to update the resolver.
             */
            if (logger.isDebugEnabled()) {
                logger.debug("Locale changed, updating locale resolver");
            }
            localeResolver.setLocale(request, response, LocaleContextHolder.getLocale());
        }
        LocaleContextHolder.resetLocaleContext();
        RequestContextHolder.resetRequestAttributes();
    }
}