Search in sources :

Example 1 with ByteArrayHttpMessageConverter

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");
}
Also used : HttpMessageConverter(cn.taketoday.http.converter.HttpMessageConverter) ByteArrayHttpMessageConverter(cn.taketoday.http.converter.ByteArrayHttpMessageConverter) StringHttpMessageConverter(cn.taketoday.http.converter.StringHttpMessageConverter) AllEncompassingFormHttpMessageConverter(cn.taketoday.http.converter.AllEncompassingFormHttpMessageConverter) MappingJackson2XmlHttpMessageConverter(cn.taketoday.http.converter.xml.MappingJackson2XmlHttpMessageConverter) MappingJackson2HttpMessageConverter(cn.taketoday.http.converter.json.MappingJackson2HttpMessageConverter) ResourceHttpMessageConverter(cn.taketoday.http.converter.ResourceHttpMessageConverter) ArrayList(java.util.ArrayList) ByteArrayHttpMessageConverter(cn.taketoday.http.converter.ByteArrayHttpMessageConverter) StringHttpMessageConverter(cn.taketoday.http.converter.StringHttpMessageConverter) Test(org.junit.jupiter.api.Test)

Example 2 with ByteArrayHttpMessageConverter

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");
}
Also used : HttpMessageConverter(cn.taketoday.http.converter.HttpMessageConverter) ByteArrayHttpMessageConverter(cn.taketoday.http.converter.ByteArrayHttpMessageConverter) StringHttpMessageConverter(cn.taketoday.http.converter.StringHttpMessageConverter) AllEncompassingFormHttpMessageConverter(cn.taketoday.http.converter.AllEncompassingFormHttpMessageConverter) MappingJackson2XmlHttpMessageConverter(cn.taketoday.http.converter.xml.MappingJackson2XmlHttpMessageConverter) MappingJackson2HttpMessageConverter(cn.taketoday.http.converter.json.MappingJackson2HttpMessageConverter) ResourceHttpMessageConverter(cn.taketoday.http.converter.ResourceHttpMessageConverter) ArrayList(java.util.ArrayList) ByteArrayHttpMessageConverter(cn.taketoday.http.converter.ByteArrayHttpMessageConverter) Method(java.lang.reflect.Method) HandlerMethod(cn.taketoday.web.handler.method.HandlerMethod) StringHttpMessageConverter(cn.taketoday.http.converter.StringHttpMessageConverter) HandlerMethod(cn.taketoday.web.handler.method.HandlerMethod) Test(org.junit.jupiter.api.Test)

Example 3 with ByteArrayHttpMessageConverter

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");
}
Also used : HttpMessageConverter(cn.taketoday.http.converter.HttpMessageConverter) ByteArrayHttpMessageConverter(cn.taketoday.http.converter.ByteArrayHttpMessageConverter) StringHttpMessageConverter(cn.taketoday.http.converter.StringHttpMessageConverter) AllEncompassingFormHttpMessageConverter(cn.taketoday.http.converter.AllEncompassingFormHttpMessageConverter) MappingJackson2XmlHttpMessageConverter(cn.taketoday.http.converter.xml.MappingJackson2XmlHttpMessageConverter) MappingJackson2HttpMessageConverter(cn.taketoday.http.converter.json.MappingJackson2HttpMessageConverter) ResourceHttpMessageConverter(cn.taketoday.http.converter.ResourceHttpMessageConverter) ArrayList(java.util.ArrayList) ByteArrayHttpMessageConverter(cn.taketoday.http.converter.ByteArrayHttpMessageConverter) StringHttpMessageConverter(cn.taketoday.http.converter.StringHttpMessageConverter) Test(org.junit.jupiter.api.Test)

Example 4 with ByteArrayHttpMessageConverter

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();
}
Also used : HttpMessageConverter(cn.taketoday.http.converter.HttpMessageConverter) ByteArrayHttpMessageConverter(cn.taketoday.http.converter.ByteArrayHttpMessageConverter) MappingJackson2HttpMessageConverter(cn.taketoday.http.converter.json.MappingJackson2HttpMessageConverter) StringHttpMessageConverter(cn.taketoday.http.converter.StringHttpMessageConverter) ArrayList(java.util.ArrayList) ByteArrayHttpMessageConverter(cn.taketoday.http.converter.ByteArrayHttpMessageConverter) Method(java.lang.reflect.Method) HandlerMethod(cn.taketoday.web.handler.method.HandlerMethod) MethodParameter(cn.taketoday.core.MethodParameter) ResolvableMethodParameter(cn.taketoday.web.handler.method.ResolvableMethodParameter) StringHttpMessageConverter(cn.taketoday.http.converter.StringHttpMessageConverter) HandlerMethod(cn.taketoday.web.handler.method.HandlerMethod) Test(org.junit.jupiter.api.Test)

Example 5 with ByteArrayHttpMessageConverter

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");
}
Also used : HttpMessageConverter(cn.taketoday.http.converter.HttpMessageConverter) ByteArrayHttpMessageConverter(cn.taketoday.http.converter.ByteArrayHttpMessageConverter) MappingJackson2HttpMessageConverter(cn.taketoday.http.converter.json.MappingJackson2HttpMessageConverter) StringHttpMessageConverter(cn.taketoday.http.converter.StringHttpMessageConverter) ArrayList(java.util.ArrayList) ByteArrayHttpMessageConverter(cn.taketoday.http.converter.ByteArrayHttpMessageConverter) Method(java.lang.reflect.Method) HandlerMethod(cn.taketoday.web.handler.method.HandlerMethod) MethodParameter(cn.taketoday.core.MethodParameter) ResolvableMethodParameter(cn.taketoday.web.handler.method.ResolvableMethodParameter) StringHttpMessageConverter(cn.taketoday.http.converter.StringHttpMessageConverter) HandlerMethod(cn.taketoday.web.handler.method.HandlerMethod) Test(org.junit.jupiter.api.Test)

Aggregations

ByteArrayHttpMessageConverter (cn.taketoday.http.converter.ByteArrayHttpMessageConverter)5 HttpMessageConverter (cn.taketoday.http.converter.HttpMessageConverter)5 StringHttpMessageConverter (cn.taketoday.http.converter.StringHttpMessageConverter)5 MappingJackson2HttpMessageConverter (cn.taketoday.http.converter.json.MappingJackson2HttpMessageConverter)5 ArrayList (java.util.ArrayList)5 Test (org.junit.jupiter.api.Test)5 AllEncompassingFormHttpMessageConverter (cn.taketoday.http.converter.AllEncompassingFormHttpMessageConverter)3 ResourceHttpMessageConverter (cn.taketoday.http.converter.ResourceHttpMessageConverter)3 MappingJackson2XmlHttpMessageConverter (cn.taketoday.http.converter.xml.MappingJackson2XmlHttpMessageConverter)3 HandlerMethod (cn.taketoday.web.handler.method.HandlerMethod)3 Method (java.lang.reflect.Method)3 MethodParameter (cn.taketoday.core.MethodParameter)2 ResolvableMethodParameter (cn.taketoday.web.handler.method.ResolvableMethodParameter)2