Search in sources :

Example 1 with ResourceHttpMessageConverter

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

the class RestTemplateBuilderTests method messageConvertersShouldReplaceExisting.

@Test
void messageConvertersShouldReplaceExisting() {
    RestTemplate template = this.builder.messageConverters(new ResourceHttpMessageConverter()).messageConverters(Collections.singleton(this.messageConverter)).build();
    assertThat(template.getMessageConverters()).containsOnly(this.messageConverter);
}
Also used : RestTemplate(cn.taketoday.web.client.RestTemplate) ResourceHttpMessageConverter(cn.taketoday.http.converter.ResourceHttpMessageConverter) Test(org.junit.jupiter.api.Test)

Example 2 with ResourceHttpMessageConverter

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

the class RestTemplateBuilderTests method additionalMessageConvertersShouldAddToExisting.

@Test
void additionalMessageConvertersShouldAddToExisting() {
    HttpMessageConverter<?> resourceConverter = new ResourceHttpMessageConverter();
    RestTemplate template = this.builder.messageConverters(resourceConverter).additionalMessageConverters(this.messageConverter).build();
    assertThat(template.getMessageConverters()).containsOnly(resourceConverter, this.messageConverter);
}
Also used : ResourceHttpMessageConverter(cn.taketoday.http.converter.ResourceHttpMessageConverter) RestTemplate(cn.taketoday.web.client.RestTemplate) Test(org.junit.jupiter.api.Test)

Example 3 with ResourceHttpMessageConverter

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

the class RestTemplateBuilderTests method additionalMessageConvertersShouldAddToExisting.

@Test
void additionalMessageConvertersShouldAddToExisting() {
    HttpMessageConverter<?> resourceConverter = new ResourceHttpMessageConverter();
    RestTemplate template = this.builder.messageConverters(resourceConverter).additionalMessageConverters(this.messageConverter).build();
    assertThat(template.getMessageConverters()).containsOnly(resourceConverter, this.messageConverter);
}
Also used : ResourceHttpMessageConverter(cn.taketoday.http.converter.ResourceHttpMessageConverter) RestTemplate(cn.taketoday.web.client.RestTemplate) Test(org.junit.jupiter.api.Test)

Example 4 with ResourceHttpMessageConverter

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

the class RequestResponseBodyMethodProcessorTests method handleReturnValueImage.

// SPR-12894
@Test
public void handleReturnValueImage() throws Throwable {
    this.servletRequest.addHeader("Accept", "*/*");
    Method method = getClass().getDeclaredMethod("getImage");
    MethodParameter returnType = new MethodParameter(method, -1);
    List<HttpMessageConverter<?>> converters = new ArrayList<>();
    converters.add(new ResourceHttpMessageConverter());
    RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
    ClassPathResource resource = new ClassPathResource("logo.jpg", getClass());
    processor.writeWithMessageConverters(resource, returnType, this.request);
    assertThat(this.servletResponse.getHeader("Content-Type")).isEqualTo("image/jpeg");
}
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) ResourceHttpMessageConverter(cn.taketoday.http.converter.ResourceHttpMessageConverter) Method(java.lang.reflect.Method) HandlerMethod(cn.taketoday.web.handler.method.HandlerMethod) MethodParameter(cn.taketoday.core.MethodParameter) ResolvableMethodParameter(cn.taketoday.web.handler.method.ResolvableMethodParameter) ClassPathResource(cn.taketoday.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 5 with ResourceHttpMessageConverter

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

the class RestTemplateBuilderTests method messageConvertersShouldReplaceExisting.

@Test
void messageConvertersShouldReplaceExisting() {
    RestTemplate template = this.builder.messageConverters(new ResourceHttpMessageConverter()).messageConverters(Collections.singleton(this.messageConverter)).build();
    assertThat(template.getMessageConverters()).containsOnly(this.messageConverter);
}
Also used : RestTemplate(cn.taketoday.web.client.RestTemplate) ResourceHttpMessageConverter(cn.taketoday.http.converter.ResourceHttpMessageConverter) Test(org.junit.jupiter.api.Test)

Aggregations

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