Search in sources :

Example 41 with StringHttpMessageConverter

use of org.springframework.http.converter.StringHttpMessageConverter in project spring-boot by spring-projects.

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(org.springframework.web.client.RestTemplate) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) Test(org.junit.jupiter.api.Test)

Example 42 with StringHttpMessageConverter

use of org.springframework.http.converter.StringHttpMessageConverter in project spring-boot by spring-projects.

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(org.springframework.web.client.RestTemplate) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) Test(org.junit.jupiter.api.Test)

Example 43 with StringHttpMessageConverter

use of org.springframework.http.converter.StringHttpMessageConverter in project dhis2-core by dhis2.

the class MvcTestConfig method configureMessageConverters.

@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    Arrays.stream(Compression.values()).forEach(compression -> converters.add(new JsonMessageConverter(nodeService(), compression)));
    Arrays.stream(Compression.values()).forEach(compression -> converters.add(new XmlMessageConverter(nodeService(), compression)));
    converters.add(new StringHttpMessageConverter());
    converters.add(new ByteArrayHttpMessageConverter());
    converters.add(new FormHttpMessageConverter());
    converters.add(mappingJackson2HttpMessageConverter());
    converters.add(mappingJackson2XmlHttpMessageConverter());
}
Also used : FormHttpMessageConverter(org.springframework.http.converter.FormHttpMessageConverter) JsonMessageConverter(org.hisp.dhis.webapi.mvc.messageconverter.JsonMessageConverter) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) XmlMessageConverter(org.hisp.dhis.webapi.mvc.messageconverter.XmlMessageConverter) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter)

Example 44 with StringHttpMessageConverter

use of org.springframework.http.converter.StringHttpMessageConverter in project xm-ms-entity by xm-online.

the class TemplateUtil method getTemplate.

public static RestTemplate getTemplate(ClientHttpRequestInterceptor interceptor) {
    RestTemplate restTemplate = new RestTemplate();
    List<ClientHttpRequestInterceptor> ris = new ArrayList<>();
    ris.add(interceptor);
    restTemplate.setInterceptors(ris);
    SimpleClientHttpRequestFactory httpFactory = new SimpleClientHttpRequestFactory();
    httpFactory.setOutputStreaming(false);
    restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(httpFactory));
    restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(Charset.forName("UTF-8")));
    return restTemplate;
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) RestTemplate(org.springframework.web.client.RestTemplate) ArrayList(java.util.ArrayList) ClientHttpRequestInterceptor(org.springframework.http.client.ClientHttpRequestInterceptor) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) BufferingClientHttpRequestFactory(org.springframework.http.client.BufferingClientHttpRequestFactory)

Example 45 with StringHttpMessageConverter

use of org.springframework.http.converter.StringHttpMessageConverter in project webapp by elimu-ai.

the class MarkupValidationHelper method verifyNoMarkupError.

/**
 * Verifies that the HTML is well formed.
 *
 * @param markup The HTML markup to be tested.
 */
public static void verifyNoMarkupError(String markup) {
    // List<MediaType> supportedMediaTypes = new ArrayList<>();
    List<MediaType> supportedMediaTypes = new ArrayList<MediaType>();
    supportedMediaTypes.add(new MediaType("text", "html", Charset.forName("UTF-8")));
    StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
    stringHttpMessageConverter.setSupportedMediaTypes(supportedMediaTypes);
    // List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
    List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
    messageConverters.add(stringHttpMessageConverter);
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.setMessageConverters(messageConverters);
    String result = restTemplate.postForObject(URL, markup, String.class);
    System.out.println("result: " + result);
    assertTrue("The document is not valid HTML5: " + markup, result.contains("The document is valid HTML5"));
}
Also used : ArrayList(java.util.ArrayList) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) RestTemplate(org.springframework.web.client.RestTemplate) MediaType(org.springframework.http.MediaType) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter)

Aggregations

StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)91 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)46 ArrayList (java.util.ArrayList)38 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)25 ByteArrayHttpMessageConverter (org.springframework.http.converter.ByteArrayHttpMessageConverter)24 RestTemplate (org.springframework.web.client.RestTemplate)23 Test (org.junit.jupiter.api.Test)21 ResourceHttpMessageConverter (org.springframework.http.converter.ResourceHttpMessageConverter)18 Test (org.junit.Test)16 AllEncompassingFormHttpMessageConverter (org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter)16 MappingJackson2XmlHttpMessageConverter (org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter)11 MediaType (org.springframework.http.MediaType)9 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)9 MockHttpServletResponse (org.springframework.web.testfixture.servlet.MockHttpServletResponse)9 SerDeHttpMessageConverter (com.kixeye.chassis.transport.http.SerDeHttpMessageConverter)7 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)7 URI (java.net.URI)7 HashMap (java.util.HashMap)7 Before (org.junit.Before)7 MethodParameter (org.springframework.core.MethodParameter)7