INT-2689 - SI builds without warnings (Except Spring Integration HTTP)

* Ensure that no deprecation warnings occur
* Spring Integration builds with all tests successfully for Spring 3.1.2.RELEASE and 3.0.7.RELEASE (Except Spring Integration HTTP)

For reference see: https://jira.springsource.org/browse/INT-2689

INT-2694 - Fix Http Test Failures with Spring 3.0

As part of INT-2689, fix Http Test Failures in the Spring Integration Http Module when using Spring 3.0.7.RELEASE
For reference see: https://jira.springsource.org/browse/INT-2694
This commit is contained in:
Gunnar Hillert
2012-07-30 15:34:47 -04:00
committed by Oleg Zhurakousky
parent 19c53ed9e9
commit 57bc67b8fb
27 changed files with 283 additions and 168 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -75,6 +75,7 @@ import org.springframework.web.client.RestTemplate;
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Gary Russell
* @author Gunnar Hillert
* @since 2.0
*/
public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMessageHandler {
@@ -289,17 +290,36 @@ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMe
}
Assert.isInstanceOf(GenericConversionService.class, conversionService);
GenericConversionService gConversionService = (GenericConversionService) conversionService;
gConversionService.addConverter(new Converter<Class<?>, String>() {
public String convert(Class<?> source) {
return source.getName();
}
});
gConversionService.addConverter(new ClassToStringConverter());
gConversionService.addConverter(new ObjectToStringConverter());
if (conversionService != null) {
this.evaluationContext.setTypeConverter(new StandardTypeConverter(gConversionService));
}
}
private class ClassToStringConverter implements Converter<Class<?>, String> {
public String convert(Class<?> source) {
return source.getName();
}
}
/**
* Spring 3.0.7.RELEASE unfortunately does not trigger the ClassToStringConverter.
* Therefore, this converter will also test for Class instances and do a
* respective type conversion.
*
*/
private class ObjectToStringConverter implements Converter<Object, String> {
public String convert(Object source) {
if (source instanceof Class) {
return ((Class<?>) source).getName();
}
return source.toString();
}
}
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
String uri = this.uriExpression.getValue(this.evaluationContext, requestMessage, String.class);

View File

