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);
}
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());
}
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;
}
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;
}
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());
}
Aggregations