Search in sources :

Example 1 with HttpMessageConverter

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));
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) ArrayList(java.util.ArrayList) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) Test(org.junit.Test)

Example 2 with HttpMessageConverter

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;
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) ArrayList(java.util.ArrayList) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) ResourceHttpMessageConverter(org.springframework.http.converter.ResourceHttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) ResourceHttpMessageConverter(org.springframework.http.converter.ResourceHttpMessageConverter) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter)

Example 3 with HttpMessageConverter

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());
}
Also used : FormHttpMessageConverter(org.springframework.http.converter.FormHttpMessageConverter) FormOAuth2ExceptionHttpMessageConverter(org.springframework.security.oauth2.http.converter.FormOAuth2ExceptionHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) FormOAuth2ExceptionHttpMessageConverter(org.springframework.security.oauth2.http.converter.FormOAuth2ExceptionHttpMessageConverter) FormOAuth2AccessTokenMessageConverter(org.springframework.security.oauth2.http.converter.FormOAuth2AccessTokenMessageConverter)

Example 4 with HttpMessageConverter

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);
}
Also used : HttpMediaTypeNotAcceptableException(org.springframework.web.HttpMediaTypeNotAcceptableException) ArrayList(java.util.ArrayList) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) MediaType(org.springframework.http.MediaType)

Example 5 with HttpMessageConverter

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());
}
Also used : ArrayList(java.util.ArrayList) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) Test(org.junit.Test)

Aggregations

HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)142 ArrayList (java.util.ArrayList)95 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)79 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)75 ByteArrayHttpMessageConverter (org.springframework.http.converter.ByteArrayHttpMessageConverter)47 Test (org.junit.jupiter.api.Test)46 RestTemplate (org.springframework.web.client.RestTemplate)38 ResourceHttpMessageConverter (org.springframework.http.converter.ResourceHttpMessageConverter)36 Test (org.junit.Test)35 AllEncompassingFormHttpMessageConverter (org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter)35 MappingJackson2XmlHttpMessageConverter (org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter)35 MethodParameter (org.springframework.core.MethodParameter)27 HandlerMethod (org.springframework.web.method.HandlerMethod)27 Method (java.lang.reflect.Method)25 MediaType (org.springframework.http.MediaType)15 HashMap (java.util.HashMap)14 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)14 SerDeHttpMessageConverter (com.kixeye.chassis.transport.http.SerDeHttpMessageConverter)13 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)13 URI (java.net.URI)13