Search in sources :

Example 56 with HttpMessageConverter

use of org.springframework.http.converter.HttpMessageConverter in project spring-security-oauth by spring-projects.

the class OAuth2ErrorHandlerTests method testHandleMessageConversionExceptions.

@Test
public void testHandleMessageConversionExceptions() throws Exception {
    HttpMessageConverter<?> extractor = new HttpMessageConverter() {

        @Override
        public boolean canRead(Class clazz, MediaType mediaType) {
            return true;
        }

        @Override
        public boolean canWrite(Class clazz, MediaType mediaType) {
            return false;
        }

        @Override
        public List<MediaType> getSupportedMediaTypes() {
            return null;
        }

        @Override
        public Object read(Class clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
            throw new HttpMessageConversionException("error");
        }

        @Override
        public void write(Object o, MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
        }
    };
    ArrayList<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
    messageConverters.add(extractor);
    handler.setMessageConverters(messageConverters);
    HttpHeaders headers = new HttpHeaders();
    final String appSpecificBodyContent = "This user is not authorized";
    InputStream appSpecificErrorBody = new ByteArrayInputStream(appSpecificBodyContent.getBytes("UTF-8"));
    ClientHttpResponse response = new TestClientHttpResponse(headers, 401, appSpecificErrorBody);
    expected.expect(HttpClientErrorException.class);
    handler.handleError(response);
}
Also used : HttpInputMessage(org.springframework.http.HttpInputMessage) HttpHeaders(org.springframework.http.HttpHeaders) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ByteArrayInputStream(java.io.ByteArrayInputStream) HttpOutputMessage(org.springframework.http.HttpOutputMessage) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) MediaType(org.springframework.http.MediaType) HttpMessageConversionException(org.springframework.http.converter.HttpMessageConversionException) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) Test(org.junit.Test)

Example 57 with HttpMessageConverter

use of org.springframework.http.converter.HttpMessageConverter in project spring-sync by spring-projects.

the class DifferentialSynchronizationRegistrar method addArgumentResolvers.

@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
    List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
    messageConverters.add(new MappingJackson2HttpMessageConverter());
}
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)

Example 58 with HttpMessageConverter

use of org.springframework.http.converter.HttpMessageConverter in project spring-security-oauth by spring-projects.

the class Converters method getJaxbConverters.

public static Collection<HttpMessageConverter<?>> getJaxbConverters() {
    Collection<HttpMessageConverter<?>> converters = new ArrayList<>();
    converters.add(new JaxbOAuth2AccessTokenMessageConverter());
    converters.add(new JaxbOAuth2ExceptionMessageConverter());
    return converters;
}
Also used : JaxbOAuth2AccessTokenMessageConverter(org.springframework.security.oauth2.http.converter.jaxb.JaxbOAuth2AccessTokenMessageConverter) JaxbOAuth2ExceptionMessageConverter(org.springframework.security.oauth2.http.converter.jaxb.JaxbOAuth2ExceptionMessageConverter) ArrayList(java.util.ArrayList) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter)

Example 59 with HttpMessageConverter

use of org.springframework.http.converter.HttpMessageConverter in project spring-data-document-examples by spring-projects.

the class CouchDbConfig method restTemplate.

@Bean
public RestTemplate restTemplate() {
    RestTemplate restTemplate = new RestTemplate();
    List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
    //converters.add(new MappingJacksonHttpMessageConverter());
    converters.add(new CouchDbMappingJacksonHttpMessageConverter());
    restTemplate.setMessageConverters(converters);
    return restTemplate;
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) ArrayList(java.util.ArrayList) MappingJacksonHttpMessageConverter(org.springframework.http.converter.json.MappingJacksonHttpMessageConverter) CouchDbMappingJacksonHttpMessageConverter(com.springone.myrestaurants.web.CouchDbMappingJacksonHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) CouchDbMappingJacksonHttpMessageConverter(com.springone.myrestaurants.web.CouchDbMappingJacksonHttpMessageConverter) Bean(org.springframework.context.annotation.Bean)

Example 60 with HttpMessageConverter

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

the class RequestResponseBodyMethodProcessorMockTests method testResolveArgumentWithValidation.

private void testResolveArgumentWithValidation(SimpleBean simpleBean) throws Exception {
    MediaType contentType = MediaType.TEXT_PLAIN;
    servletRequest.addHeader("Content-Type", contentType.toString());
    servletRequest.setContent("payload".getBytes(StandardCharsets.UTF_8));
    @SuppressWarnings("unchecked") HttpMessageConverter<SimpleBean> beanConverter = mock(HttpMessageConverter.class);
    given(beanConverter.getSupportedMediaTypes()).willReturn(Collections.singletonList(MediaType.TEXT_PLAIN));
    given(beanConverter.canRead(SimpleBean.class, contentType)).willReturn(true);
    given(beanConverter.read(eq(SimpleBean.class), isA(HttpInputMessage.class))).willReturn(simpleBean);
    processor = new RequestResponseBodyMethodProcessor(Collections.<HttpMessageConverter<?>>singletonList(beanConverter));
    processor.resolveArgument(paramValidBean, mavContainer, webRequest, new ValidatingBinderFactory());
}
Also used : HttpInputMessage(org.springframework.http.HttpInputMessage) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) MediaType(org.springframework.http.MediaType)

Aggregations

HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)95 ArrayList (java.util.ArrayList)66 Test (org.junit.Test)62 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)59 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)51 ByteArrayHttpMessageConverter (org.springframework.http.converter.ByteArrayHttpMessageConverter)37 MappingJackson2XmlHttpMessageConverter (org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter)33 ResourceHttpMessageConverter (org.springframework.http.converter.ResourceHttpMessageConverter)32 AllEncompassingFormHttpMessageConverter (org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter)30 RestTemplate (org.springframework.web.client.RestTemplate)29 Method (java.lang.reflect.Method)25 MethodParameter (org.springframework.core.MethodParameter)25 HandlerMethod (org.springframework.web.method.HandlerMethod)24 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 HashMap (java.util.HashMap)13 MapPropertySource (org.springframework.core.env.MapPropertySource)13 StandardEnvironment (org.springframework.core.env.StandardEnvironment)13