Search in sources :

Example 21 with ByteArrayHttpMessageConverter

use of org.springframework.http.converter.ByteArrayHttpMessageConverter in project snow-owl by b2ihealthcare.

the class SnowOwlApiConfig method configureMessageConverters.

@Override
public void configureMessageConverters(final List<HttpMessageConverter<?>> converters) {
    final StringHttpMessageConverter stringConverter = new StringHttpMessageConverter(Charsets.UTF_8);
    stringConverter.setWriteAcceptCharset(false);
    converters.add(stringConverter);
    converters.add(new ByteArrayHttpMessageConverter());
    converters.add(new ResourceHttpMessageConverter());
    converters.add(new CsvMessageConverter());
    // XXX using null value here as Spring calls a proxied method anyway which returns an already configured instance, see mapping2JacksonHttpMessageConverter Bean method
    converters.add(mapping2JacksonHttpMessageConverter(null));
}
Also used : ResourceHttpMessageConverter(org.springframework.http.converter.ResourceHttpMessageConverter) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) CsvMessageConverter(com.b2international.snowowl.core.rest.util.CsvMessageConverter)

Example 22 with ByteArrayHttpMessageConverter

use of org.springframework.http.converter.ByteArrayHttpMessageConverter in project littlefisher-system by littlefishercoder.

the class WebSpringMvcConfig method configureMessageConverters.

/**
 * Description: 消息转换器配置
 *
 * @param converters converters
 */
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    MappingJackson2HttpMessageConverter jacksonConverter = new MappingJackson2HttpMessageConverter();
    ObjectMapper om = jacksonConverter.getObjectMapper();
    om.setDateFormat(new SimpleDateFormat(DateUtil.DATETIME_FORMAT_1));
    om.setLocale(Locale.CHINA);
    om.setTimeZone(TimeZone.getTimeZone("GMT+8"));
    List<MediaType> mediaTypeList = Lists.newArrayList();
    mediaTypeList.add(new MediaType(MediaType.APPLICATION_JSON, Charsets.UTF_8));
    mediaTypeList.add(new MediaType(MediaType.TEXT_HTML, Charsets.UTF_8));
    jacksonConverter.setSupportedMediaTypes(mediaTypeList);
    StringHttpMessageConverter stringConverter = new StringHttpMessageConverter(Charsets.UTF_8);
    stringConverter.setWriteAcceptCharset(false);
    // 保持以下顺序
    // "application/json" "application/*+json"
    converters.add(jacksonConverter);
    // "application/xml" "text/xml" "application/*+xml"
    converters.add(new Jaxb2RootElementHttpMessageConverter());
    // "application/xml" "text/xml" "application/*+xml"
    converters.add(new SourceHttpMessageConverter<>());
    // "application/x-www-form-urlencoded" "multipart/form-data"
    converters.add(new AllEncompassingFormHttpMessageConverter());
    // "application/octet-stream" "*/*"
    converters.add(new ByteArrayHttpMessageConverter());
    // "text/plain" "*/*"
    converters.add(stringConverter);
    // "*/*"
    converters.add(new ResourceHttpMessageConverter());
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) Jaxb2RootElementHttpMessageConverter(org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter) ResourceHttpMessageConverter(org.springframework.http.converter.ResourceHttpMessageConverter) MediaType(org.springframework.http.MediaType) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) AllEncompassingFormHttpMessageConverter(org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter) SimpleDateFormat(java.text.SimpleDateFormat) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter)

Example 23 with ByteArrayHttpMessageConverter

use of org.springframework.http.converter.ByteArrayHttpMessageConverter in project ma-core-public by infiniteautomation.

the class MangoRestSpringConfiguration method configureMessageConverters.

