use of org.springframework.http.converter.ByteArrayHttpMessageConverter in project spring-framework by spring-projects.
the class RequestResponseBodyMethodProcessorTests method handleReturnValueString.
@Test
public void handleReturnValueString() throws Exception {
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new ByteArrayHttpMessageConverter());
converters.add(new StringHttpMessageConverter());
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
processor.handleReturnValue("Foo", returnTypeString, container, request);
assertThat(servletResponse.getHeader("Content-Type")).isEqualTo("text/plain;charset=ISO-8859-1");
assertThat(servletResponse.getContentAsString()).isEqualTo("Foo");
}
use of org.springframework.http.converter.ByteArrayHttpMessageConverter in project spring-framework by spring-projects.
the class RequestResponseBodyMethodProcessorTests method handleReturnValueCharSequence.
// SPR-13423
@Test
public void handleReturnValueCharSequence() throws Exception {
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new ByteArrayHttpMessageConverter());
converters.add(new StringHttpMessageConverter());
Method method = ResponseBodyController.class.getMethod("handleWithCharSequence");
MethodParameter returnType = new MethodParameter(method, -1);
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
processor.handleReturnValue(new StringBuilder("Foo"), returnType, container, request);
assertThat(servletResponse.getHeader("Content-Type")).isEqualTo("text/plain;charset=ISO-8859-1");
assertThat(servletResponse.getContentAsString()).isEqualTo("Foo");
}
use of org.springframework.http.converter.ByteArrayHttpMessageConverter in project spring-framework by spring-projects.
the class RouterFunctionMapping method initMessageConverters.
/**
* Initializes a default set of {@linkplain HttpMessageConverter message converters}.
*/
private void initMessageConverters() {
List<HttpMessageConverter<?>> messageConverters = new ArrayList<>(4);
messageConverters.add(new ByteArrayHttpMessageConverter());
messageConverters.add(new StringHttpMessageConverter());
if (!shouldIgnoreXml) {
try {
messageConverters.add(new SourceHttpMessageConverter<>());
} catch (Error err) {
// Ignore when no TransformerFactory implementation is available
}
}
messageConverters.add(new AllEncompassingFormHttpMessageConverter());
this.messageConverters = messageConverters;
}
use of org.springframework.http.converter.ByteArrayHttpMessageConverter in project spring-framework by spring-projects.
the class HttpEntityMethodProcessorTests method handleReturnValueCharSequence.
// SPR-13423
@Test
public void handleReturnValueCharSequence() throws Exception {
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new ByteArrayHttpMessageConverter());
converters.add(new StringHttpMessageConverter());
Method method = getClass().getDeclaredMethod("handle");
MethodParameter returnType = new MethodParameter(method, -1);
ResponseEntity<StringBuilder> returnValue = ResponseEntity.ok(new StringBuilder("Foo"));
HttpEntityMethodProcessor processor = new HttpEntityMethodProcessor(converters);
processor.handleReturnValue(returnValue, returnType, mavContainer, webRequest);
assertThat(servletResponse.getHeader("Content-Type")).isEqualTo("text/plain;charset=ISO-8859-1");
assertThat(servletResponse.getContentAsString()).isEqualTo("Foo");
}
use of org.springframework.http.converter.ByteArrayHttpMessageConverter in project spring-cloud-gateway by spring-cloud.
the class ProxyResponseAutoConfiguration method proxyExchangeArgumentResolver.
@Bean
@ConditionalOnMissingBean
public ProxyExchangeArgumentResolver proxyExchangeArgumentResolver(Optional<RestTemplateBuilder> optional, ProxyProperties proxy) {
RestTemplateBuilder builder = optional.orElse(new RestTemplateBuilder());
RestTemplate template = builder.build();
template.setErrorHandler(new NoOpResponseErrorHandler());
template.getMessageConverters().add(new ByteArrayHttpMessageConverter() {
@Override
public boolean supports(Class<?> clazz) {
return true;
}
});
ProxyExchangeArgumentResolver resolver = new ProxyExchangeArgumentResolver(template);
resolver.setHeaders(proxy.convertHeaders());
// can be null
resolver.setSensitive(proxy.getSensitive());
return resolver;
}
Aggregations