Search in sources :

Example 1 with AllEncompassingFormHttpMessageConverter

use of org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter in project spring-framework by spring-projects.

the class WebMvcConfigurationSupport method addDefaultHttpMessageConverters.

/**
	 * Adds a set of default HttpMessageConverter instances to the given list.
	 * Subclasses can call this method from {@link #configureMessageConverters(List)}.
	 * @param messageConverters the list to add the default message converters to
	 */
protected final void addDefaultHttpMessageConverters(List<HttpMessageConverter<?>> messageConverters) {
    StringHttpMessageConverter stringConverter = new StringHttpMessageConverter();
    stringConverter.setWriteAcceptCharset(false);
    messageConverters.add(new ByteArrayHttpMessageConverter());
    messageConverters.add(stringConverter);
    messageConverters.add(new ResourceHttpMessageConverter());
    messageConverters.add(new SourceHttpMessageConverter<>());
    messageConverters.add(new AllEncompassingFormHttpMessageConverter());
    if (romePresent) {
        messageConverters.add(new AtomFeedHttpMessageConverter());
        messageConverters.add(new RssChannelHttpMessageConverter());
    }
    if (jackson2XmlPresent) {
        ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.xml().applicationContext(this.applicationContext).build();
        messageConverters.add(new MappingJackson2XmlHttpMessageConverter(objectMapper));
    } else if (jaxb2Present) {
        messageConverters.add(new Jaxb2RootElementHttpMessageConverter());
    }
    if (jackson2Present) {
        ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().applicationContext(this.applicationContext).build();
        messageConverters.add(new MappingJackson2HttpMessageConverter(objectMapper));
    } else if (gsonPresent) {
        messageConverters.add(new GsonHttpMessageConverter());
    }
    if (jackson2SmilePresent) {
        ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.smile().applicationContext(this.applicationContext).build();
        messageConverters.add(new MappingJackson2SmileHttpMessageConverter(objectMapper));
    }
    if (jackson2CborPresent) {
        ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.cbor().applicationContext(this.applicationContext).build();
        messageConverters.add(new MappingJackson2CborHttpMessageConverter(objectMapper));
    }
}
Also used : Jaxb2RootElementHttpMessageConverter(org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) AtomFeedHttpMessageConverter(org.springframework.http.converter.feed.AtomFeedHttpMessageConverter) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) GsonHttpMessageConverter(org.springframework.http.converter.json.GsonHttpMessageConverter) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) MappingJackson2SmileHttpMessageConverter(org.springframework.http.converter.smile.MappingJackson2SmileHttpMessageConverter) MappingJackson2XmlHttpMessageConverter(org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter) RssChannelHttpMessageConverter(org.springframework.http.converter.feed.RssChannelHttpMessageConverter) ResourceHttpMessageConverter(org.springframework.http.converter.ResourceHttpMessageConverter) AllEncompassingFormHttpMessageConverter(org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter) MappingJackson2CborHttpMessageConverter(org.springframework.http.converter.cbor.MappingJackson2CborHttpMessageConverter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with AllEncompassingFormHttpMessageConverter

use of org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter in project spring-framework by spring-projects.

the class RequestPartIntegrationTests method setup.

@Before
public void setup() {
    ByteArrayHttpMessageConverter emptyBodyConverter = new ByteArrayHttpMessageConverter();
    emptyBodyConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON));
    List<HttpMessageConverter<?>> converters = new ArrayList<>(3);
    converters.add(emptyBodyConverter);
    converters.add(new ByteArrayHttpMessageConverter());
    converters.add(new ResourceHttpMessageConverter());
    converters.add(new MappingJackson2HttpMessageConverter());
    AllEncompassingFormHttpMessageConverter converter = new AllEncompassingFormHttpMessageConverter();
    converter.setPartConverters(converters);
    restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
    restTemplate.setMessageConverters(Collections.singletonList(converter));
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) ArrayList(java.util.ArrayList) AllEncompassingFormHttpMessageConverter(org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter) ResourceHttpMessageConverter(org.springframework.http.converter.ResourceHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) ResourceHttpMessageConverter(org.springframework.http.converter.ResourceHttpMessageConverter) RestTemplate(org.springframework.web.client.RestTemplate) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) AllEncompassingFormHttpMessageConverter(org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) Before(org.junit.Before)

Example 3 with AllEncompassingFormHttpMessageConverter

use of org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter in project spring-framework by spring-projects.

the class RequestResponseBodyMethodProcessorTests method resolveArgumentRawTypeFromParameterizedType.

@Test
public void resolveArgumentRawTypeFromParameterizedType() throws Exception {
    String content = "fruit=apple&vegetable=kale";
    this.servletRequest.setMethod("GET");
    this.servletRequest.setContent(content.getBytes("UTF-8"));
    this.servletRequest.setContentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE);
    List<HttpMessageConverter<?>> converters = new ArrayList<>();
    converters.add(new AllEncompassingFormHttpMessageConverter());
    RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
    @SuppressWarnings("unchecked") MultiValueMap<String, String> result = (MultiValueMap<String, String>) processor.resolveArgument(paramMultiValueMap, container, request, factory);
    assertNotNull(result);
    assertEquals("apple", result.getFirst("fruit"));
    assertEquals("kale", result.getFirst("vegetable"));
}
Also used : ArrayList(java.util.ArrayList) AllEncompassingFormHttpMessageConverter(org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter) ResourceHttpMessageConverter(org.springframework.http.converter.ResourceHttpMessageConverter) MappingJackson2XmlHttpMessageConverter(org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) AllEncompassingFormHttpMessageConverter(org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter) MultiValueMap(org.springframework.util.MultiValueMap) Test(org.junit.Test)

Aggregations

ByteArrayHttpMessageConverter (org.springframework.http.converter.ByteArrayHttpMessageConverter)3 ResourceHttpMessageConverter (org.springframework.http.converter.ResourceHttpMessageConverter)3 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)3 AllEncompassingFormHttpMessageConverter (org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter)3 ArrayList (java.util.ArrayList)2 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)2 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)2 MappingJackson2XmlHttpMessageConverter (org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Before (org.junit.Before)1 Test (org.junit.Test)1 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)1 MappingJackson2CborHttpMessageConverter (org.springframework.http.converter.cbor.MappingJackson2CborHttpMessageConverter)1 AtomFeedHttpMessageConverter (org.springframework.http.converter.feed.AtomFeedHttpMessageConverter)1 RssChannelHttpMessageConverter (org.springframework.http.converter.feed.RssChannelHttpMessageConverter)1 GsonHttpMessageConverter (org.springframework.http.converter.json.GsonHttpMessageConverter)1 MappingJackson2SmileHttpMessageConverter (org.springframework.http.converter.smile.MappingJackson2SmileHttpMessageConverter)1 Jaxb2RootElementHttpMessageConverter (org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter)1 MultiValueMap (org.springframework.util.MultiValueMap)1 RestTemplate (org.springframework.web.client.RestTemplate)1