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


Java RequestMappingHandlerAdapter.getMessageConverters方法代碼示例

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


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

示例1: rebuildMessageConverter

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入方法依賴的package包/類
private void rebuildMessageConverter(RequestMappingHandlerAdapter adapter) {
        List<HttpMessageConverter<?>> messageConverters = adapter.getMessageConverters();
        if (!CollectionUtils.isEmpty(messageConverters)) {
            for (HttpMessageConverter<?> messageConverter : messageConverters) {
                if (messageConverter instanceof MappingJackson2HttpMessageConverter) {
                    rebuildJacksonV2((MappingJackson2HttpMessageConverter) messageConverter);
                }

//                if (messageConverter instanceof MappingJacksonHttpMessageConverter) {
//                    rebuildJacksonV1((MappingJacksonHttpMessageConverter) messageConverter);
//                }
            }
        }

        /**
         * 處理form表單
         * form表單通過get方法請求,controller裏邊的方法中隻需設置一個接收的對象即可.
         */
        adapter.getMessageConverters().add(new FormHttpMessageConverter());

    }
 
開發者ID:glameyzhou,項目名稱:scaffold,代碼行數:22,代碼來源:WebConfig.java

示例2: findConverter

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private HttpMessageConverter<Object> findConverter(
		Class<? extends HttpMessageConverter<?>> selectedConverterType,
		MediaType mediaType) {
	HttpMessageConverter<Object> cached = (HttpMessageConverter<Object>) this.converterCache
			.get(mediaType);
	if (cached != null) {
		return cached;
	}
	for (RequestMappingHandlerAdapter handlerAdapter : this.handlerAdapters) {
		for (HttpMessageConverter<?> converter : handlerAdapter
				.getMessageConverters()) {
			if (selectedConverterType.isAssignableFrom(converter.getClass())
					&& converter.canWrite(EndpointResource.class, mediaType)) {
				this.converterCache.put(mediaType, converter);
				return (HttpMessageConverter<Object>) converter;
			}
		}
	}
	return null;
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:22,代碼來源:EndpointWebMvcHypermediaManagementContextConfiguration.java

示例3: customizedSupportedMediaTypes

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入方法依賴的package包/類
@PostConstruct
public void customizedSupportedMediaTypes() {
	if (this.beanFactory instanceof ListableBeanFactory) {
		Map<String, RequestMappingHandlerAdapter> handlerAdapters = ((ListableBeanFactory) this.beanFactory)
				.getBeansOfType(RequestMappingHandlerAdapter.class);
		for (Entry<String, RequestMappingHandlerAdapter> entry : handlerAdapters
				.entrySet()) {
			RequestMappingHandlerAdapter handlerAdapter = entry.getValue();
			for (HttpMessageConverter<?> converter : handlerAdapter
					.getMessageConverters()) {
				if (converter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) {
					((TypeConstrainedMappingJackson2HttpMessageConverter) converter)
							.setSupportedMediaTypes(
									Arrays.asList(MediaTypes.HAL_JSON,
											MediaType.APPLICATION_JSON));
				}
			}

		}
	}
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:22,代碼來源:HypermediaHttpMessageConverterConfiguration.java

示例4: customizationOfSupportedMediaTypesCanBeDisabled

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入方法依賴的package包/類
@Test
public void customizationOfSupportedMediaTypesCanBeDisabled() {
	this.context = new AnnotationConfigWebApplicationContext();
	this.context.setServletContext(new MockServletContext());
	this.context.register(BaseConfig.class);
	EnvironmentTestUtils.addEnvironment(this.context,
			"spring.hateoas.use-hal-as-default-json-media-type:false");
	this.context.refresh();
	RequestMappingHandlerAdapter handlerAdapter = this.context
			.getBean(RequestMappingHandlerAdapter.class);
	for (HttpMessageConverter<?> converter : handlerAdapter.getMessageConverters()) {
		if (converter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) {
			assertThat(converter.getSupportedMediaTypes())
					.containsExactly(MediaTypes.HAL_JSON);
		}
	}
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:18,代碼來源:HypermediaAutoConfigurationTests.java

示例5: findConverter

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private HttpMessageConverter<Object> findConverter(
		Class<? extends HttpMessageConverter<?>> selectedConverterType,
		MediaType mediaType) {
	if (this.converterCache.containsKey(mediaType)) {
		return (HttpMessageConverter<Object>) this.converterCache.get(mediaType);
	}
	for (RequestMappingHandlerAdapter handlerAdapter : this.handlerAdapters) {
		for (HttpMessageConverter<?> converter : handlerAdapter
				.getMessageConverters()) {
			if (selectedConverterType.isAssignableFrom(converter.getClass())
					&& converter.canWrite(EndpointResource.class, mediaType)) {
				this.converterCache.put(mediaType, converter);
				return (HttpMessageConverter<Object>) converter;
			}
		}
	}
	return null;
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:20,代碼來源:EndpointWebMvcHypermediaManagementContextConfiguration.java

示例6: customizationOfSupportedMediaTypesCanBeDisabled

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入方法依賴的package包/類
@Test
public void customizationOfSupportedMediaTypesCanBeDisabled() {
	this.context = new AnnotationConfigWebApplicationContext();
	this.context.setServletContext(new MockServletContext());
	this.context.register(BaseConfig.class);
	EnvironmentTestUtils.addEnvironment(this.context,
			"spring.hateoas.use-hal-as-default-json-media-type:false");
	this.context.refresh();
	RequestMappingHandlerAdapter handlerAdapter = this.context
			.getBean(RequestMappingHandlerAdapter.class);
	for (HttpMessageConverter<?> converter : handlerAdapter.getMessageConverters()) {
		if (converter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) {
			assertThat(converter.getSupportedMediaTypes(),
					contains(MediaTypes.HAL_JSON));
		}
	}
}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:18,代碼來源:HypermediaAutoConfigurationTests.java

示例7: postProcessAfterInitialization

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入方法依賴的package包/類
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
  if (bean instanceof RequestMappingHandlerAdapter) {
    RequestMappingHandlerAdapter adapter = (RequestMappingHandlerAdapter) bean;
    List<HttpMessageConverter<?>> converters = adapter.getMessageConverters();
    for (HttpMessageConverter<?> converter : converters) {
      if (converter instanceof MappingJackson2HttpMessageConverter) {
        MappingJackson2HttpMessageConverter jsonConverter = (MappingJackson2HttpMessageConverter) converter;

        ObjectMapper objectMapper = new ObjectMapper();
        SimpleModule module = new SimpleModule("Alfresco MVC Module", new Version(1, 0, 0, null, null, null));
        module.addSerializer(QName.class, new Jackson2QnameSerializer(serviceRegistry));
        module.addDeserializer(QName.class, new Jackson2QnameDeserializer(serviceRegistry));

        objectMapper.setDateFormat(new SimpleDateFormat(getDateFormat()));
        objectMapper.registerModule(module);

        jsonConverter.setObjectMapper(objectMapper);
      }
    }
  }
  return bean;
}
 
開發者ID:dgradecak,項目名稱:alfresco-mvc,代碼行數:23,代碼來源:Jackson2PostProcessor.java

示例8: requestMappingHandlerAdapter

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入方法依賴的package包/類
@Test
public void requestMappingHandlerAdapter() throws Exception {
	ApplicationContext context = initContext(WebConfig.class);
	RequestMappingHandlerAdapter adapter = context.getBean(RequestMappingHandlerAdapter.class);
	List<HttpMessageConverter<?>> converters = adapter.getMessageConverters();
	assertEquals(9, converters.size());
	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());
			}
		}
	}

	ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) adapter.getWebBindingInitializer();
	assertNotNull(initializer);

	ConversionService conversionService = initializer.getConversionService();
	assertNotNull(conversionService);
	assertTrue(conversionService instanceof FormattingConversionService);

	Validator validator = initializer.getValidator();
	assertNotNull(validator);
	assertTrue(validator instanceof LocalValidatorFactoryBean);

	DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(adapter);
	@SuppressWarnings("unchecked")
	List<Object> bodyAdvice = (List<Object>) fieldAccessor.getPropertyValue("requestResponseBodyAdvice");
	assertEquals(2, bodyAdvice.size());
	assertEquals(JsonViewRequestBodyAdvice.class, bodyAdvice.get(0).getClass());
	assertEquals(JsonViewResponseBodyAdvice.class, bodyAdvice.get(1).getClass());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:37,代碼來源:WebMvcConfigurationSupportTests.java

