use of cn.taketoday.http.converter.ByteArrayHttpMessageConverter in project today-framework by TAKETODAY.
the class RequestResponseBodyMethodProcessorTests method handleReturnValueString.
@Test
public void handleReturnValueString() throws Throwable {
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new ByteArrayHttpMessageConverter());
converters.add(new StringHttpMessageConverter());
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
processor.handleReturnValue(request, handlerMethod, "Foo");
assertThat(servletResponse.getHeader("Content-Type")).isEqualTo("text/plain;charset=UTF-8");
assertThat(servletResponse.getContentAsString()).isEqualTo("Foo");
}
use of cn.taketoday.http.converter.ByteArrayHttpMessageConverter in project today-framework by TAKETODAY.
the class RequestResponseBodyMethodProcessorTests method handleReturnValueCharSequence.
// SPR-13423
@Test
public void handleReturnValueCharSequence() throws Throwable {
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new ByteArrayHttpMessageConverter());
converters.add(new StringHttpMessageConverter());
Method method = ResponseBodyController.class.getMethod("handleWithCharSequence");
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
processor.handleReturnValue(request, new HandlerMethod(this, method), new StringBuilder("Foo"));
assertThat(servletResponse.getHeader("Content-Type")).isEqualTo("text/plain;charset=UTF-8");
assertThat(servletResponse.getContentAsString()).isEqualTo("Foo");
}
use of cn.taketoday.http.converter.ByteArrayHttpMessageConverter in project today-framework by TAKETODAY.
the class RequestResponseBodyMethodProcessorTests method handleReturnValueStringAcceptCharset.
@Test
public void handleReturnValueStringAcceptCharset() throws Throwable {
this.servletRequest.addHeader("Accept", "text/plain;charset=UTF-8");
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new ByteArrayHttpMessageConverter());
converters.add(new StringHttpMessageConverter());
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
processor.writeWithMessageConverters("Foo", returnTypeString.getParameter(), request);
assertThat(servletResponse.getHeader("Content-Type")).isEqualTo("text/plain;charset=UTF-8");
}
use of cn.taketoday.http.converter.ByteArrayHttpMessageConverter in project today-framework by TAKETODAY.
the class HttpEntityMethodProcessorTests method handleReturnValueWithMalformedAcceptHeader.
// gh-24539
@Test
public void handleReturnValueWithMalformedAcceptHeader() throws Exception {
servletRequest.addHeader("Accept", "null");
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<String> returnValue = ResponseEntity.badRequest().body("Foo");
HttpEntityMethodProcessor processor = new HttpEntityMethodProcessor(converters, null);
processor.handleReturnValue(webRequest, new HandlerMethod(this, method), returnValue);
assertThat(servletResponse.getStatus()).isEqualTo(400);
assertThat(servletResponse.getHeader("Content-Type")).isNull();
assertThat(servletResponse.getContentAsString()).isEmpty();
}
use of cn.taketoday.http.converter.ByteArrayHttpMessageConverter in project today-framework by TAKETODAY.
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, null);
processor.handleReturnValue(webRequest, new HandlerMethod(this, method), returnValue);
assertThat(servletResponse.getHeader("Content-Type")).isEqualTo("text/plain;charset=ISO-8859-1");
assertThat(servletResponse.getContentAsString()).isEqualTo("Foo");
}
Aggregations