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


Java RequestMappingHandlerAdapter.handle方法代碼示例

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


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

示例1: testCustomConversionService

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入方法依賴的package包/類
@Test(expected = TypeMismatchException.class)
public void testCustomConversionService() throws Exception {
	loadBeanDefinitions("mvc-config-custom-conversion-service.xml", 14);

	RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
	assertNotNull(mapping);
	mapping.setDefaultHandler(handlerMethod);

	// default web binding initializer behavior test
	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
	request.setRequestURI("/accounts/12345");
	request.addParameter("date", "2009-10-31");
	MockHttpServletResponse response = new MockHttpServletResponse();

	HandlerExecutionChain chain = mapping.getHandler(request);
	assertEquals(1, chain.getInterceptors().length);
	assertTrue(chain.getInterceptors()[0] instanceof ConversionServiceExposingInterceptor);
	ConversionServiceExposingInterceptor interceptor = (ConversionServiceExposingInterceptor) chain.getInterceptors()[0];
	interceptor.preHandle(request, response, handler);
	assertSame(appContext.getBean("conversionService"), request.getAttribute(ConversionService.class.getName()));

	RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
	assertNotNull(adapter);
	adapter.handle(request, response, handlerMethod);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:26,代碼來源:MvcNamespaceTests.java

示例2: doTestCustomValidator

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入方法依賴的package包/類
private void doTestCustomValidator(String xml) throws Exception {
	loadBeanDefinitions(xml, 14);

	RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
	assertNotNull(mapping);
	assertFalse(mapping.getUrlPathHelper().shouldRemoveSemicolonContent());

	RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
	assertNotNull(adapter);
	assertEquals(true, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));

	// default web binding initializer behavior test
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.addParameter("date", "2009-10-31");
	MockHttpServletResponse response = new MockHttpServletResponse();
	adapter.handle(request, response, handlerMethod);

	assertTrue(appContext.getBean(TestValidator.class).validatorInvoked);
	assertFalse(handler.recordedValidationError);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:MvcNamespaceTests.java

示例3: testCustomConversionService

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入方法依賴的package包/類
@Test(expected=TypeMismatchException.class)
public void testCustomConversionService() throws Exception {
	loadBeanDefinitions("mvc-config-custom-conversion-service.xml", 12);

	RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
	assertNotNull(mapping);
	mapping.setDefaultHandler(handlerMethod);

	// default web binding initializer behavior test
	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
	request.setRequestURI("/accounts/12345");
	request.addParameter("date", "2009-10-31");
	MockHttpServletResponse response = new MockHttpServletResponse();

	HandlerExecutionChain chain = mapping.getHandler(request);
	assertEquals(1, chain.getInterceptors().length);
	assertTrue(chain.getInterceptors()[0] instanceof ConversionServiceExposingInterceptor);
	ConversionServiceExposingInterceptor interceptor = (ConversionServiceExposingInterceptor) chain.getInterceptors()[0];
	interceptor.preHandle(request, response, handler);
	assertSame(appContext.getBean("conversionService"), request.getAttribute(ConversionService.class.getName()));

	RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
	assertNotNull(adapter);
	adapter.handle(request, response, handlerMethod);
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:26,代碼來源:MvcNamespaceTests.java

示例4: testCustomValidator

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入方法依賴的package包/類
@Test
public void testCustomValidator() throws Exception {
	loadBeanDefinitions("mvc-config-custom-validator.xml", 12);

	RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
	assertNotNull(mapping);
	assertFalse(mapping.getUrlPathHelper().shouldRemoveSemicolonContent());

	RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
	assertNotNull(adapter);
	assertEquals(true, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));

	// default web binding initializer behavior test
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.addParameter("date", "2009-10-31");
	MockHttpServletResponse response = new MockHttpServletResponse();
	adapter.handle(request, response, handlerMethod);

	assertTrue(appContext.getBean(TestValidator.class).validatorInvoked);
	assertFalse(handler.recordedValidationError);
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:22,代碼來源:MvcNamespaceTests.java

示例5: testDefaultConfig

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入方法依賴的package包/類
@Test
public void testDefaultConfig() throws Exception {
	loadBeanDefinitions("mvc-config.xml", 14);

	RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
	assertNotNull(mapping);
	assertEquals(0, mapping.getOrder());
	assertTrue(mapping.getUrlPathHelper().shouldRemoveSemicolonContent());
	mapping.setDefaultHandler(handlerMethod);

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.json");
	NativeWebRequest webRequest = new ServletWebRequest(request);
	ContentNegotiationManager manager = mapping.getContentNegotiationManager();
	assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(webRequest));

	RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
	assertNotNull(adapter);
	assertEquals(false, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));

	List<HttpMessageConverter<?>> converters = adapter.getMessageConverters();
	assertTrue(converters.size() > 0);
	for (HttpMessageConverter<?> converter : converters) {
		if (converter instanceof AbstractJackson2HttpMessageConverter) {
			ObjectMapper objectMapper = ((AbstractJackson2HttpMessageConverter) converter).getObjectMapper();
			assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
			assertFalse(objectMapper.getSerializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
			assertFalse(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
			if (converter instanceof MappingJackson2XmlHttpMessageConverter) {
				assertEquals(XmlMapper.class, objectMapper.getClass());
			}
		}
	}

	assertNotNull(appContext.getBean(FormattingConversionServiceFactoryBean.class));
	assertNotNull(appContext.getBean(ConversionService.class));
	assertNotNull(appContext.getBean(LocalValidatorFactoryBean.class));
	assertNotNull(appContext.getBean(Validator.class));

	// default web binding initializer behavior test
	request = new MockHttpServletRequest("GET", "/");
	request.addParameter("date", "2009-10-31");
	request.addParameter("percent", "99.99%");
	MockHttpServletResponse response = new MockHttpServletResponse();

	HandlerExecutionChain chain = mapping.getHandler(request);
	assertEquals(1, chain.getInterceptors().length);
	assertTrue(chain.getInterceptors()[0] instanceof ConversionServiceExposingInterceptor);
	ConversionServiceExposingInterceptor interceptor = (ConversionServiceExposingInterceptor) chain.getInterceptors()[0];
	interceptor.preHandle(request, response, handlerMethod);
	assertSame(appContext.getBean(ConversionService.class), request.getAttribute(ConversionService.class.getName()));

	adapter.handle(request, response, handlerMethod);
	assertTrue(handler.recordedValidationError);
	assertEquals(LocalDate.parse("2009-10-31").toDate(), handler.date);
	assertEquals(Double.valueOf(0.9999), handler.percent);

	CompositeUriComponentsContributor uriComponentsContributor = this.appContext.getBean(
			MvcUriComponentsBuilder.MVC_URI_COMPONENTS_CONTRIBUTOR_BEAN_NAME,
			CompositeUriComponentsContributor.class);

	assertNotNull(uriComponentsContributor);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:63,代碼來源:MvcNamespaceTests.java

示例6: testDefaultConfig

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入方法依賴的package包/類
@Test
public void testDefaultConfig() throws Exception {
	loadBeanDefinitions("mvc-config.xml", 12);

	RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
	assertNotNull(mapping);
	assertEquals(0, mapping.getOrder());
	assertTrue(mapping.getUrlPathHelper().shouldRemoveSemicolonContent());
	mapping.setDefaultHandler(handlerMethod);

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.json");
	NativeWebRequest webRequest = new ServletWebRequest(request);
	ContentNegotiationManager manager = mapping.getContentNegotiationManager();
	assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(webRequest));

	RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
	assertNotNull(adapter);
	assertEquals(false, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));

	List<HttpMessageConverter<?>> messageConverters = adapter.getMessageConverters();
	assertTrue(messageConverters.size() > 0);

	assertNotNull(appContext.getBean(FormattingConversionServiceFactoryBean.class));
	assertNotNull(appContext.getBean(ConversionService.class));
	assertNotNull(appContext.getBean(LocalValidatorFactoryBean.class));
	assertNotNull(appContext.getBean(Validator.class));

	// default web binding initializer behavior test
	request = new MockHttpServletRequest("GET", "/");
	request.addParameter("date", "2009-10-31");
	MockHttpServletResponse response = new MockHttpServletResponse();

	HandlerExecutionChain chain = mapping.getHandler(request);
	assertEquals(1, chain.getInterceptors().length);
	assertTrue(chain.getInterceptors()[0] instanceof ConversionServiceExposingInterceptor);
	ConversionServiceExposingInterceptor interceptor = (ConversionServiceExposingInterceptor) chain.getInterceptors()[0];
	interceptor.preHandle(request, response, handlerMethod);
	assertSame(appContext.getBean(ConversionService.class), request.getAttribute(ConversionService.class.getName()));

	adapter.handle(request, response, handlerMethod);
	assertTrue(handler.recordedValidationError);
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:43,代碼來源:MvcNamespaceTests.java


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