@@ -57,6 +57,7 @@ import org.springframework.util.MultiValueMap;
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Gary Russell
* @author Gunnar Hillert
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@@ -73,21 +74,21 @@ public class HttpInboundChannelAdapterParserTests {
@Autowired
private HttpRequestHandlingMessagingGateway putOrDeleteAdapter;
@Autowired
private HttpRequestHandlingMessagingGateway withMappedHeaders;
@Autowired
private HttpRequestHandlingMessagingGateway inboundAdapterWithExpressions;
@Autowired
@Qualifier("/fname/{blah}/lname/{boo}")
private HttpRequestHandlingMessagingGateway inboundAdapterWithNameAndExpressions;
@Autowired
@Qualifier("/fname/{f}/lname/{l}")
private HttpRequestHandlingMessagingGateway inboundAdapterWithNameNoPath;
@Autowired
private HttpRequestHandlingController inboundController;
@@ -117,12 +118,12 @@ public class HttpInboundChannelAdapterParserTests {
assertEquals("bar", map.getFirst("foo"));
assertNotNull(TestUtils.getPropertyValue(defaultAdapter, "errorChannel"));
}
@Test
public void getRequestWithHeaders() throws Exception {
DefaultHttpHeaderMapper headerMapper =
DefaultHttpHeaderMapper headerMapper =
(DefaultHttpHeaderMapper) TestUtils.getPropertyValue(withMappedHeaders, "headerMapper");
HttpHeaders headers = new HttpHeaders();
headers.set("foo", "foo");
headers.set("bar", "bar");
@@ -132,7 +133,7 @@ public class HttpInboundChannelAdapterParserTests {
assertEquals("foo", map.get("foo"));
assertEquals("bar", map.get("bar"));
}
@Test
// INT-1677
public void withExpressions() throws Exception {
@@ -142,7 +143,7 @@ public class HttpInboundChannelAdapterParserTests {
request.setParameter("foo", "bar");
request.setContent("hello".getBytes());
request.setRequestURI("/fname/bill/lname/clinton");
MockHttpServletResponse response = new MockHttpServletResponse();
inboundAdapterWithExpressions.handleRequest(request, response);
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
@@ -163,7 +164,7 @@ public class HttpInboundChannelAdapterParserTests {
request.setParameter("foo", "bar");
request.setContent("hello".getBytes());
request.setRequestURI("/fname/bill/lname/clinton");
MockHttpServletResponse response = new MockHttpServletResponse();
inboundAdapterWithNameAndExpressions.handleRequest(request, response);
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
@@ -174,7 +175,7 @@ public class HttpInboundChannelAdapterParserTests {
assertEquals("bill", payload);
assertEquals("clinton", message.getHeaders().get("lname"));
}
@Test(expected=SpelEvaluationException.class)
// INT-1677
public void withNameAndExpressionsNoPath() throws Exception {
@@ -184,7 +185,7 @@ public class HttpInboundChannelAdapterParserTests {
request.setParameter("foo", "bar");
request.setContent("hello".getBytes());
request.setRequestURI("/fname/bill/lname/clinton");
MockHttpServletResponse response = new MockHttpServletResponse();
inboundAdapterWithNameNoPath.handleRequest(request, response);
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
@@ -195,8 +196,8 @@ public class HttpInboundChannelAdapterParserTests {
assertEquals("hello", payload); // default payload
assertNull(message.getHeaders().get("lname"));
}
@Test
public void getRequestNotAllowed() throws Exception {
@@ -215,7 +216,11 @@ public class HttpInboundChannelAdapterParserTests {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.setContent("test".getBytes());
request.setContentType("text/plain");
//request.setContentType("text/plain"); //Works in Spring 3.1.2.RELEASE but not in Spring 3.0.7.RELEASE
//Instead use:
request.addHeader("Content-Type", "text/plain");
MockHttpServletResponse response = new MockHttpServletResponse();
postOnlyAdapter.handleRequest(request, response);
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
@@ -237,7 +242,11 @@ public class HttpInboundChannelAdapterParserTests {
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
new ObjectOutputStream(byteStream).writeObject(obj);
request.setContent(byteStream.toByteArray());
request.setContentType("application/x-java-serialized-object");
// //request.setContentType("application/x-java-serialized-object"); //Works in Spring 3.1.2.RELEASE but not in Spring 3.0.7.RELEASE
// //Instead use:
request.addHeader("Content-Type", "application/x-java-serialized-object");
MockHttpServletResponse response = new MockHttpServletResponse();
postOnlyAdapter.handleRequest(request, response);
assertEquals(HttpServletResponse.SC_OK, response.getStatus());

View File

@@ -59,6 +59,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Iwein Fuld
* @author Oleg Zhurakousky
* @author Gary Russell
* @author Gunnar Hillert
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@@ -109,10 +110,14 @@ public class HttpInboundGatewayParserTests {
request.setMethod("GET");
request.addHeader("Accept", "application/x-java-serialized-object");
request.setParameter("foo", "bar");
MockHttpServletResponse response = new MockHttpServletResponse();
gateway.handleRequest(request, response);
assertThat(response.getStatus(), is(HttpServletResponse.SC_OK));
assertThat(response.getContentType(), is("application/x-java-serialized-object"));
//MockHttpServletResponse#getContentType() works in Spring 3.1.2.RELEASE but not in 3.0.7.RELEASE
//For 3.0.7.RELEASE we have to rely on MockHttpServletResponse#getHeader instead
assertEquals(response.getHeader("Content-Type"), "application/x-java-serialized-object");
}
@Test

View File

@@ -113,7 +113,9 @@ public class HttpOutboundGatewayWithMethodExpression {
String response = null;
if (requestMethod.equalsIgnoreCase(this.httpMethod)){
response = httpMethod;
t.getResponseHeaders().add("Content-Type", "text/plain"); //Required for Spring 3.0.x
t.sendResponseHeaders(200, response.length());
}
else {
response = "Request is NOT valid";

View File

@@ -28,6 +28,7 @@ import org.junit.Test;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
@@ -139,6 +140,7 @@ public class OutboundResponseTypeTests {
String response = null;
if (requestMethod.equalsIgnoreCase(this.httpMethod)){
response = httpMethod;
t.getResponseHeaders().add("Content-Type", MediaType.TEXT_PLAIN.toString()); //Required for Spring 3.0.x
t.sendResponseHeaders(200, response.length());
}
else {

View File

@@ -48,6 +48,7 @@ import org.springframework.web.servlet.View;
/**
* @author Mark Fisher
* @author Gary Russell
* @author Gunnar Hillert
* @since 2.0
*/
public class HttpRequestHandlingControllerTests {
@@ -61,7 +62,11 @@ public class HttpRequestHandlingControllerTests {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.setContent("hello".getBytes());
request.setContentType("text/plain");
//request.setContentType("text/plain"); //Works in Spring 3.1.2.RELEASE but NOT in 3.0.7.RELEASE
//Instead do:
request.addHeader("Content-Type", "text/plain");
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView modelAndView = controller.handleRequest(request, response);
assertEquals("foo", modelAndView.getViewName());
@@ -81,7 +86,11 @@ public class HttpRequestHandlingControllerTests {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.setContent("hello".getBytes());
request.setContentType("text/plain");
//request.setContentType("text/plain"); //Works in Spring 3.1.2.RELEASE but NOT in 3.0.7.RELEASE
//Instead do:
request.addHeader("Content-Type", "text/plain");
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView modelAndView = controller.handleRequest(request, response);
assertEquals("baz", modelAndView.getViewName());
@@ -106,8 +115,12 @@ public class HttpRequestHandlingControllerTests {
controller.setViewName("foo");
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.setContent("hello".getBytes());
request.setContentType("text/plain");
//request.setContentType("text/plain"); //Works in Spring 3.1.2.RELEASE but NOT in 3.0.7.RELEASE
//Instead do:
request.addHeader("Content-Type", "text/plain");
request.setContent("hello".getBytes()); //For Spring 3.0.7.RELEASE the Content must be set,
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView modelAndView = controller.handleRequest(request, response);
assertEquals("foo", modelAndView.getViewName());
@@ -191,7 +204,11 @@ public class HttpRequestHandlingControllerTests {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.setContent("howdy".getBytes());
request.setContentType("text/plain");
//request.setContentType("text/plain"); //Works in Spring 3.1.2.RELEASE but NOT in 3.0.7.RELEASE
//Instead do:
request.addHeader("Content-Type", "text/plain");
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView modelAndView = controller.handleRequest(request, response);
assertEquals("foo", modelAndView.getViewName());
@@ -218,7 +235,11 @@ public class HttpRequestHandlingControllerTests {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.setContent("abc".getBytes());
request.setContentType("text/plain");
//request.setContentType("text/plain"); //Works in Spring 3.1.2.RELEASE but NOT in 3.0.7.RELEASE
//Instead do:
request.addHeader("Content-Type", "text/plain");
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView modelAndView = controller.handleRequest(request, response);
assertEquals("foo", modelAndView.getViewName());
@@ -279,7 +300,11 @@ public class HttpRequestHandlingControllerTests {
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.setContent("hello".getBytes());
request.setContentType("text/plain");
//request.setContentType("text/plain"); //Works in Spring 3.1.2.RELEASE but NOT in 3.0.7.RELEASE
//Instead do:
request.addHeader("Content-Type", "text/plain");
MockHttpServletResponse response = new MockHttpServletResponse();
final AtomicInteger active = new AtomicInteger();
final AtomicBoolean expected503 = new AtomicBoolean();

View File

@@ -45,6 +45,7 @@ import org.springframework.util.SerializationUtils;
/**
* @author Mark Fisher
* @author Gary Russell
* @author Gunnar Hillert
* @since 2.0
*/
public class HttpRequestHandlingMessagingGatewayTests {
@@ -76,7 +77,11 @@ public class HttpRequestHandlingMessagingGatewayTests {
gateway.setRequestChannel(requestChannel);
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.setContentType("text/plain");
//request.setContentType("text/plain"); //Works in Spring 3.1.2.RELEASE but NOT in 3.0.7.RELEASE
//Instead do:
request.addHeader("Content-Type", "text/plain");
request.setContent("hello".getBytes());
MockHttpServletResponse response = new MockHttpServletResponse();
gateway.handleRequest(request, response);
@@ -101,7 +106,11 @@ public class HttpRequestHandlingMessagingGatewayTests {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.addHeader("Accept", "x-application/octet-stream");
request.setContentType("text/plain");
//request.setContentType("text/plain"); //Works in Spring 3.1.2.RELEASE but NOT in 3.0.7.RELEASE
//Instead do:
request.addHeader("Content-Type", "text/plain");
request.setContent("hello".getBytes());
MockHttpServletResponse response = new MockHttpServletResponse();
gateway.handleRequest(request, response);
@@ -122,7 +131,11 @@ public class HttpRequestHandlingMessagingGatewayTests {
gateway.setRequestChannel(requestChannel);
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.setContentType("text/plain");
//request.setContentType("text/plain"); //Works in Spring 3.1.2.RELEASE but NOT in 3.0.7.RELEASE
//Instead do:
request.addHeader("Content-Type", "text/plain");
request.setContent("hello".getBytes());
MockHttpServletResponse response = new MockHttpServletResponse();
gateway.handleRequest(request, response);
@@ -183,7 +196,11 @@ public class HttpRequestHandlingMessagingGatewayTests {
gateway.setRequestPayloadType(TestBean.class);
gateway.setRequestChannel(channel);
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/test");
request.setContentType("application/x-java-serialized-object");
//request.setContentType("application/x-java-serialized-object"); //Works in Spring 3.1.2.RELEASE but NOT in 3.0.7.RELEASE
//Instead do:
request.addHeader("Content-Type", "application/x-java-serialized-object");
TestBean testBean = new TestBean();
testBean.setName("T. Bean");
testBean.setAge(42);

View File

@@ -35,6 +35,7 @@ import org.springframework.mock.web.MockHttpServletResponse;
/**
* @author Oleg Zhurakousky
* @author Gary Russell
* @author Gunnar Hillert
*/
public class HttpRequestHandlingMessagingGatewayWithPathMappingTests {
@@ -53,7 +54,10 @@ public class HttpRequestHandlingMessagingGatewayWithPathMappingTests {
});
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.setContentType("text/plain");
//request.setContentType("text/plain"); //Works in Spring 3.1.2.RELEASE but NOT in 3.0.7.RELEASE
//Instead do:
request.addHeader("Content-Type", "text/plain");
request.setParameter("foo", "bar");
request.setContent("hello".getBytes());
request.setRequestURI("/fname/bill/lname/clinton");

View File

@@ -34,7 +34,7 @@ import org.junit.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.convert.support.ConversionServiceFactory;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
@@ -57,131 +57,131 @@ public class DefaultHttpHeaderMapperFromMessageInboundTests {
Map<String, Object> messageHeaders = new HashMap<String, Object>();
messageHeaders.put("Allow", "bar");
HttpHeaders headers = new HttpHeaders();
mapper.fromHeaders(new MessageHeaders(messageHeaders), headers);
}
@Test
public void validateAllowAsString(){
HeaderMapper<HttpHeaders> mapper = DefaultHttpHeaderMapper.inboundMapper();
Map<String, Object> messageHeaders = new HashMap<String, Object>();
messageHeaders.put("Allow", "GET");
HttpHeaders headers = new HttpHeaders();
mapper.fromHeaders(new MessageHeaders(messageHeaders), headers);
assertEquals(1, headers.getAllow().size());
assertEquals(HttpMethod.GET, headers.getAllow().iterator().next());
}
@Test
public void validateAllowAsStringCaseInsensitive(){
HeaderMapper<HttpHeaders> mapper = DefaultHttpHeaderMapper.inboundMapper();
Map<String, Object> messageHeaders = new HashMap<String, Object>();
messageHeaders.put("allow", "GET");
HttpHeaders headers = new HttpHeaders();
mapper.fromHeaders(new MessageHeaders(messageHeaders), headers);
assertEquals(1, headers.getAllow().size());
assertEquals(HttpMethod.GET, headers.getAllow().iterator().next());
}
@Test
public void validateAllowAsHttpMethod(){
HeaderMapper<HttpHeaders> mapper = DefaultHttpHeaderMapper.inboundMapper();
Map<String, Object> messageHeaders = new HashMap<String, Object>();
messageHeaders.put("Allow", HttpMethod.GET);
HttpHeaders headers = new HttpHeaders();
mapper.fromHeaders(new MessageHeaders(messageHeaders), headers);
assertEquals(1, headers.getAllow().size());
assertEquals(HttpMethod.GET, headers.getAllow().iterator().next());
}
@Test
public void validateAllowAsDelimitedString(){
HeaderMapper<HttpHeaders> mapper = DefaultHttpHeaderMapper.inboundMapper();
Map<String, Object> messageHeaders = new HashMap<String, Object>();
messageHeaders.put("Allow", "GET, POST");
HttpHeaders headers = new HttpHeaders();
mapper.fromHeaders(new MessageHeaders(messageHeaders), headers);
assertEquals(2, headers.getAllow().size());
assertTrue(headers.getAllow().contains(HttpMethod.GET));
assertTrue(headers.getAllow().contains(HttpMethod.POST));
}
@Test
public void validateAllowAsStringArray(){
HeaderMapper<HttpHeaders> mapper = DefaultHttpHeaderMapper.inboundMapper();
Map<String, Object> messageHeaders = new HashMap<String, Object>();
messageHeaders.put("Allow", new String[]{"GET", "POST"});
HttpHeaders headers = new HttpHeaders();
mapper.fromHeaders(new MessageHeaders(messageHeaders), headers);
assertEquals(2, headers.getAllow().size());
assertTrue(headers.getAllow().contains(HttpMethod.GET));
assertTrue(headers.getAllow().contains(HttpMethod.POST));
}
@Test
public void validateAllowAsHttpMethodArray(){
HeaderMapper<HttpHeaders> mapper = DefaultHttpHeaderMapper.inboundMapper();
Map<String, Object> messageHeaders = new HashMap<String, Object>();
messageHeaders.put("Allow", new HttpMethod[]{HttpMethod.GET, HttpMethod.POST});
HttpHeaders headers = new HttpHeaders();
mapper.fromHeaders(new MessageHeaders(messageHeaders), headers);
assertEquals(2, headers.getAllow().size());
assertTrue(headers.getAllow().contains(HttpMethod.GET));
assertTrue(headers.getAllow().contains(HttpMethod.POST));
}
@Test
public void validateAllowAsCollectionOfString(){
HeaderMapper<HttpHeaders> mapper = DefaultHttpHeaderMapper.inboundMapper();
Map<String, Object> messageHeaders = new HashMap<String, Object>();
messageHeaders.put("Allow", CollectionUtils.arrayToList(new String[]{"GET", "POST"}));
HttpHeaders headers = new HttpHeaders();
mapper.fromHeaders(new MessageHeaders(messageHeaders), headers);
assertEquals(2, headers.getAllow().size());
assertTrue(headers.getAllow().contains(HttpMethod.GET));
assertTrue(headers.getAllow().contains(HttpMethod.POST));
}
@Test
public void validateAllowAsCollectionOfHttpMethods(){
HeaderMapper<HttpHeaders> mapper = DefaultHttpHeaderMapper.inboundMapper();
Map<String, Object> messageHeaders = new HashMap<String, Object>();
messageHeaders.put("Allow", CollectionUtils.arrayToList(new HttpMethod[]{HttpMethod.GET, HttpMethod.POST}));
HttpHeaders headers = new HttpHeaders();
mapper.fromHeaders(new MessageHeaders(messageHeaders), headers);
assertEquals(2, headers.getAllow().size());
assertTrue(headers.getAllow().contains(HttpMethod.GET));
assertTrue(headers.getAllow().contains(HttpMethod.POST));
}
// Cache-Control tested as part of DefaultHttpHeaderMapperFromMessageOutboundTests
// Content-Length tested as part of DefaultHttpHeaderMapperFromMessageOutboundTests
// Content-Type tested as part of DefaultHttpHeaderMapperFromMessageOutboundTests
// Date tested as part of DefaultHttpHeaderMapperFromMessageOutboundTests
// ETag tests
@Test
public void validateETag(){
HeaderMapper<HttpHeaders> mapper = DefaultHttpHeaderMapper.inboundMapper();
Map<String, Object> messageHeaders = new HashMap<String, Object>();
messageHeaders.put("ETag", "\"1234\"");
HttpHeaders headers = new HttpHeaders();
mapper.fromHeaders(new MessageHeaders(messageHeaders), headers);
assertEquals("\"1234\"", headers.getETag());
}
// Expires tests
@Test
public void validateExpiresAsNumber() throws ParseException{
HeaderMapper<HttpHeaders> mapper = DefaultHttpHeaderMapper.inboundMapper();
@@ -189,12 +189,12 @@ public class DefaultHttpHeaderMapperFromMessageInboundTests {
messageHeaders.put("Expires", 12345678);
HttpHeaders headers = new HttpHeaders();
mapper.fromHeaders(new MessageHeaders(messageHeaders), headers);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
assertEquals(simpleDateFormat.parse("Thu, 01 Jan 1970 03:25:45 GMT").getTime(), headers.getExpires());
}
@Test
public void validateExpiresAsString() throws ParseException{
HeaderMapper<HttpHeaders> mapper = DefaultHttpHeaderMapper.inboundMapper();
@@ -202,9 +202,9 @@ public class DefaultHttpHeaderMapperFromMessageInboundTests {
messageHeaders.put("Expires", "12345678");
HttpHeaders headers = new HttpHeaders();
mapper.fromHeaders(new MessageHeaders(messageHeaders), headers);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
assertEquals(simpleDateFormat.parse("Thu, 01 Jan 1970 03:25:45 GMT").getTime(), headers.getExpires());
}
@Test
@@ -214,14 +214,14 @@ public class DefaultHttpHeaderMapperFromMessageInboundTests {
messageHeaders.put("Expires", new Date(12345678));
HttpHeaders headers = new HttpHeaders();
mapper.fromHeaders(new MessageHeaders(messageHeaders), headers);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
assertEquals(simpleDateFormat.parse("Thu, 01 Jan 1970 03:25:45 GMT").getTime(), headers.getExpires());
}
// Last-Modified tests
@Test
public void validateLastModifiedAsNumber() throws ParseException{
HeaderMapper<HttpHeaders> mapper = DefaultHttpHeaderMapper.inboundMapper();
@@ -229,12 +229,12 @@ public class DefaultHttpHeaderMapperFromMessageInboundTests {
messageHeaders.put("Last-Modified", 12345678);
HttpHeaders headers = new HttpHeaders();
mapper.fromHeaders(new MessageHeaders(messageHeaders), headers);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
assertEquals(simpleDateFormat.parse("Thu, 01 Jan 1970 03:25:45 GMT").getTime(), headers.getLastModified());
}
@Test
public void validateLastModifiedAsString() throws ParseException{
HeaderMapper<HttpHeaders> mapper = DefaultHttpHeaderMapper.inboundMapper();
@@ -242,9 +242,9 @@ public class DefaultHttpHeaderMapperFromMessageInboundTests {
messageHeaders.put("Last-Modified", "12345678");
HttpHeaders headers = new HttpHeaders();
mapper.fromHeaders(new MessageHeaders(messageHeaders), headers);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
assertEquals(simpleDateFormat.parse("Thu, 01 Jan 1970 03:25:45 GMT").getTime(), headers.getLastModified());
}
@Test
@@ -254,14 +254,14 @@ public class DefaultHttpHeaderMapperFromMessageInboundTests {
messageHeaders.put("Last-Modified", new Date(12345678));
HttpHeaders headers = new HttpHeaders();
mapper.fromHeaders(new MessageHeaders(messageHeaders), headers);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
assertEquals(simpleDateFormat.parse("Thu, 01 Jan 1970 03:25:45 GMT").getTime(), headers.getLastModified());
}
// Location tests
@Test
public void validateLocation() throws Exception{
HeaderMapper<HttpHeaders> mapper = DefaultHttpHeaderMapper.inboundMapper();
@@ -269,10 +269,10 @@ public class DefaultHttpHeaderMapperFromMessageInboundTests {
messageHeaders.put("Location", "http://foo.com");
HttpHeaders headers = new HttpHeaders();
mapper.fromHeaders(new MessageHeaders(messageHeaders), headers);
assertEquals(new URI("http://foo.com").toString(), headers.getLocation().toString());
}
// Pragma tested as part of DefaultHttpHeaderMapperFromMessageOutboundTests
@Test
@@ -315,7 +315,7 @@ public class DefaultHttpHeaderMapperFromMessageInboundTests {
assertEquals(1, headers.get("X-1z").size());
assertEquals("1z-value", headers.getFirst("X-1z"));
assertEquals(1, headers.get("X-abcdef").size());
assertEquals("abcdef-value", headers.getFirst("X-abcdef"));
assertEquals("abcdef-value", headers.getFirst("X-abcdef"));
}
@Test
@@ -334,7 +334,7 @@ public class DefaultHttpHeaderMapperFromMessageInboundTests {
assertEquals(1, headers.get("X-foobar").size());
assertEquals("abc", headers.getFirst("X-foobar"));
}
@Test
public void validateCustomHeaderNamePatternsAndStandardResponseHeadersMappedToHttpHeadersWithCustomPrefix() throws Exception{
DefaultHttpHeaderMapper mapper = new DefaultHttpHeaderMapper();
@@ -352,7 +352,7 @@ public class DefaultHttpHeaderMapperFromMessageInboundTests {
assertEquals(1, headers.get("Z-foobar").size());
assertEquals("abc", headers.getFirst("Z-foobar"));
}
@Test
public void validateCustomHeaderNamePatternsAndStandardResponseHeadersMappedToHttpHeadersWithCustomPrefixEmptyString() throws Exception{
DefaultHttpHeaderMapper mapper = new DefaultHttpHeaderMapper();
@@ -370,7 +370,7 @@ public class DefaultHttpHeaderMapperFromMessageInboundTests {
assertEquals(1, headers.get("foobar").size());
assertEquals("abc", headers.getFirst("foobar"));
}
@Test
public void validateCustomHeaderNamePatternsAndStandardResponseHeadersMappedToHttpHeadersWithCustomPrefixNull() throws Exception{
DefaultHttpHeaderMapper mapper = new DefaultHttpHeaderMapper();
@@ -439,76 +439,79 @@ public class DefaultHttpHeaderMapperFromMessageInboundTests {
assertEquals("abc", result.get("foobar"));
assertEquals(MediaType.TEXT_XML, result.get("Accept"));
}
@Test
public void validateCustomHeadersWithNonStringValuesAndNoConverter() throws Exception{
DefaultHttpHeaderMapper mapper = new DefaultHttpHeaderMapper();
mapper.setOutboundHeaderNames(new String[] {"customHeader*"});
HttpHeaders headers = new HttpHeaders();
Map<String, Object> messageHeaders = new HashMap<String, Object>();
messageHeaders.put("customHeaderA", 123);
messageHeaders.put("customHeaderB", new TestClass());
mapper.fromHeaders(new MessageHeaders(messageHeaders), headers);
assertNull(headers.get("X-customHeaderA"));
assertNull(headers.get("X-customHeaderB"));
}
@Test
@SuppressWarnings("deprecation")
public void validateCustomHeadersWithNonStringValuesAndDefaultConverterOnly() throws Exception{
DefaultHttpHeaderMapper mapper = new DefaultHttpHeaderMapper();
mapper.setOutboundHeaderNames(new String[] {"customHeader*"});
ConversionService cs = new DefaultConversionService();
ConversionService cs = ConversionServiceFactory.createDefaultConversionService();
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.registerSingleton("integrationConversionService", cs);
mapper.setBeanFactory(beanFactory);
mapper.afterPropertiesSet();
HttpHeaders headers = new HttpHeaders();
Map<String, Object> messageHeaders = new HashMap<String, Object>();
messageHeaders.put("customHeaderA", 123);
messageHeaders.put("customHeaderB", new TestClass());
mapper.fromHeaders(new MessageHeaders(messageHeaders), headers);
assertNotNull(headers.get("X-customHeaderA"));
assertEquals("123", headers.get("X-customHeaderA").get(0));
assertNull(headers.get("X-customHeaderB"));
}
@Test
@SuppressWarnings("deprecation")
public void validateCustomHeadersWithNonStringValuesAndDefaultConverterWithCustomConverter() throws Exception{
DefaultHttpHeaderMapper mapper = new DefaultHttpHeaderMapper();
mapper.setOutboundHeaderNames(new String[] {"customHeader*"});
GenericConversionService cs = new DefaultConversionService();
GenericConversionService cs = ConversionServiceFactory.createDefaultConversionService();
cs.addConverter(new TestClassConverter());
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.registerSingleton("integrationConversionService", cs);
mapper.setBeanFactory(beanFactory);
mapper.afterPropertiesSet();
HttpHeaders headers = new HttpHeaders();
Map<String, Object> messageHeaders = new HashMap<String, Object>();
messageHeaders.put("customHeaderA", 123);
messageHeaders.put("customHeaderB", new TestClass());
mapper.fromHeaders(new MessageHeaders(messageHeaders), headers);
assertNotNull(headers.get("X-customHeaderA"));
assertEquals("123", headers.get("X-customHeaderA").get(0));
assertNotNull(headers.get("X-customHeaderB"));
assertEquals("TestClass.class", headers.get("X-customHeaderB").get(0));
}
public static class TestClass {
}
public static class TestClassConverter implements Converter<TestClass, String>{
public String convert(TestClass source) {
return "TestClass.class";
}
}
}