Search in sources :

Example 1 with HttpMessageConverter

use of cn.taketoday.http.converter.HttpMessageConverter in project today-infrastructure by TAKETODAY.

the class HeaderRequestMatchersIntegrationTests method setup.

@BeforeEach
public void setup() {
    List<HttpMessageConverter<?>> converters = new ArrayList<>();
    converters.add(new StringHttpMessageConverter());
    converters.add(new MappingJackson2HttpMessageConverter());
    this.restTemplate = new RestTemplate();
    this.restTemplate.setMessageConverters(converters);
    this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
}
Also used : MappingJackson2HttpMessageConverter(cn.taketoday.http.converter.json.MappingJackson2HttpMessageConverter) HttpMessageConverter(cn.taketoday.http.converter.HttpMessageConverter) MappingJackson2HttpMessageConverter(cn.taketoday.http.converter.json.MappingJackson2HttpMessageConverter) StringHttpMessageConverter(cn.taketoday.http.converter.StringHttpMessageConverter) ArrayList(java.util.ArrayList) RestTemplate(cn.taketoday.web.client.RestTemplate) StringHttpMessageConverter(cn.taketoday.http.converter.StringHttpMessageConverter) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with HttpMessageConverter

use of cn.taketoday.http.converter.HttpMessageConverter in project today-framework by TAKETODAY.

the class HttpEntityMethodProcessorTests method jacksonTypeInfoList.

// SPR-12811
@Test
public void jacksonTypeInfoList() throws Exception {
    Method method = JacksonController.class.getMethod("handleList");
    HandlerMethod handlerMethod = new HandlerMethod(new JacksonController(), method);
    MethodParameter methodReturnType = handlerMethod.getReturnType();
    List<HttpMessageConverter<?>> converters = new ArrayList<>();
    converters.add(new MappingJackson2HttpMessageConverter());
    HttpEntityMethodProcessor processor = new HttpEntityMethodProcessor(converters, null);
    Object returnValue = new JacksonController().handleList();
    processor.handleReturnValue(webRequest, handlerMethod, returnValue);
    String content = this.servletResponse.getContentAsString();
    assertThat(content.contains("\"type\":\"foo\"")).isTrue();
    assertThat(content.contains("\"type\":\"bar\"")).isTrue();
}
Also used : MappingJackson2HttpMessageConverter(cn.taketoday.http.converter.json.MappingJackson2HttpMessageConverter) 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) Method(java.lang.reflect.Method) HandlerMethod(cn.taketoday.web.handler.method.HandlerMethod) MethodParameter(cn.taketoday.core.MethodParameter) ResolvableMethodParameter(cn.taketoday.web.handler.method.ResolvableMethodParameter) HandlerMethod(cn.taketoday.web.handler.method.HandlerMethod) Test(org.junit.jupiter.api.Test)

Example 3 with HttpMessageConverter

use of cn.taketoday.http.converter.HttpMessageConverter in project today-framework by TAKETODAY.

the class RequestResponseBodyMethodProcessorTests method jacksonJsonViewWithResponseBodyAndXmlMessageConverter.

// SPR-12149
@Test
public void jacksonJsonViewWithResponseBodyAndXmlMessageConverter() throws Throwable {
    Method method = JacksonController.class.getMethod("handleResponseBody");
    HandlerMethod handlerMethod = new HandlerMethod(new JacksonController(), method);
    MethodParameter methodReturnType = handlerMethod.getReturnType();
    List<HttpMessageConverter<?>> converters = new ArrayList<>();
    converters.add(new MappingJackson2XmlHttpMessageConverter());
    RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters, null, Collections.singletonList(new JsonViewResponseBodyAdvice()));
    Object returnValue = new JacksonController().handleResponseBody();
    processor.handleReturnValue(request, handlerMethod, returnValue);
    String content = this.servletResponse.getContentAsString();
    assertThat(content.contains("<withView1>with</withView1>")).isFalse();
    assertThat(content.contains("<withView2>with</withView2>")).isTrue();
    assertThat(content.contains("<withoutView>without</withoutView>")).isFalse();
}
Also used : MappingJackson2XmlHttpMessageConverter(cn.taketoday.http.converter.xml.MappingJackson2XmlHttpMessageConverter) 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) JsonViewResponseBodyAdvice(cn.taketoday.web.handler.method.JsonViewResponseBodyAdvice) Method(java.lang.reflect.Method) HandlerMethod(cn.taketoday.web.handler.method.HandlerMethod) MethodParameter(cn.taketoday.core.MethodParameter) ResolvableMethodParameter(cn.taketoday.web.handler.method.ResolvableMethodParameter) HandlerMethod(cn.taketoday.web.handler.method.HandlerMethod) Test(org.junit.jupiter.api.Test)

