Search in sources :

Example 6 with StringHttpMessageConverter

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

the class ServletInvocableHandlerMethodTests method wrapConcurrentResult_ResponseBodyEmitter.

@Test
public void wrapConcurrentResult_ResponseBodyEmitter() throws Exception {
    List<HttpMessageConverter<?>> converters = new ArrayList<>();
    converters.add(new StringHttpMessageConverter());
    this.returnValueHandlers.addHandler(new ResponseBodyEmitterReturnValueHandler(converters));
    ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new AsyncHandler(), "handleWithEmitter");
    handlerMethod = handlerMethod.wrapConcurrentResult(null);
    handlerMethod.invokeAndHandle(this.webRequest, this.mavContainer);
    assertEquals(200, this.response.getStatus());
    assertEquals("", this.response.getContentAsString());
}
Also used : ArrayList(java.util.ArrayList) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) Test(org.junit.Test)

Example 7 with StringHttpMessageConverter

use of org.springframework.http.converter.StringHttpMessageConverter in project java-function-invoker by projectriff.

the class JavaFunctionInvokerConfiguration method textPlainMessageConverter.

/**
 * Installs a message converter that supports {@literal text/plain} if the target type
 * is assignable from {@literal String}.
 *
 * <p>
 * This departs from the standard converter that is automatically registered, which
 * requires that the target type is exactly String (but accepts all content types).
 * This is necessary here because the signature of
 * {@link JavaFunctionInvokerController#invoke(Object)} accepts {@literal Object}.
 * </p>
 */
@Bean
public HttpMessageConverter<?> textPlainMessageConverter() {
    StringHttpMessageConverter converter = new StringHttpMessageConverter() {

        @Override
        public boolean supports(Class<?> clazz) {
            return clazz.isAssignableFrom(String.class);
        }
    };
    converter.setSupportedMediaTypes(Arrays.asList(MediaType.TEXT_PLAIN));
    return converter;
}
Also used : StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) Bean(org.springframework.context.annotation.Bean)

Example 8 with StringHttpMessageConverter

use of org.springframework.http.converter.StringHttpMessageConverter in project apollo by ctripcorp.

the class HttpMessageConverterConfiguration method messageConverters.

@Bean
public HttpMessageConverters messageConverters() {
    GsonHttpMessageConverter gsonHttpMessageConverter = new GsonHttpMessageConverter();
    gsonHttpMessageConverter.setGson(new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").create());
    final List<HttpMessageConverter<?>> converters = Lists.newArrayList(new ByteArrayHttpMessageConverter(), new StringHttpMessageConverter(), new AllEncompassingFormHttpMessageConverter(), gsonHttpMessageConverter);
    return new HttpMessageConverters() {

        @Override
        public List<HttpMessageConverter<?>> getConverters() {
            return converters;
        }
    };
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) AllEncompassingFormHttpMessageConverter(org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) GsonHttpMessageConverter(org.springframework.http.converter.json.GsonHttpMessageConverter) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) GsonHttpMessageConverter(org.springframework.http.converter.json.GsonHttpMessageConverter) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) AllEncompassingFormHttpMessageConverter(org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) HttpMessageConverters(org.springframework.boot.autoconfigure.http.HttpMessageConverters) Bean(org.springframework.context.annotation.Bean)

Example 9 with StringHttpMessageConverter

use of org.springframework.http.converter.StringHttpMessageConverter in project webofneeds by researchstudio-sat.

the class HttpService method init.

private void init(ClientHttpRequestFactory factory) {
    restTemplate = new RestTemplate(factory);
    restTemplate.getMessageConverters().add(new StringHttpMessageConverter(Charset.forName("UTF-8")));
    jsonHeaders = new HttpHeaders();
    jsonHeaders.add("Content-Type", "application/json");
    jsonHeaders.add("Accept", "*/*");
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter)

Example 10 with StringHttpMessageConverter

use of org.springframework.http.converter.StringHttpMessageConverter in project crnk-framework by crnk-project.

the class SpringParameterProvider method getHttpMessageConverters.

private List<HttpMessageConverter<?>> getHttpMessageConverters() {
    StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
    // see SPR-7316
    stringHttpMessageConverter.setWriteAcceptCharset(false);
    List<HttpMessageConverter<?>> converters = new ArrayList<>(4);
    converters.add(new ByteArrayHttpMessageConverter());
    converters.add(stringHttpMessageConverter);
    converters.add(new SourceHttpMessageConverter<>());
    converters.add(new AllEncompassingFormHttpMessageConverter());
    return converters;
}
Also used : AllEncompassingFormHttpMessageConverter(org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) SourceHttpMessageConverter(org.springframework.http.converter.xml.SourceHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) ArrayList(java.util.ArrayList) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) AllEncompassingFormHttpMessageConverter(org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter) 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