Search in sources :

Example 1 with ProtobufHttpMessageConverter

use of org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter in project tutorials by eugenp.

the class WebConfig method configureMessageConverters.

// 
@Override
public void configureMessageConverters(final List<HttpMessageConverter<?>> messageConverters) {
    final Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
    builder.indentOutput(true).dateFormat(new SimpleDateFormat("dd-MM-yyyy hh:mm"));
    messageConverters.add(new MappingJackson2HttpMessageConverter(builder.build()));
    messageConverters.add(new MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build()));
    messageConverters.add(createXmlHttpMessageConverter());
    // messageConverters.add(new MappingJackson2HttpMessageConverter());
    messageConverters.add(new ProtobufHttpMessageConverter());
    messageConverters.add(new KryoHttpMessageConverter());
    messageConverters.add(new StringHttpMessageConverter());
    super.configureMessageConverters(messageConverters);
}
Also used : ProtobufHttpMessageConverter(org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) Jackson2ObjectMapperBuilder(org.springframework.http.converter.json.Jackson2ObjectMapperBuilder) KryoHttpMessageConverter(org.baeldung.config.converter.KryoHttpMessageConverter) MappingJackson2XmlHttpMessageConverter(org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter) SimpleDateFormat(java.text.SimpleDateFormat) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter)

Example 2 with ProtobufHttpMessageConverter

use of org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter in project tutorials by eugenp.

the class SpringHttpMessageConvertersLiveTest method givenConsumingProtobuf_whenReadingTheFoo_thenCorrect.

@Test
public void givenConsumingProtobuf_whenReadingTheFoo_thenCorrect() {
    final String URI = BASE_URI + "foos/{id}";
    final RestTemplate restTemplate = new RestTemplate();
    restTemplate.setMessageConverters(Arrays.asList(new ProtobufHttpMessageConverter()));
    final HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(ProtobufHttpMessageConverter.PROTOBUF));
    final HttpEntity<String> entity = new HttpEntity<String>(headers);
    final ResponseEntity<FooProtos.Foo> response = restTemplate.exchange(URI, HttpMethod.GET, entity, FooProtos.Foo.class, "1");
    final FooProtos.Foo resource = response.getBody();
    assertThat(resource, notNullValue());
}
Also used : ProtobufHttpMessageConverter(org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter) HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) Foo(org.baeldung.web.dto.Foo) RestTemplate(org.springframework.web.client.RestTemplate) FooProtos(org.baeldung.web.dto.FooProtos) Test(org.junit.Test)

Aggregations

ProtobufHttpMessageConverter (org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter)2 SimpleDateFormat (java.text.SimpleDateFormat)1 KryoHttpMessageConverter (org.baeldung.config.converter.KryoHttpMessageConverter)1 Foo (org.baeldung.web.dto.Foo)1 FooProtos (org.baeldung.web.dto.FooProtos)1 Test (org.junit.Test)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)1 Jackson2ObjectMapperBuilder (org.springframework.http.converter.json.Jackson2ObjectMapperBuilder)1 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)1 MappingJackson2XmlHttpMessageConverter (org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter)1 RestTemplate (org.springframework.web.client.RestTemplate)1