use of org.springframework.http.converter.HttpMessageConverter in project geode by apache.
the class RestTestUtils method getRestTemplate.
public static RestTemplate getRestTemplate() {
if (restTemplate == null) {
restTemplate = new RestTemplate();
final List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
messageConverters.add(new ByteArrayHttpMessageConverter());
messageConverters.add(new ResourceHttpMessageConverter());
messageConverters.add(new StringHttpMessageConverter());
messageConverters.add(createMappingJackson2HttpMessageConverter());
restTemplate.setMessageConverters(messageConverters);
}
return restTemplate;
}
use of org.springframework.http.converter.HttpMessageConverter in project spring-framework by spring-projects.
the class XpathRequestMatchersIntegrationTests method setup.
@Before
public void setup() {
List<Person> composers = Arrays.asList(new Person("Johann Sebastian Bach").setSomeDouble(21), new Person("Johannes Brahms").setSomeDouble(.0025), new Person("Edvard Grieg").setSomeDouble(1.6035), new Person("Robert Schumann").setSomeDouble(Double.NaN));
List<Person> performers = Arrays.asList(new Person("Vladimir Ashkenazy").setSomeBoolean(false), new Person("Yehudi Menuhin").setSomeBoolean(true));
this.people = new PeopleWrapper(composers, performers);
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new Jaxb2RootElementHttpMessageConverter());
this.restTemplate = new RestTemplate();
this.restTemplate.setMessageConverters(converters);
this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
}
use of org.springframework.http.converter.HttpMessageConverter in project spring-boot by spring-projects.
the class RestTemplateAutoConfigurationTests method restTemplateWhenMessageConvertersDefinedShouldHaveMessageConverters.
@Test
public void restTemplateWhenMessageConvertersDefinedShouldHaveMessageConverters() {
load(HttpMessageConvertersAutoConfiguration.class, RestTemplateConfig.class);
assertThat(this.context.getBeansOfType(RestTemplate.class)).hasSize(1);
RestTemplate restTemplate = this.context.getBean(RestTemplate.class);
List<HttpMessageConverter<?>> converters = this.context.getBean(HttpMessageConverters.class).getConverters();
assertThat(restTemplate.getMessageConverters()).containsExactlyElementsOf(converters);
assertThat(restTemplate.getRequestFactory()).isInstanceOf(HttpComponentsClientHttpRequestFactory.class);
}
use of org.springframework.http.converter.HttpMessageConverter in project nikita-noark5-core by HiOA-ABI.
the class AppWebMvcConfiguration method extendMessageConverters.
/**
* Allows us to pretty print JSON/XML output. CLI tools like curl may not prettyprint for you
* so this allows us to format the api output so that any developer testing the system gets nicely
* formatted output.
* However the client should be using Accept: application/json or application/xml when connecting
*/
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
final Optional<HttpMessageConverter<?>> jsonConverterFound = converters.stream().filter(c -> c instanceof MappingJackson2HttpMessageConverter).findFirst();
if (jsonConverterFound.isPresent()) {
final AbstractJackson2HttpMessageConverter converter = (AbstractJackson2HttpMessageConverter) jsonConverterFound.get();
converter.getObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
// Convert timestamps to readable text strings
converter.getObjectMapper().configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
converter.getObjectMapper().enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
}
final Optional<HttpMessageConverter<?>> xmlConverterFound = converters.stream().filter(c -> c instanceof MappingJackson2XmlHttpMessageConverter).findFirst();
if (jsonConverterFound.isPresent()) {
final MappingJackson2XmlHttpMessageConverter converter = (MappingJackson2XmlHttpMessageConverter) xmlConverterFound.get();
converter.getObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
converter.getObjectMapper().enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
}
}
use of org.springframework.http.converter.HttpMessageConverter in project geode by apache.
the class RestInterfaceJUnitTest method createRestTemplate.
protected RestTemplate createRestTemplate() {
MappingJackson2HttpMessageConverter httpMessageConverter = new MappingJackson2HttpMessageConverter();
httpMessageConverter.setObjectMapper(getObjectMapper());
return setErrorHandler(new RestTemplate(Collections.<HttpMessageConverter<?>>singletonList(httpMessageConverter)));
}
Aggregations