當前位置: 首頁>>代碼示例>>Java>>正文


Java HandlerInterceptor.preHandle方法代碼示例

本文整理匯總了Java中org.springframework.web.servlet.HandlerInterceptor.preHandle方法的典型用法代碼示例。如果您正苦於以下問題:Java HandlerInterceptor.preHandle方法的具體用法?Java HandlerInterceptor.preHandle怎麽用?Java HandlerInterceptor.preHandle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.web.servlet.HandlerInterceptor的用法示例。


在下文中一共展示了HandlerInterceptor.preHandle方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: verifyAdaptedInterceptor

import org.springframework.web.servlet.HandlerInterceptor; //導入方法依賴的package包/類
private void verifyAdaptedInterceptor(HandlerInterceptor interceptor, TestWebRequestInterceptor webInterceptor)
		throws Exception {
	assertTrue(interceptor instanceof WebRequestHandlerInterceptorAdapter);
	interceptor.preHandle(request, response, null);
	assertTrue(webInterceptor.preHandleInvoked);
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:7,代碼來源:InterceptorRegistryTests.java

示例2: preHandle

import org.springframework.web.servlet.HandlerInterceptor; //導入方法依賴的package包/類
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    List<? extends HandlerInterceptor> interceptors = getInterceptors(request, handler);
    if (!CollectionUtils.isEmpty(interceptors)) {
        for (HandlerInterceptor interceptor : interceptors) {
            boolean ret = interceptor.preHandle(request, response, handler);
            if (!ret) return false;
        }
    }
    return true;
}
 
開發者ID:cyanqueen,項目名稱:backbone,代碼行數:12,代碼來源:AnnotationBasedProcessorInterceptor.java

示例3: getHandler

import org.springframework.web.servlet.HandlerInterceptor; //導入方法依賴的package包/類
private HandlerExecutionChain getHandler(MockHttpServletRequest req) throws Exception {
	HandlerExecutionChain hec = hm.getHandler(req);
	HandlerInterceptor[] interceptors = hec.getInterceptors();
	if (interceptors != null) {
		for (HandlerInterceptor interceptor : interceptors) {
			interceptor.preHandle(req, null, hec.getHandler());
		}
	}
	return hec;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:11,代碼來源:PathMatchingUrlHandlerMappingTests.java

示例4: getHandler

import org.springframework.web.servlet.HandlerInterceptor; //導入方法依賴的package包/類
private HandlerExecutionChain getHandler(HandlerMapping hm, MockHttpServletRequest req) throws Exception {
	HandlerExecutionChain hec = hm.getHandler(req);
	HandlerInterceptor[] interceptors = hec.getInterceptors();
	if (interceptors != null) {
		for (HandlerInterceptor interceptor : interceptors) {
			interceptor.preHandle(req, null, hec.getHandler());
		}
	}
	return hec;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:11,代碼來源:SimpleUrlHandlerMappingTests.java

示例5: testResources

import org.springframework.web.servlet.HandlerInterceptor; //導入方法依賴的package包/類
@Test
public void testResources() throws Exception {
	loadBeanDefinitions("mvc-config-resources.xml", 10);

	HttpRequestHandlerAdapter adapter = appContext.getBean(HttpRequestHandlerAdapter.class);
	assertNotNull(adapter);

	ResourceHttpRequestHandler handler = appContext.getBean(ResourceHttpRequestHandler.class);
	assertNotNull(handler);

	SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class);
	assertNotNull(mapping);
	assertEquals(Ordered.LOWEST_PRECEDENCE - 1, mapping.getOrder());

	BeanNameUrlHandlerMapping beanNameMapping = appContext.getBean(BeanNameUrlHandlerMapping.class);
	assertNotNull(beanNameMapping);
	assertEquals(2, beanNameMapping.getOrder());

	ResourceUrlProvider urlProvider = appContext.getBean(ResourceUrlProvider.class);
	assertNotNull(urlProvider);

	MappedInterceptor mappedInterceptor = appContext.getBean(MappedInterceptor.class);
	assertNotNull(urlProvider);
	assertEquals(ResourceUrlProviderExposingInterceptor.class, mappedInterceptor.getInterceptor().getClass());

	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setRequestURI("/resources/foo.css");
	request.setMethod("GET");

	HandlerExecutionChain chain = mapping.getHandler(request);
	assertTrue(chain.getHandler() instanceof ResourceHttpRequestHandler);

	MockHttpServletResponse response = new MockHttpServletResponse();
	for (HandlerInterceptor interceptor : chain.getInterceptors()) {
		interceptor.preHandle(request, response, chain.getHandler());
	}
	ModelAndView mv = adapter.handle(request, response, chain.getHandler());
	assertNull(mv);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:40,代碼來源:MvcNamespaceTests.java

示例6: preHandle

import org.springframework.web.servlet.HandlerInterceptor; //導入方法依賴的package包/類
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

    for (HandlerInterceptor item : handlers) {
        if (!item.preHandle(request, response, handler)) {
            return false;
        }
    }

    return true;
}
 
開發者ID:treeleafj,項目名稱:treeleaf,代碼行數:12,代碼來源:MultipleHandlerInerceptor.java

示例7: execute

import org.springframework.web.servlet.HandlerInterceptor; //導入方法依賴的package包/類
/**
 * Execute the action using the given context.
 *
 * @param context       The current context
 * @param configuration The configuration
 * @throws Exception Any error
 */
public void execute(JPublishContext context, Configuration configuration) throws Exception {
    HttpServletRequest request = (HttpServletRequest) context.get("request");
    HttpServletResponse response = (HttpServletResponse) context.get("response");
    Page page = ((Page) context.get("page"));

    if (page != null) {
        Locale locale = page.getLocale();

        ApplicationContext applicationContext = getApplicationContext(context);
        context.put(SPRING, applicationContext);
        HandlerInterceptor localeChangeInterceptor = (HandlerInterceptor)
                applicationContext.getBean("localeChangeInterceptor");

        if (localeChangeInterceptor != null) {
            try {
                LocaleResolver localeResolver = (LocaleResolver) applicationContext.getBean("localeResolver");
                if (localeResolver != null) {
                    request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, localeResolver);
                    localeChangeInterceptor.preHandle(request, response, null);
                    locale = localeResolver.resolveLocale(request);
                    MessageSource messageSource = (MessageSource) applicationContext.getBean("messageSource");
                    if (messageSource != null) {
                        context.put(I18N, new MessageSourceAccessor(messageSource, locale));
                    } else {
                        log.error("There is no 'messageSource' defined in your application context." +
                                " Please define one.");
                    }
                } else {
                    log.error("please define a 'localeResolver' bean in your Application context");
                }
            } catch (Exception e) {
                e.printStackTrace();
                log.error("Cannot handle the locale change event");
            }
        }
        page.setLocale(locale);
    }
}
 
