本文整理匯總了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());
}
示例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));
}
}
}
示例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;
}
示例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());
}
示例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);
}
示例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;
}
示例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));
}
}
}
示例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);
}
示例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);
}