use of org.springframework.http.converter.HttpMessageConverter in project spring-boot-admin by codecentric.
the class AdminServerWebConfigurationTest method jacksonMapperPresentFromDefault.
@Test
public void jacksonMapperPresentFromDefault() {
AdminServerWebConfiguration config = new AdminServerWebConfiguration(null, null, null, null);
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new MappingJackson2HttpMessageConverter());
config.extendMessageConverters(converters);
assertThat(converters, hasItem(isA(MappingJackson2HttpMessageConverter.class)));
assertThat(converters.size(), is(1));
}
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-security-oauth by spring-projects.
the class OAuth2AccessTokenSupport method setMessageConverters.
public void setMessageConverters(List<HttpMessageConverter<?>> messageConverters) {
this.messageConverters = new ArrayList<HttpMessageConverter<?>>(messageConverters);
this.messageConverters.add(new FormOAuth2AccessTokenMessageConverter());
this.messageConverters.add(new FormOAuth2ExceptionHttpMessageConverter());
}
use of org.springframework.http.converter.HttpMessageConverter in project spring-security-oauth by spring-projects.
the class DefaultOAuth2ExceptionRenderer method writeWithMessageConverters.
@SuppressWarnings({ "unchecked", "rawtypes" })
private void writeWithMessageConverters(Object returnValue, HttpInputMessage inputMessage, HttpOutputMessage outputMessage) throws IOException, HttpMediaTypeNotAcceptableException {
List<MediaType> acceptedMediaTypes = inputMessage.getHeaders().getAccept();
if (acceptedMediaTypes.isEmpty()) {
acceptedMediaTypes = Collections.singletonList(MediaType.ALL);
}
MediaType.sortByQualityValue(acceptedMediaTypes);
Class<?> returnValueType = returnValue.getClass();
List<MediaType> allSupportedMediaTypes = new ArrayList<MediaType>();
for (MediaType acceptedMediaType : acceptedMediaTypes) {
for (HttpMessageConverter messageConverter : messageConverters) {
if (messageConverter.canWrite(returnValueType, acceptedMediaType)) {
messageConverter.write(returnValue, acceptedMediaType, outputMessage);
if (logger.isDebugEnabled()) {
MediaType contentType = outputMessage.getHeaders().getContentType();
if (contentType == null) {
contentType = acceptedMediaType;
}
logger.debug("Written [" + returnValue + "] as \"" + contentType + "\" using [" + messageConverter + "]");
}
return;
}
}
}
for (HttpMessageConverter messageConverter : messageConverters) {
allSupportedMediaTypes.addAll(messageConverter.getSupportedMediaTypes());
}
throw new HttpMediaTypeNotAcceptableException(allSupportedMediaTypes);
}
use of org.springframework.http.converter.HttpMessageConverter in project spring-framework by spring-projects.
the class ServletInvocableHandlerMethodTests method wrapConcurrentResult_ResponseEntityNullReturnValue.
@Test
public void wrapConcurrentResult_ResponseEntityNullReturnValue() throws Exception {
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new StringHttpMessageConverter());
List<Object> advice = Collections.singletonList(mock(ResponseBodyAdvice.class));
HttpEntityMethodProcessor processor = new HttpEntityMethodProcessor(converters, null, advice);
this.returnValueHandlers.addHandler(processor);
ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new ResponseEntityHandler(), "handleDeferred");
handlerMethod = handlerMethod.wrapConcurrentResult(null);
handlerMethod.invokeAndHandle(this.webRequest, this.mavContainer);
assertEquals(200, this.response.getStatus());
assertEquals("", this.response.getContentAsString());
}
Aggregations