示例9: setRequestMappingHandlerAdapter

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入方法依賴的package包/類
@Autowired
void setRequestMappingHandlerAdapter(RequestMappingHandlerAdapter requestMappingHandlerAdapter) {
	for(HttpMessageConverter<?> converter:requestMappingHandlerAdapter.getMessageConverters()){
		if(converter instanceof MappingJackson2HttpMessageConverter){
			mappingJackson2HttpMessageConverter = converter;
			break;
		}
	}
    Assert.assertNotNull(this.mappingJackson2HttpMessageConverter);
}
 
開發者ID:simbest,項目名稱:simbest-cores,代碼行數:11,代碼來源:AbstractControllerTester.java

示例10: supportedMediaTypesOfTypeConstrainedConvertersIsCustomized

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入方法依賴的package包/類
@Test
public void supportedMediaTypesOfTypeConstrainedConvertersIsCustomized() {
	this.context = new AnnotationConfigWebApplicationContext();
	this.context.setServletContext(new MockServletContext());
	this.context.register(BaseConfig.class);
	this.context.refresh();
	RequestMappingHandlerAdapter handlerAdapter = this.context
			.getBean(RequestMappingHandlerAdapter.class);
	for (HttpMessageConverter<?> converter : handlerAdapter.getMessageConverters()) {
		if (converter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) {
			assertThat(converter.getSupportedMediaTypes())
					.contains(MediaType.APPLICATION_JSON, MediaTypes.HAL_JSON);
		}
	}
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:16,代碼來源:HypermediaAutoConfigurationTests.java

示例11: postProcessAfterInitialization

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入方法依賴的package包/類
@Override
public Object postProcessAfterInitialization( Object bean, String beanName )
    throws BeansException
{
    if ( !(bean instanceof RequestMappingHandlerAdapter) )
    {
        return bean;
    }

    RequestMappingHandlerAdapter handlerAdapter = (RequestMappingHandlerAdapter) bean;
    List<HttpMessageConverter<?>> converters = handlerAdapter.getMessageConverters();
    converters.add( 0, messageConverter );
    handlerAdapter.setMessageConverters( converters );
    return handlerAdapter;
}
 
開發者ID:dhis2,項目名稱:dhis2-core,代碼行數:16,代碼來源:MessageConverterAddingPostProcessor.java

示例12: supportedMediaTypesOfTypeConstrainedConvertersIsCustomized

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入方法依賴的package包/類
@Test
public void supportedMediaTypesOfTypeConstrainedConvertersIsCustomized() {
	this.context = new AnnotationConfigWebApplicationContext();
	this.context.setServletContext(new MockServletContext());
	this.context.register(BaseConfig.class);
	this.context.refresh();
	RequestMappingHandlerAdapter handlerAdapter = this.context
			.getBean(RequestMappingHandlerAdapter.class);
	for (HttpMessageConverter<?> converter : handlerAdapter.getMessageConverters()) {
		if (converter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) {
			assertThat(converter.getSupportedMediaTypes(), containsInAnyOrder(
					MediaType.APPLICATION_JSON, MediaTypes.HAL_JSON));
		}
	}
}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:16,代碼來源:HypermediaAutoConfigurationTests.java

示例13: 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

示例14: 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.getMessageConverters方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。