use of org.springframework.integration.http.converter.SerializingHttpMessageConverter in project spring-integration by spring-projects.
the class HttpInboundGatewayParserTests method checkFlow.
@Test
@DirtiesContext
public void checkFlow() throws Exception {
this.requests.subscribe(handlerExpecting(any(Message.class)));
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("GET");
request.addHeader("Accept", "application/my-serialized");
request.setParameter("foo", "bar");
MockHttpServletResponse response = new MockHttpServletResponse();
List<HttpMessageConverter<?>> converters = new ArrayList<>();
SerializingHttpMessageConverter serializingHttpMessageConverter = new SerializingHttpMessageConverter();
serializingHttpMessageConverter.setSupportedMediaTypes(Collections.singletonList(new MediaType("application", "my-serialized")));
converters.add(serializingHttpMessageConverter);
this.gateway.setMessageConverters(converters);
this.gateway.afterPropertiesSet();
this.gateway.start();
this.gateway.handleRequest(request, response);
assertThat(response.getStatus(), is(HttpServletResponse.SC_OK));
assertEquals(response.getContentType(), "application/my-serialized");
}
use of org.springframework.integration.http.converter.SerializingHttpMessageConverter in project spring-integration by spring-projects.
the class HttpRequestHandlingMessagingGatewayTests method serializableRequestBody.
@Test
public void serializableRequestBody() throws Exception {
QueueChannel channel = new QueueChannel();
HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(false);
gateway.setBeanFactory(mock(BeanFactory.class));
gateway.setRequestPayloadTypeClass(TestBean.class);
gateway.setRequestChannel(channel);
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
converters.add(new SerializingHttpMessageConverter());
gateway.setMessageConverters(converters);
gateway.afterPropertiesSet();
gateway.start();
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/test");
request.setContentType("application/x-java-serialized-object");
TestBean testBean = new TestBean();
testBean.setName("T. Bean");
testBean.setAge(42);
request.setContent(SerializationUtils.serialize(testBean));
MockHttpServletResponse response = new MockHttpServletResponse();
gateway.handleRequest(request, response);
byte[] bytes = response.getContentAsByteArray();
assertNotNull(bytes);
Message<?> message = channel.receive(0);
assertNotNull(message);
assertNotNull(message.getPayload());
assertEquals(TestBean.class, message.getPayload().getClass());
TestBean result = (TestBean) message.getPayload();
assertEquals("T. Bean", result.name);
assertEquals(84, result.age);
}
use of org.springframework.integration.http.converter.SerializingHttpMessageConverter in project spring-integration by spring-projects.
the class HttpRequestExecutingMessageHandlerTests method acceptHeaderForSerializableResponseMessageExchange.
@Test
public void acceptHeaderForSerializableResponseMessageExchange() throws Exception {
HttpRequestExecutingMessageHandler handler = new HttpRequestExecutingMessageHandler("http://www.springsource.org/spring-integration");
handler.setHttpMethod(HttpMethod.GET);
handler.setExtractPayload(false);
handler.setExpectedResponseType(GenericMessage.class);
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
converters.add(new SerializingHttpMessageConverter());
handler.setMessageConverters(converters);
setBeanFactory(handler);
handler.afterPropertiesSet();
RestTemplate restTemplate = TestUtils.getPropertyValue(handler, "restTemplate", RestTemplate.class);
HttpHeaders requestHeaders = setUpMocksToCaptureSentHeaders(restTemplate);
Message<?> message = MessageBuilder.withPayload("foo").build();
Exception exception = null;
try {
handler.handleMessage(message);
} catch (Exception e) {
exception = e;
}
assertTrue(requestHeaders.getAccept() != null);
assertTrue(requestHeaders.getAccept().size() > 0);
assertEquals("404 Not Found", exception.getCause().getMessage());
List<MediaType> accept = requestHeaders.getAccept();
assertTrue(accept != null && accept.size() > 0);
assertEquals("application", accept.get(0).getType());
assertEquals("x-java-serialized-object", accept.get(0).getSubtype());
}
use of org.springframework.integration.http.converter.SerializingHttpMessageConverter in project spring-integration by spring-projects.
the class HttpRequestExecutingMessageHandlerTests method acceptHeaderForSerializableResponse.
@Test
public void acceptHeaderForSerializableResponse() throws Exception {
HttpRequestExecutingMessageHandler handler = new HttpRequestExecutingMessageHandler("http://www.springsource.org/spring-integration");
handler.setHttpMethod(HttpMethod.GET);
handler.setExpectedResponseType(Foo.class);
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
converters.add(new SerializingHttpMessageConverter());
handler.setMessageConverters(converters);
setBeanFactory(handler);
handler.afterPropertiesSet();
RestTemplate restTemplate = TestUtils.getPropertyValue(handler, "restTemplate", RestTemplate.class);
HttpHeaders requestHeaders = setUpMocksToCaptureSentHeaders(restTemplate);
Message<?> message = MessageBuilder.withPayload("foo").build();
Exception exception = null;
try {
handler.handleMessage(message);
} catch (Exception e) {
exception = e;
}
assertTrue(requestHeaders.getAccept() != null);
assertTrue(requestHeaders.getAccept().size() > 0);
assertEquals("404 Not Found", exception.getCause().getMessage());
List<MediaType> accept = requestHeaders.getAccept();
assertTrue(accept != null && accept.size() > 0);
assertEquals("application", accept.get(0).getType());
assertEquals("x-java-serialized-object", accept.get(0).getSubtype());
}
Aggregations