本文整理汇总了Java中org.springframework.web.servlet.i18n.LocaleChangeInterceptor类的典型用法代码示例。如果您正苦于以下问题:Java LocaleChangeInterceptor类的具体用法?Java LocaleChangeInterceptor怎么用?Java LocaleChangeInterceptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LocaleChangeInterceptor类属于org.springframework.web.servlet.i18n包,在下文中一共展示了LocaleChangeInterceptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifyStartAuthentication
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
@Test
public void verifyStartAuthentication() throws Exception {
final MockHttpServletRequest mockRequest = new MockHttpServletRequest();
mockRequest.setParameter(ThemeChangeInterceptor.DEFAULT_PARAM_NAME, MY_THEME);
mockRequest.setParameter(LocaleChangeInterceptor.DEFAULT_PARAM_NAME, MY_LOCALE);
mockRequest.setParameter(CasProtocolConstants.PARAMETER_METHOD, MY_METHOD);
final MockHttpSession mockSession = new MockHttpSession();
mockRequest.setSession(mockSession);
final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class);
when(servletExternalContext.getNativeRequest()).thenReturn(mockRequest);
final MockRequestContext mockRequestContext = new MockRequestContext();
mockRequestContext.setExternalContext(servletExternalContext);
mockRequestContext.getFlowScope().put(CasProtocolConstants.PARAMETER_SERVICE,
org.jasig.cas.services.TestUtils.getService(MY_SERVICE));
final FacebookClient facebookClient = new FacebookClient(MY_KEY, MY_SECRET);
final TwitterClient twitterClient = new TwitterClient(MY_KEY, MY_SECRET);
final Clients clients = new Clients(MY_LOGIN_URL, facebookClient, twitterClient);
final ClientAction action = new ClientAction();
action.setCentralAuthenticationService(mock(CentralAuthenticationService.class));
action.setClients(clients);
final Event event = action.execute(mockRequestContext);
assertEquals("error", event.getId());
assertEquals(MY_THEME, mockSession.getAttribute(ThemeChangeInterceptor.DEFAULT_PARAM_NAME));
assertEquals(MY_LOCALE, mockSession.getAttribute(LocaleChangeInterceptor.DEFAULT_PARAM_NAME));
assertEquals(MY_METHOD, mockSession.getAttribute(CasProtocolConstants.PARAMETER_METHOD));
final MutableAttributeMap flowScope = mockRequestContext.getFlowScope();
final Map<String, String> urls = (Map<String, String>) flowScope.get(ClientAction.PAC4J_URLS);
assertTrue((urls.get("Facebook"))
.startsWith("https://www.facebook.com/v2.2/dialog/oauth?client_id=my_key&redirect_uri=http%3A%2F%2Fcasserver%2Flogin%3F"
+ Clients.DEFAULT_CLIENT_NAME_PARAMETER + "%3DFacebookClient&state="));
assertEquals(MY_LOGIN_URL + '?' + Clients.DEFAULT_CLIENT_NAME_PARAMETER
+ "=TwitterClient&needs_client_redirection=true", urls.get("Twitter"));
}
示例2: testBeanDecoration
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
@Test
public void testBeanDecoration() throws Exception {
loadBeanDefinitions("mvc-config-bean-decoration.xml", 16);
RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
assertNotNull(mapping);
mapping.setDefaultHandler(handlerMethod);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
HandlerExecutionChain chain = mapping.getHandler(request);
assertEquals(3, chain.getInterceptors().length);
assertTrue(chain.getInterceptors()[0] instanceof ConversionServiceExposingInterceptor);
assertTrue(chain.getInterceptors()[1] instanceof LocaleChangeInterceptor);
assertTrue(chain.getInterceptors()[2] instanceof ThemeChangeInterceptor);
LocaleChangeInterceptor interceptor = (LocaleChangeInterceptor) chain.getInterceptors()[1];
assertEquals("lang", interceptor.getParamName());
ThemeChangeInterceptor interceptor2 = (ThemeChangeInterceptor) chain.getInterceptors()[2];
assertEquals("style", interceptor2.getParamName());
}
示例3: doFilterInternal
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
String newLocale = request.getParameter(LocaleChangeInterceptor.DEFAULT_PARAM_NAME);
if(localeResolver != null && newLocale != null){
Locale locale = StringUtils.parseLocaleString(newLocale);
logger.warn("setLocale : "+locale.toString());
localeResolver.setLocale(request, response, locale);
LocaleContextHolder.setLocale(locale);
}
chain.doFilter(request, response);
if (localeResolver != null) {
LocaleContextHolder.resetLocaleContext();
}
}
示例4: testBeanDecoration
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
@Test
public void testBeanDecoration() throws Exception {
loadBeanDefinitions("mvc-config-bean-decoration.xml", 14);
RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
assertNotNull(mapping);
mapping.setDefaultHandler(handlerMethod);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
HandlerExecutionChain chain = mapping.getHandler(request);
assertEquals(3, chain.getInterceptors().length);
assertTrue(chain.getInterceptors()[0] instanceof ConversionServiceExposingInterceptor);
assertTrue(chain.getInterceptors()[1] instanceof LocaleChangeInterceptor);
assertTrue(chain.getInterceptors()[2] instanceof ThemeChangeInterceptor);
LocaleChangeInterceptor interceptor = (LocaleChangeInterceptor) chain.getInterceptors()[1];
assertEquals("lang", interceptor.getParamName());
ThemeChangeInterceptor interceptor2 = (ThemeChangeInterceptor) chain.getInterceptors()[2];
assertEquals("style", interceptor2.getParamName());
}
示例5: prepareForLoginPage
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
/**
* Prepare the data for the login page.
*
* @param context The current webflow context
*/
protected void prepareForLoginPage(final RequestContext context) {
final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
final HttpServletResponse response = WebUtils.getHttpServletResponse(context);
final HttpSession session = request.getSession();
// web context
final WebContext webContext = new J2EContext(request, response);
// save parameters in web session
final WebApplicationService service = WebUtils.getService(context);
logger.debug("save service: {}", service);
session.setAttribute(CasProtocolConstants.PARAMETER_SERVICE, service);
saveRequestParameter(request, session, ThemeChangeInterceptor.DEFAULT_PARAM_NAME);
saveRequestParameter(request, session, LocaleChangeInterceptor.DEFAULT_PARAM_NAME);
saveRequestParameter(request, session, CasProtocolConstants.PARAMETER_METHOD);
final LinkedHashMap<String, String> urls = new LinkedHashMap<>();
// for all clients, generate redirection urls
for (final Client client : this.clients.findAllClients()) {
final IndirectClient indirectClient = (IndirectClient) client;
// clean Client suffix for default names
final String name = client.getName().replace("Client", "");
final String redirectionUrl = indirectClient.getRedirectionUrl(webContext);
logger.debug("{} -> {}", name, redirectionUrl);
urls.put(name, redirectionUrl);
}
context.getFlowScope().put(PAC4J_URLS, urls);
}
示例6: localeChangeInterceptor
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
@RefreshScope
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
final LocaleChangeInterceptor bean = new LocaleChangeInterceptor();
bean.setParamName(this.casProperties.getLocale().getParamName());
return bean;
}
示例7: verifyStartAuthentication
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
@Test
public void verifyStartAuthentication() throws Exception {
final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
final MockHttpServletRequest mockRequest = new MockHttpServletRequest();
mockRequest.setParameter(ThemeChangeInterceptor.DEFAULT_PARAM_NAME, MY_THEME);
mockRequest.setParameter(LocaleChangeInterceptor.DEFAULT_PARAM_NAME, MY_LOCALE);
mockRequest.setParameter(CasProtocolConstants.PARAMETER_METHOD, MY_METHOD);
final MockHttpSession mockSession = new MockHttpSession();
mockRequest.setSession(mockSession);
final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class);
when(servletExternalContext.getNativeRequest()).thenReturn(mockRequest);
when(servletExternalContext.getNativeResponse()).thenReturn(mockResponse);
final MockRequestContext mockRequestContext = new MockRequestContext();
mockRequestContext.setExternalContext(servletExternalContext);
mockRequestContext.getFlowScope().put(CasProtocolConstants.PARAMETER_SERVICE,
RegisteredServiceTestUtils.getService(MY_SERVICE));
final FacebookClient facebookClient = new FacebookClient(MY_KEY, MY_SECRET);
final TwitterClient twitterClient = new TwitterClient("3nJPbVTVRZWAyUgoUKQ8UA", "h6LZyZJmcW46Vu8R47MYfeXTSYGI30EqnWaSwVhFkbA");
final Clients clients = new Clients(MY_LOGIN_URL, facebookClient, twitterClient);
final DelegatedClientAuthenticationAction action = new DelegatedClientAuthenticationAction(clients,
null, mock(CentralAuthenticationService.class),
"theme", "locale", false);
final Event event = action.execute(mockRequestContext);
assertEquals("error", event.getId());
assertEquals(MY_THEME, mockSession.getAttribute(ThemeChangeInterceptor.DEFAULT_PARAM_NAME));
assertEquals(MY_LOCALE, mockSession.getAttribute(LocaleChangeInterceptor.DEFAULT_PARAM_NAME));
assertEquals(MY_METHOD, mockSession.getAttribute(CasProtocolConstants.PARAMETER_METHOD));
final MutableAttributeMap flowScope = mockRequestContext.getFlowScope();
final Set<DelegatedClientAuthenticationAction.ProviderLoginPageConfiguration> urls =
(Set<DelegatedClientAuthenticationAction.ProviderLoginPageConfiguration>) flowScope.get(DelegatedClientAuthenticationAction.PAC4J_URLS);
assertFalse(urls.isEmpty());
assertSame(2, urls.size());
}
示例8: localeChangeInterceptor
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
@RefreshScope
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
LocaleChangeInterceptor bean = new LocaleChangeInterceptor();
bean.setParamName(this.casProperties.getLocale().getParamName());
return bean;
}
示例9: localeChangeInterceptor
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
lci.setParamName("lang");
return lci;
}
示例10: localeInterceptor
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
/**
* Set up locale configuration by url parameter
*
* @return
*/
@Bean
public LocaleChangeInterceptor localeInterceptor() {
LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor();
interceptor.setParamName(LANG_PARAMETER_NAME);
return interceptor;
}
示例11: localeInterceptor
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
/**
* Set up locale configuration by url parameter
*
* @return
*/
@Bean
public LocaleChangeInterceptor localeInterceptor() {
LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor();
interceptor.setParamName("lang");
return interceptor;
}
示例12: localeChangeInterceptor
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
// 参数名
lci.setParamName("lang");
return lci;
}
示例13: addInterceptors
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
@Override
public void addInterceptors(InterceptorRegistry registry) {
LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
localeChangeInterceptor.setParamName("lang");
localeChangeInterceptor.setIgnoreInvalidLocale(true);
localeChangeInterceptor.setLanguageTagCompliant(true);
registry.addInterceptor(localeChangeInterceptor);
}
示例14: testInterceptors
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
@Test
public void testInterceptors() throws Exception {
loadBeanDefinitions("mvc-config-interceptors.xml", 21);
RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
assertNotNull(mapping);
mapping.setDefaultHandler(handlerMethod);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
request.setRequestURI("/accounts/12345");
request.addParameter("locale", "en");
request.addParameter("theme", "green");
HandlerExecutionChain chain = mapping.getHandler(request);
assertEquals(5, chain.getInterceptors().length);
assertTrue(chain.getInterceptors()[0] instanceof ConversionServiceExposingInterceptor);
assertTrue(chain.getInterceptors()[1] instanceof LocaleChangeInterceptor);
assertTrue(chain.getInterceptors()[2] instanceof WebRequestHandlerInterceptorAdapter);
assertTrue(chain.getInterceptors()[3] instanceof ThemeChangeInterceptor);
assertTrue(chain.getInterceptors()[4] instanceof UserRoleAuthorizationInterceptor);
request.setRequestURI("/admin/users");
chain = mapping.getHandler(request);
assertEquals(3, chain.getInterceptors().length);
request.setRequestURI("/logged/accounts/12345");
chain = mapping.getHandler(request);
assertEquals(5, chain.getInterceptors().length);
assertTrue(chain.getInterceptors()[4] instanceof WebRequestHandlerInterceptorAdapter);
request.setRequestURI("/foo/logged");
chain = mapping.getHandler(request);
assertEquals(5, chain.getInterceptors().length);
assertTrue(chain.getInterceptors()[4] instanceof WebRequestHandlerInterceptorAdapter);
}
示例15: setup
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
@Before
public void setup() {
CookieLocaleResolver localeResolver = new CookieLocaleResolver();
localeResolver.setCookieDomain("domain");
this.mockMvc = standaloneSetup(new SimpleController())
.addInterceptors(new LocaleChangeInterceptor())
.setLocaleResolver(localeResolver)
.defaultRequest(get("/").param("locale", "en_US"))
.alwaysExpect(status().isOk())
.build();
}