Search in sources :

Example 1 with StringHttpMessageConverter

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

the class HttpMessageConvertersAutoConfiguration method stringHttpMessageConverter.

@Component
@ConditionalOnMissingBean
public StringHttpMessageConverter stringHttpMessageConverter(Environment environment) {
    Charset charset;
    String encoding = environment.getProperty("server.encoding");
    if (encoding != null) {
        charset = Charset.forName(encoding);
    } else {
        charset = StandardCharsets.UTF_8;
    }
    StringHttpMessageConverter converter = new StringHttpMessageConverter(charset);
    converter.setWriteAcceptCharset(false);
    return converter;
}
Also used : Charset(java.nio.charset.Charset) StringHttpMessageConverter(cn.taketoday.http.converter.StringHttpMessageConverter) ConditionalOnMissingBean(cn.taketoday.context.condition.ConditionalOnMissingBean) Component(cn.taketoday.lang.Component)

Example 2 with StringHttpMessageConverter

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

the class RestTemplateBuilderTests method defaultMessageConvertersShouldClearExisting.

@Test
void defaultMessageConvertersShouldClearExisting() {
    RestTemplate template = new RestTemplate(Collections.singletonList(new StringHttpMessageConverter()));
    this.builder.additionalMessageConverters(this.messageConverter).defaultMessageConverters().configure(template);
    assertThat(template.getMessageConverters()).hasSameSizeAs(new RestTemplate().getMessageConverters());
}
Also used : RestTemplate(cn.taketoday.web.client.RestTemplate) StringHttpMessageConverter(cn.taketoday.http.converter.StringHttpMessageConverter) Test(org.junit.jupiter.api.Test)

Example 3 with StringHttpMessageConverter

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

the class RestTemplateBuilderTests method defaultMessageConvertersShouldSetDefaultList.

@Test
void defaultMessageConvertersShouldSetDefaultList() {
    RestTemplate template = new RestTemplate(Collections.singletonList(new StringHttpMessageConverter()));
    this.builder.defaultMessageConverters().configure(template);
    assertThat(template.getMessageConverters()).hasSameSizeAs(new RestTemplate().getMessageConverters());
}
Also used : RestTemplate(cn.taketoday.web.client.RestTemplate) StringHttpMessageConverter(cn.taketoday.http.converter.StringHttpMessageConverter) Test(org.junit.jupiter.api.Test)

Example 4 with StringHttpMessageConverter

use of cn.taketoday.http.converter.StringHttpMessageConverter 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 5 with StringHttpMessageConverter

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

the class ParameterResolvingRegistryTests method parameterResolvingRegistry.

@Test
void parameterResolvingRegistry() {
    assertThat(registry.getMessageConverters()).hasSize(3);
    ParameterResolvingRegistry registry1 = new ParameterResolvingRegistry(registry.getMessageConverters());
    assertThat(registry1.getMessageConverters()).isNotEmpty().hasSize(3);
    assertThat(registry1).isNotEqualTo(registry);
    registry.setMessageConverters(List.of(new StringHttpMessageConverter(StandardCharsets.US_ASCII)));
    assertThat(registry.getMessageConverters()).isNotEmpty().hasSize(1);
    assertThat(registry.toString()).isNotEmpty();
    registry.hashCode();
}
Also used : ParameterResolvingRegistry(cn.taketoday.web.bind.resolver.ParameterResolvingRegistry) StringHttpMessageConverter(cn.taketoday.http.converter.StringHttpMessageConverter) Test(org.junit.jupiter.api.Test)

Aggregations

StringHttpMessageConverter (cn.taketoday.http.converter.StringHttpMessageConverter)26 Test (org.junit.jupiter.api.Test)19 HttpMessageConverter (cn.taketoday.http.converter.HttpMessageConverter)16 MappingJackson2HttpMessageConverter (cn.taketoday.http.converter.json.MappingJackson2HttpMessageConverter)16 ArrayList (java.util.ArrayList)15 ByteArrayHttpMessageConverter (cn.taketoday.http.converter.ByteArrayHttpMessageConverter)12 AllEncompassingFormHttpMessageConverter (cn.taketoday.http.converter.AllEncompassingFormHttpMessageConverter)9 ResourceHttpMessageConverter (cn.taketoday.http.converter.ResourceHttpMessageConverter)9 MappingJackson2XmlHttpMessageConverter (cn.taketoday.http.converter.xml.MappingJackson2XmlHttpMessageConverter)9 RestTemplate (cn.taketoday.web.client.RestTemplate)8 HandlerMethod (cn.taketoday.web.handler.method.HandlerMethod)6 Method (java.lang.reflect.Method)6 MethodParameter (cn.taketoday.core.MethodParameter)5 ResolvableMethodParameter (cn.taketoday.web.handler.method.ResolvableMethodParameter)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 ConditionalOnMissingBean (cn.taketoday.context.condition.ConditionalOnMissingBean)3 MediaType (cn.taketoday.http.MediaType)3 Charset (java.nio.charset.Charset)3 Component (cn.taketoday.lang.Component)2 ContentNegotiationManagerFactoryBean (cn.taketoday.web.accept.ContentNegotiationManagerFactoryBean)2