Search in sources :

Example 1 with StringHttpMessageConverter

use of org.springframework.http.converter.StringHttpMessageConverter in project geode by apache.

the class RestTestUtils method getRestTemplate.

public static RestTemplate getRestTemplate() {
    if (restTemplate == null) {
        restTemplate = new RestTemplate();
        final List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
        messageConverters.add(new ByteArrayHttpMessageConverter());
        messageConverters.add(new ResourceHttpMessageConverter());
        messageConverters.add(new StringHttpMessageConverter());
        messageConverters.add(createMappingJackson2HttpMessageConverter());
        restTemplate.setMessageConverters(messageConverters);
    }
    return restTemplate;
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) ArrayList(java.util.ArrayList) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) ResourceHttpMessageConverter(org.springframework.http.converter.ResourceHttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) ResourceHttpMessageConverter(org.springframework.http.converter.ResourceHttpMessageConverter) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter)

Example 2 with StringHttpMessageConverter

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

the class ServletAnnotationControllerHandlerMethodTests method overlappingMessageConvertersRequestBody.

/*
	 * See SPR-6877
	 */
@Test
public void overlappingMessageConvertersRequestBody() throws ServletException, IOException {
    initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {

        @Override
        public void initialize(GenericWebApplicationContext wac) {
            RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
            List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
            messageConverters.add(new StringHttpMessageConverter());
            messageConverters.add(new SimpleMessageConverter(new MediaType("application", "json"), MediaType.ALL));
            adapterDef.getPropertyValues().add("messageConverters", messageConverters);
            wac.registerBeanDefinition("handlerAdapter", adapterDef);
        }
    }, RequestResponseBodyController.class);
    MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/something");
    request.setContent("Hello World".getBytes("UTF-8"));
    request.addHeader("Content-Type", "text/plain; charset=utf-8");
    request.addHeader("Accept", "application/json, text/javascript, */*");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertEquals("Invalid content-type", "application/json;charset=ISO-8859-1", response.getHeader("Content-Type"));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) MediaType(org.springframework.http.MediaType) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Test(org.junit.Test)

Example 3 with StringHttpMessageConverter

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

the class ServletInvocableHandlerMethodTests method wrapConcurrentResult_ResponseEntityNullReturnValue.

@Test
public void wrapConcurrentResult_ResponseEntityNullReturnValue() throws Exception {
    List<HttpMessageConverter<?>> converters = new ArrayList<>();
    converters.add(new StringHttpMessageConverter());
    List<Object> advice = Collections.singletonList(mock(ResponseBodyAdvice.class));
    HttpEntityMethodProcessor processor = new HttpEntityMethodProcessor(converters, null, advice);
    this.returnValueHandlers.addHandler(processor);
    ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new ResponseEntityHandler(), "handleDeferred");
    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 4 with StringHttpMessageConverter

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

the class ServletInvocableHandlerMethodTests method wrapConcurrentResult_ResponseEntityNullBody.

// SPR-12287
@Test
public void wrapConcurrentResult_ResponseEntityNullBody() throws Exception {
    List<HttpMessageConverter<?>> converters = new ArrayList<>();
    converters.add(new StringHttpMessageConverter());
    List<Object> advice = Collections.singletonList(mock(ResponseBodyAdvice.class));
    HttpEntityMethodProcessor processor = new HttpEntityMethodProcessor(converters, null, advice);
    this.returnValueHandlers.addHandler(processor);
    ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new ResponseEntityHandler(), "handleDeferred");
    handlerMethod = handlerMethod.wrapConcurrentResult(new ResponseEntity<>(HttpStatus.OK));
    handlerMethod.invokeAndHandle(this.webRequest, this.mavContainer);
    assertEquals(200, this.response.getStatus());
    assertEquals("", this.response.getContentAsString());
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) 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 5 with StringHttpMessageConverter

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

the class ServletInvocableHandlerMethodTests method wrapConcurrentResult_ResponseEntity.

@Test
public void wrapConcurrentResult_ResponseEntity() throws Exception {
    List<HttpMessageConverter<?>> converters = new ArrayList<>();
    converters.add(new StringHttpMessageConverter());
    this.returnValueHandlers.addHandler(new HttpEntityMethodProcessor(converters));
    ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new ResponseEntityHandler(), "handleDeferred");
    handlerMethod = handlerMethod.wrapConcurrentResult(new ResponseEntity<>("bar", HttpStatus.OK));
    handlerMethod.invokeAndHandle(this.webRequest, this.mavContainer);
    assertEquals("bar", this.response.getContentAsString());
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) 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)

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