Example 4 with HttpMessageConverter

use of cn.taketoday.http.converter.HttpMessageConverter in project today-framework by TAKETODAY.

the class RequestResponseBodyMethodProcessorTests method supportsReturnTypeResponseBodyOnType.

@Test
public void supportsReturnTypeResponseBodyOnType() throws Throwable {
    Method method = ResponseBodyController.class.getMethod("handle");
    MethodParameter returnType = new MethodParameter(method, -1);
    List<HttpMessageConverter<?>> converters = new ArrayList<>();
    converters.add(new StringHttpMessageConverter());
    RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
    assertThat(processor.supportsHandlerMethod(new HandlerMethod(this, method))).as("Failed to recognize type-level @ResponseBody").isTrue();
}
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) 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 HttpMessageConverter

use of cn.taketoday.http.converter.HttpMessageConverter in project today-framework by TAKETODAY.

the class RequestResponseBodyMethodProcessorTests method jacksonSubType.

// SPR-13318
@Test
public void jacksonSubType() throws Throwable {
    Method method = JacksonController.class.getMethod("handleSubType");
    HandlerMethod handlerMethod = new HandlerMethod(new JacksonController(), method);
    MethodParameter methodReturnType = handlerMethod.getReturnType();
    List<HttpMessageConverter<?>> converters = new ArrayList<>();
    converters.add(new MappingJackson2HttpMessageConverter());
    RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
    Object returnValue = new JacksonController().handleSubType();
    processor.handleReturnValue(request, handlerMethod, returnValue);
    String content = this.servletResponse.getContentAsString();
    assertThat(content.contains("\"id\":123")).isTrue();
    assertThat(content.contains("\"name\":\"foo\"")).isTrue();
}
Also used : MappingJackson2HttpMessageConverter(cn.taketoday.http.converter.json.MappingJackson2HttpMessageConverter) 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) Method(java.lang.reflect.Method) HandlerMethod(cn.taketoday.web.handler.method.HandlerMethod) MethodParameter(cn.taketoday.core.MethodParameter) ResolvableMethodParameter(cn.taketoday.web.handler.method.ResolvableMethodParameter) HandlerMethod(cn.taketoday.web.handler.method.HandlerMethod) Test(org.junit.jupiter.api.Test)

Aggregations

HttpMessageConverter (cn.taketoday.http.converter.HttpMessageConverter)42 MappingJackson2HttpMessageConverter (cn.taketoday.http.converter.json.MappingJackson2HttpMessageConverter)41 StringHttpMessageConverter (cn.taketoday.http.converter.StringHttpMessageConverter)40 ArrayList (java.util.ArrayList)39 ByteArrayHttpMessageConverter (cn.taketoday.http.converter.ByteArrayHttpMessageConverter)36 Test (org.junit.jupiter.api.Test)36 AllEncompassingFormHttpMessageConverter (cn.taketoday.http.converter.AllEncompassingFormHttpMessageConverter)29 ResourceHttpMessageConverter (cn.taketoday.http.converter.ResourceHttpMessageConverter)29 MappingJackson2XmlHttpMessageConverter (cn.taketoday.http.converter.xml.MappingJackson2XmlHttpMessageConverter)29 HandlerMethod (cn.taketoday.web.handler.method.HandlerMethod)24 Method (java.lang.reflect.Method)24 ResolvableMethodParameter (cn.taketoday.web.handler.method.ResolvableMethodParameter)22 MethodParameter (cn.taketoday.core.MethodParameter)21 HttpEntity (cn.taketoday.http.HttpEntity)6 BeforeEach (org.junit.jupiter.api.BeforeEach)5 RestTemplate (cn.taketoday.web.client.RestTemplate)4 JsonViewRequestBodyAdvice (cn.taketoday.web.handler.method.JsonViewRequestBodyAdvice)4 JsonViewResponseBodyAdvice (cn.taketoday.web.handler.method.JsonViewResponseBodyAdvice)4 List (java.util.List)3 HttpMessageNotReadableException (cn.taketoday.http.converter.HttpMessageNotReadableException)2