/**
 * Configure the Message Converters for the API for now only JSON
 */
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    converters.add(new ResourceHttpMessageConverter());
    converters.add(new MappingJackson2HttpMessageConverter(getObjectMapper()));
    converters.add(new CsvMessageConverter());
    converters.add(new CsvRowMessageConverter());
    converters.add(new CsvQueryArrayStreamMessageConverter());
    converters.add(new CsvDataPageQueryStreamMessageConverter());
    converters.add(new ByteArrayHttpMessageConverter());
    converters.add(new HtmlHttpMessageConverter());
    converters.add(new SerotoninJsonMessageConverter());
    converters.add(new ExceptionCsvMessageConverter());
    // Now is a good time to register our Sero Json Converter
    Common.JSON_CONTEXT.addConverter(new AbstractRestModelConverter(), AbstractRestModel.class);
}
Also used : CsvDataPageQueryStreamMessageConverter(com.serotonin.m2m2.web.mvc.rest.v1.converters.CsvDataPageQueryStreamMessageConverter) SerotoninJsonMessageConverter(com.serotonin.m2m2.web.mvc.rest.v1.converters.SerotoninJsonMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) CsvQueryArrayStreamMessageConverter(com.serotonin.m2m2.web.mvc.rest.v1.converters.CsvQueryArrayStreamMessageConverter) CsvRowMessageConverter(com.serotonin.m2m2.web.mvc.rest.v1.converters.CsvRowMessageConverter) HtmlHttpMessageConverter(com.serotonin.m2m2.web.mvc.rest.v1.converters.HtmlHttpMessageConverter) ResourceHttpMessageConverter(org.springframework.http.converter.ResourceHttpMessageConverter) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) AbstractRestModelConverter(com.serotonin.m2m2.util.AbstractRestModelConverter) ExceptionCsvMessageConverter(com.infiniteautomation.mango.rest.v2.converters.ExceptionCsvMessageConverter) CsvMessageConverter(com.serotonin.m2m2.web.mvc.rest.v1.converters.CsvMessageConverter) ExceptionCsvMessageConverter(com.infiniteautomation.mango.rest.v2.converters.ExceptionCsvMessageConverter)

Example 24 with ByteArrayHttpMessageConverter

use of org.springframework.http.converter.ByteArrayHttpMessageConverter in project syndesis by syndesisio.

the class BaseITCase method setRestTemplate.

@Autowired
public void setRestTemplate(TestRestTemplate testRestTemplate) {
    List<HttpMessageConverter<?>> messageConverters = testRestTemplate.getRestTemplate().getMessageConverters();
    messageConverters.add(0, new YamlJackson2HttpMessageConverter());
    messageConverters.add(0, new JsonJackson2HttpMessageConverter());
    messageConverters.add(0, new ByteArrayHttpMessageConverter());
    this.restTemplate = testRestTemplate;
}
Also used : AbstractJackson2HttpMessageConverter(org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) Autowired(org.springframework.beans.factory.annotation.Autowired)

Example 25 with ByteArrayHttpMessageConverter

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

the class RequestPartIntegrationTests method standardMultipartResolverWithEncodedFileName.

// SPR-13319
@Test
public void standardMultipartResolverWithEncodedFileName() throws Exception {
    String boundaryText = MimeTypeUtils.generateMultipartBoundaryString();
    Map<String, String> params = Collections.singletonMap("boundary", boundaryText);
    String content = "--" + boundaryText + "\r\n" + "Content-Disposition: form-data; name=\"file\"; filename*=\"utf-8''%C3%A9l%C3%A8ve.txt\"\r\n" + "Content-Type: text/plain\r\n" + "Content-Length: 7\r\n" + "\r\n" + "content\r\n" + "--" + boundaryText + "--";
    RequestEntity<byte[]> requestEntity = RequestEntity.post(new URI(baseUrl + "/standard-resolver/spr13319")).contentType(new MediaType(MediaType.MULTIPART_FORM_DATA, params)).body(content.getBytes(StandardCharsets.US_ASCII));
    ByteArrayHttpMessageConverter converter = new ByteArrayHttpMessageConverter();
    converter.setSupportedMediaTypes(Collections.singletonList(MediaType.MULTIPART_FORM_DATA));
    this.restTemplate.setMessageConverters(Collections.singletonList(converter));
    ResponseEntity<Void> responseEntity = restTemplate.exchange(requestEntity, Void.class);
    assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
}
Also used : MediaType(org.springframework.http.MediaType) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Aggregations

ByteArrayHttpMessageConverter (org.springframework.http.converter.ByteArrayHttpMessageConverter)33 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)17 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)13 ResourceHttpMessageConverter (org.springframework.http.converter.ResourceHttpMessageConverter)12 ArrayList (java.util.ArrayList)11 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)11 AllEncompassingFormHttpMessageConverter (org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter)11 RestTemplate (org.springframework.web.client.RestTemplate)7 Test (org.junit.jupiter.api.Test)6 Test (org.junit.Test)5 Bean (org.springframework.context.annotation.Bean)5 MediaType (org.springframework.http.MediaType)4 Jaxb2RootElementHttpMessageConverter (org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter)4 MappingJackson2XmlHttpMessageConverter (org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter)4 Method (java.lang.reflect.Method)3 MethodParameter (org.springframework.core.MethodParameter)3 GsonHttpMessageConverter (org.springframework.http.converter.json.GsonHttpMessageConverter)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2