開發者ID:florinpatrascu,項目名稱:jpublish,代碼行數:46,代碼來源:SpringI18nSupport.java

示例8: testResources

import org.springframework.web.servlet.HandlerInterceptor; //導入方法依賴的package包/類
@Test
public void testResources() throws Exception {
	loadBeanDefinitions("mvc-config-resources.xml", 5);

	HttpRequestHandlerAdapter adapter = appContext.getBean(HttpRequestHandlerAdapter.class);
	assertNotNull(adapter);

	ResourceHttpRequestHandler handler = appContext.getBean(ResourceHttpRequestHandler.class);
	assertNotNull(handler);

	SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class);
	assertNotNull(mapping);
	assertEquals(Ordered.LOWEST_PRECEDENCE - 1, mapping.getOrder());

	BeanNameUrlHandlerMapping beanNameMapping = appContext.getBean(BeanNameUrlHandlerMapping.class);
	assertNotNull(beanNameMapping);
	assertEquals(2, beanNameMapping.getOrder());

	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setRequestURI("/resources/foo.css");
	request.setMethod("GET");

	HandlerExecutionChain chain = mapping.getHandler(request);
	assertTrue(chain.getHandler() instanceof ResourceHttpRequestHandler);

	MockHttpServletResponse response = new MockHttpServletResponse();
	for (HandlerInterceptor interceptor : chain.getInterceptors()) {
		interceptor.preHandle(request, response, chain.getHandler());
	}
	ModelAndView mv = adapter.handle(request, response, chain.getHandler());
	assertNull(mv);
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:33,代碼來源:MvcNamespaceTests.java

示例9: verifyWebInterceptor

import org.springframework.web.servlet.HandlerInterceptor; //導入方法依賴的package包/類
private void verifyWebInterceptor(HandlerInterceptor interceptor, TestWebRequestInterceptor webInterceptor) throws Exception {
	assertTrue(interceptor instanceof WebRequestHandlerInterceptorAdapter);
	interceptor.preHandle(this.request, this.response, null);
	assertTrue(webInterceptor.preHandleInvoked);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:6,代碼來源:InterceptorRegistryTests.java


注:本文中的org.springframework.web.servlet.HandlerInterceptor.preHandle方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。