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

@@ -45,8 +45,9 @@ subprojects { subproject ->
junitVersion = '4.8.2' junitVersion = '4.8.2'
log4jVersion = '1.2.12' log4jVersion = '1.2.12'
mockitoVersion = '1.9.0' mockitoVersion = '1.9.0'
// When changing Spring Versions - don't forget to update bundlor ranges // When changing Spring Versions - don't forget to update bundlor ranges
springVersion = '3.1.2.RELEASE' springVersion = project.hasProperty('springVersion') ? getProperty('springVersion') : '3.1.2.RELEASE'
springAmqpVersion = '1.1.1.RELEASE' springAmqpVersion = '1.1.1.RELEASE'
springDataMongoVersion = '1.1.0.M1' springDataMongoVersion = '1.1.0.M1'
springDataRedisVersion = '1.0.1.RELEASE' springDataRedisVersion = '1.0.1.RELEASE'
@@ -355,7 +356,7 @@ project('spring-integration-http') {
dependencies { dependencies {
compile project(":spring-integration-core") compile project(":spring-integration-core")
compile "org.springframework:spring-webmvc:$springVersion" compile "org.springframework:spring-webmvc:$springVersion"
compile("javax.servlet:servlet-api:2.4", provided) compile("javax.servlet:javax.servlet-api:3.0.1", provided)
compile("commons-httpclient:commons-httpclient:3.1") { dep -> compile("commons-httpclient:commons-httpclient:3.1") { dep ->
optional dep optional dep
exclude group: 'junit', module: 'junit' exclude group: 'junit', module: 'junit'
@@ -517,12 +518,15 @@ project('spring-integration-jpa') {
testCompile "org.aspectj:aspectjrt:$aspectjVersion" testCompile "org.aspectj:aspectjrt:$aspectjVersion"
testCompile "org.aspectj:aspectjweaver:$aspectjVersion" testCompile "org.aspectj:aspectjweaver:$aspectjVersion"
testCompile "org.hibernate:hibernate-entitymanager:4.0.1.Final" testCompile "org.hibernate:hibernate-entitymanager:3.6.10.Final"
testCompile "org.eclipse.persistence:org.eclipse.persistence.jpa:2.3.2" testCompile "org.eclipse.persistence:org.eclipse.persistence.jpa:2.3.2"
testCompile "org.apache.openjpa:openjpa:2.2.0" testCompile "org.apache.openjpa:openjpa:2.2.0"
javaAgentSpringInstrument "org.springframework:spring-instrument:$springVersion" javaAgentSpringInstrument "org.springframework:spring-instrument:$springVersion"
javaAgentOpenJpa "org.apache.openjpa:openjpa:2.2.0" javaAgentOpenJpa "org.apache.openjpa:openjpa:2.2.0"
//Suppress openjpa annotation processor warnings
compileTestJava.options.compilerArgs = ["${xLintArg},-processing"]
} }
bundlor { bundlor {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2010 the original author or authors. * Copyright 2002-2012 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -27,9 +27,10 @@ import org.springframework.util.ReflectionUtils.MethodCallback;
/** /**
* Helper to provide common features for inspecting objects and locating annotated methods. * Helper to provide common features for inspecting objects and locating annotated methods.
* *
* @author Dave Syer * @author Dave Syer
* * @author Gunnar Hillert
*
*/ */
abstract class AnnotationFinder { abstract class AnnotationFinder {
@@ -45,6 +46,7 @@ abstract class AnnotationFinder {
return reference.get(); return reference.get();
} }
@SuppressWarnings("deprecation")
private static Class<?> getTargetClass(Object targetObject) { private static Class<?> getTargetClass(Object targetObject) {
Class<?> targetClass = targetObject.getClass(); Class<?> targetClass = targetObject.getClass();
if (AopUtils.isAopProxy(targetObject)) { if (AopUtils.isAopProxy(targetObject)) {

View File

@@ -32,7 +32,7 @@ import org.springframework.jmx.export.annotation.ManagedResource;
/** /**
* Base class for all Message Routers. * Base class for all Message Routers.
* *
* @author Mark Fisher * @author Mark Fisher
* @author Oleg Zhurakousky * @author Oleg Zhurakousky
* @author Gunnar Hillert * @author Gunnar Hillert
@@ -50,12 +50,12 @@ public abstract class AbstractMessageRouter extends AbstractMessageHandler {
/** /**
* Set the default channel where Messages should be sent if channel resolution * Set the default channel where Messages should be sent if channel resolution
* fails to return any channels. If no default channel is provided and channel * fails to return any channels. If no default channel is provided and channel
* resolution fails to return any channels, the router will throw an * resolution fails to return any channels, the router will throw an
* {@link MessageDeliveryException}. * {@link MessageDeliveryException}.
* *
* If messages shall be ignored (dropped) instead, please provide a {@link NullChannel}. * If messages shall be ignored (dropped) instead, please provide a {@link NullChannel}.
*/ */
public void setDefaultOutputChannel(MessageChannel defaultOutputChannel) { public void setDefaultOutputChannel(MessageChannel defaultOutputChannel) {
this.defaultOutputChannel = defaultOutputChannel; this.defaultOutputChannel = defaultOutputChannel;
@@ -100,6 +100,7 @@ public abstract class AbstractMessageRouter extends AbstractMessageHandler {
return this.messagingTemplate; return this.messagingTemplate;
} }
@SuppressWarnings("deprecation")
protected ConversionService getRequiredConversionService() { protected ConversionService getRequiredConversionService() {
if (this.getConversionService() == null) { if (this.getConversionService() == null) {
this.setConversionService(ConversionServiceFactory.createDefaultConversionService()); this.setConversionService(ConversionServiceFactory.createDefaultConversionService());

View File

@@ -29,12 +29,12 @@ import org.springframework.validation.DataBinder;
/** /**
* Will transform Map to an instance of Object. There are two ways to specify the type of the transformed Object. * Will transform Map to an instance of Object. There are two ways to specify the type of the transformed Object.
* You can use one of two constructors. The constructor that takes the Class&lt;?&gt; as an argument will construct the Object of * You can use one of two constructors. The constructor that takes the Class&lt;?&gt; as an argument will construct the Object of
* that type. There is another constructor that takes a 'beanName' as an argument and will populate this bean with transformed data. * that type. There is another constructor that takes a 'beanName' as an argument and will populate this bean with transformed data.
* Such bean must be of 'prototype' scope otherwise {@link MessageTransformationException} will be thrown. * Such bean must be of 'prototype' scope otherwise {@link MessageTransformationException} will be thrown.
* This transformer is integrated with the {@link ConversionService} allowing values in the Map to be converted * This transformer is integrated with the {@link ConversionService} allowing values in the Map to be converted
* to types that represent the properties of the Object. * to types that represent the properties of the Object.
* *
* @author Oleg Zhurakousky * @author Oleg Zhurakousky
* @since 2.0 * @since 2.0
*/ */
@@ -63,11 +63,12 @@ public class MapToObjectTransformer extends AbstractPayloadTransformer<Map<?,?>,
* (non-Javadoc) * (non-Javadoc)
* @see org.springframework.integration.transformer.AbstractPayloadTransformer#transformPayload(java.lang.Object) * @see org.springframework.integration.transformer.AbstractPayloadTransformer#transformPayload(java.lang.Object)
*/ */
@SuppressWarnings("deprecation")
protected Object transformPayload(Map<?,?> payload) throws Exception { protected Object transformPayload(Map<?,?> payload) throws Exception {
Object target = (this.targetClass != null) Object target = (this.targetClass != null)
? BeanUtils.instantiate(this.targetClass) ? BeanUtils.instantiate(this.targetClass)
: this.getBeanFactory().getBean(this.targetBeanName); : this.getBeanFactory().getBean(this.targetBeanName);
DataBinder binder = new DataBinder(target); DataBinder binder = new DataBinder(target);
ConversionService conversionService = null; ConversionService conversionService = null;
if (this.getBeanFactory() instanceof ConfigurableBeanFactory){ if (this.getBeanFactory() instanceof ConfigurableBeanFactory){
conversionService = ((ConfigurableBeanFactory)this.getBeanFactory()).getConversionService(); conversionService = ((ConfigurableBeanFactory)this.getBeanFactory()).getConversionService();
@@ -79,7 +80,7 @@ public class MapToObjectTransformer extends AbstractPayloadTransformer<Map<?,?>,
binder.bind(new MutablePropertyValues(payload)); binder.bind(new MutablePropertyValues(payload));
return target; return target;
} }
protected void onInit(){ protected void onInit(){
if (StringUtils.hasText(this.targetBeanName)) { if (StringUtils.hasText(this.targetBeanName)) {
Assert.isTrue(this.getBeanFactory().isPrototype(this.targetBeanName), Assert.isTrue(this.getBeanFactory().isPrototype(this.targetBeanName),

View File

@@ -43,6 +43,7 @@ public class BeanFactoryTypeConverter implements TypeConverter, BeanFactoryAware
private volatile ConversionService conversionService; private volatile ConversionService conversionService;
@SuppressWarnings("deprecation")
public BeanFactoryTypeConverter() { public BeanFactoryTypeConverter() {
synchronized (BeanFactoryTypeConverter.class) { synchronized (BeanFactoryTypeConverter.class) {
if (defaultConversionService == null) { if (defaultConversionService == null) {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2010 the original author or authors. * Copyright 2002-2012 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -68,10 +68,12 @@ import org.springframework.util.StringUtils;
* is provided, and more than one declared method has that name, the method-selection will be dynamic, based on the * is provided, and more than one declared method has that name, the method-selection will be dynamic, based on the
* underlying SpEL method resolution. Alternatively, an annotation type may be provided so that the candidates for * underlying SpEL method resolution. Alternatively, an annotation type may be provided so that the candidates for
* SpEL's method resolution are determined by the presence of that annotation rather than the method name. * SpEL's method resolution are determined by the presence of that annotation rather than the method name.
* *
* @author Mark Fisher * @author Mark Fisher
* @author Oleg Zhurakousky * @author Oleg Zhurakousky
* @author Dave Syer * @author Dave Syer
* @author Gunnar Hillert
*
* @since 2.0 * @since 2.0
*/ */
public class MessagingMethodInvokerHelper<T> extends AbstractExpressionEvaluator { public class MessagingMethodInvokerHelper<T> extends AbstractExpressionEvaluator {
@@ -280,7 +282,7 @@ public class MessagingMethodInvokerHelper<T> extends AbstractExpressionEvaluator
if (isMethodDefinedOnObjectClass(method)) { if (isMethodDefinedOnObjectClass(method)) {
return; return;
} }
if (method.getDeclaringClass().equals(Proxy.class)) { if (method.getDeclaringClass().equals(Proxy.class)) {
return; return;
} }
if (!Modifier.isPublic(method.getModifiers())) { if (!Modifier.isPublic(method.getModifiers())) {
@@ -354,6 +356,7 @@ public class MessagingMethodInvokerHelper<T> extends AbstractExpressionEvaluator
return fallbackMethods; return fallbackMethods;
} }
@SuppressWarnings("deprecation")
private Class<?> getTargetClass(Object targetObject) { private Class<?> getTargetClass(Object targetObject) {
Class<?> targetClass = targetObject.getClass(); Class<?> targetClass = targetObject.getClass();
if (AopUtils.isAopProxy(targetObject)) { if (AopUtils.isAopProxy(targetObject)) {

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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -225,7 +225,9 @@ public class MethodInvokingMessageGroupProcessorTests {
assertThat((Integer) ((Message<?>) result).getPayload(), is(7)); assertThat((Integer) ((Message<?>) result).getPayload(), is(7));
} }
@Test @Test
@SuppressWarnings("deprecation")
public void shouldFindSimpleAggregatorMethodWithIterator() throws Exception { public void shouldFindSimpleAggregatorMethodWithIterator() throws Exception {
@SuppressWarnings("unused") @SuppressWarnings("unused")
@@ -280,7 +282,7 @@ public class MethodInvokingMessageGroupProcessorTests {
Object result = processor.processMessageGroup(messageGroupMock); Object result = processor.processMessageGroup(messageGroupMock);
assertThat((Integer) ((Message<?>) result).getPayload(), is(7)); assertThat((Integer) ((Message<?>) result).getPayload(), is(7));
} }
@Test @Test
public void shouldFindFittingMethodForIteratorOfMessages() { public void shouldFindFittingMethodForIteratorOfMessages() {

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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -57,6 +57,7 @@ public class DatatypeChannelTests {
} }
@Test @Test
@SuppressWarnings("deprecation")
public void unsupportedTypeButConversionServiceSupports() { public void unsupportedTypeButConversionServiceSupports() {
QueueChannel channel = createChannel(Integer.class); QueueChannel channel = createChannel(Integer.class);
ConversionService conversionService = ConversionServiceFactory.createDefaultConversionService(); ConversionService conversionService = ConversionServiceFactory.createDefaultConversionService();
@@ -65,6 +66,7 @@ public class DatatypeChannelTests {
} }
@Test(expected = MessageDeliveryException.class) @Test(expected = MessageDeliveryException.class)
@SuppressWarnings("deprecation")
public void unsupportedTypeAndConversionServiceDoesNotSupport() { public void unsupportedTypeAndConversionServiceDoesNotSupport() {
QueueChannel channel = createChannel(Integer.class); QueueChannel channel = createChannel(Integer.class);
ConversionService conversionService = ConversionServiceFactory.createDefaultConversionService(); ConversionService conversionService = ConversionServiceFactory.createDefaultConversionService();
@@ -73,6 +75,7 @@ public class DatatypeChannelTests {
} }
@Test @Test
@SuppressWarnings("deprecation")
public void unsupportedTypeButCustomConversionServiceSupports() { public void unsupportedTypeButCustomConversionServiceSupports() {
QueueChannel channel = createChannel(Integer.class); QueueChannel channel = createChannel(Integer.class);
GenericConversionService conversionService = ConversionServiceFactory.createDefaultConversionService(); GenericConversionService conversionService = ConversionServiceFactory.createDefaultConversionService();
@@ -104,10 +107,11 @@ public class DatatypeChannelTests {
context.registerBeanDefinition("testChannel", channelBuilder.getBeanDefinition()); context.registerBeanDefinition("testChannel", channelBuilder.getBeanDefinition());
QueueChannel channel = context.getBean("testChannel", QueueChannel.class); QueueChannel channel = context.getBean("testChannel", QueueChannel.class);
assertTrue(channel.send(new GenericMessage<Boolean>(Boolean.TRUE))); assertTrue(channel.send(new GenericMessage<Boolean>(Boolean.TRUE)));
assertEquals(new Integer(1), channel.receive().getPayload()); assertEquals(new Integer(1), channel.receive().getPayload());
} }
@Test @Test
@SuppressWarnings("deprecation")
public void conversionServiceReferenceOverridesDefault() { public void conversionServiceReferenceOverridesDefault() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
Converter<Boolean, Integer> defaultConverter = new Converter<Boolean, Integer>() { Converter<Boolean, Integer> defaultConverter = new Converter<Boolean, Integer>() {
@@ -131,7 +135,7 @@ public class DatatypeChannelTests {
context.registerBeanDefinition("testChannel", channelBuilder.getBeanDefinition()); context.registerBeanDefinition("testChannel", channelBuilder.getBeanDefinition());
QueueChannel channel = context.getBean("testChannel", QueueChannel.class); QueueChannel channel = context.getBean("testChannel", QueueChannel.class);
assertTrue(channel.send(new GenericMessage<Boolean>(Boolean.TRUE))); assertTrue(channel.send(new GenericMessage<Boolean>(Boolean.TRUE)));
assertEquals(new Integer(99), channel.receive().getPayload()); assertEquals(new Integer(99), channel.receive().getPayload());
} }
@Test @Test

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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -65,8 +65,9 @@ public class GatewayProxyFactoryBeanTests {
String result = service.requestReply("foo"); String result = service.requestReply("foo");
assertEquals("foobar", result); assertEquals("foobar", result);
} }
@Test @Test
@SuppressWarnings("deprecation")
public void testRequestReplyWithAnonymousChannelConvertedTypeViaConversionService() throws Exception { public void testRequestReplyWithAnonymousChannelConvertedTypeViaConversionService() throws Exception {
QueueChannel requestChannel = new QueueChannel(); QueueChannel requestChannel = new QueueChannel();
startResponder(requestChannel); startResponder(requestChannel);
@@ -75,13 +76,13 @@ public class GatewayProxyFactoryBeanTests {
public byte[] convert(String source) { public byte[] convert(String source) {
return source.getBytes(); return source.getBytes();
} }
}; };
stringToByteConverter = Mockito.spy(stringToByteConverter); stringToByteConverter = Mockito.spy(stringToByteConverter);
cs.addConverter(stringToByteConverter); cs.addConverter(stringToByteConverter);
GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean(); GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean();
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerSingleton(IntegrationContextUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME, cs); bf.registerSingleton(IntegrationContextUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME, cs);
proxyFactory.setBeanFactory(bf); proxyFactory.setBeanFactory(bf);
proxyFactory.setDefaultRequestChannel(requestChannel); proxyFactory.setDefaultRequestChannel(requestChannel);
proxyFactory.setServiceInterface(TestService.class); proxyFactory.setServiceInterface(TestService.class);
@@ -334,7 +335,7 @@ public class GatewayProxyFactoryBeanTests {
// MessageHistoryEvent event1 = historyIterator.next(); // MessageHistoryEvent event1 = historyIterator.next();
// MessageHistoryEvent event2 = historyIterator.next(); // MessageHistoryEvent event2 = historyIterator.next();
// MessageHistoryEvent event3 = historyIterator.next(); // MessageHistoryEvent event3 = historyIterator.next();
// //
// //assertEquals("echo", event1.getAttribute("method", String.class)); // //assertEquals("echo", event1.getAttribute("method", String.class));
// assertEquals("gateway", event1.getType()); // assertEquals("gateway", event1.getType());
// assertEquals("testGateway", event1.getName()); // assertEquals("testGateway", event1.getName());

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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -36,12 +36,14 @@ import static junit.framework.Assert.assertNull;
/** /**
* @author Oleg Zhurakousky * @author Oleg Zhurakousky
* @author Gunnar Hillert
*
* @since 2.0 * @since 2.0
*/ */
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
public class MapToObjectTransformerTests { public class MapToObjectTransformerTests {
@Test @Test
public void testMapToObjectTransformation(){ public void testMapToObjectTransformation(){
Map map = new HashMap(); Map map = new HashMap();
@@ -50,9 +52,9 @@ public class MapToObjectTransformerTests {
Address address = new Address(); Address address = new Address();
address.setStreet("1123 Main st"); address.setStreet("1123 Main st");
map.put("address", address); map.put("address", address);
Message message = MessageBuilder.withPayload(map).build(); Message message = MessageBuilder.withPayload(map).build();
MapToObjectTransformer transformer = new MapToObjectTransformer(Person.class); MapToObjectTransformer transformer = new MapToObjectTransformer(Person.class);
transformer.setBeanFactory(this.getBeanFactory()); transformer.setBeanFactory(this.getBeanFactory());
Message newMessage = transformer.transform(message); Message newMessage = transformer.transform(message);
@@ -64,7 +66,7 @@ public class MapToObjectTransformerTests {
assertNotNull(person.getAddress()); assertNotNull(person.getAddress());
assertEquals("1123 Main st", person.getAddress().getStreet()); assertEquals("1123 Main st", person.getAddress().getStreet());
} }
@Test @Test
public void testMapToObjectTransformationWithPrototype(){ public void testMapToObjectTransformationWithPrototype(){
Map map = new HashMap(); Map map = new HashMap();
@@ -73,7 +75,7 @@ public class MapToObjectTransformerTests {
Address address = new Address(); Address address = new Address();
address.setStreet("1123 Main st"); address.setStreet("1123 Main st");
map.put("address", address); map.put("address", address);
Message message = MessageBuilder.withPayload(map).build(); Message message = MessageBuilder.withPayload(map).build();
StaticApplicationContext ac = new StaticApplicationContext(); StaticApplicationContext ac = new StaticApplicationContext();
ac.registerPrototype("person", Person.class); ac.registerPrototype("person", Person.class);
@@ -95,14 +97,14 @@ public class MapToObjectTransformerTests {
map.put("fname", "Justin"); map.put("fname", "Justin");
map.put("lname", "Case"); map.put("lname", "Case");
map.put("address", "1123 Main st"); map.put("address", "1123 Main st");
Message message = MessageBuilder.withPayload(map).build(); Message message = MessageBuilder.withPayload(map).build();
MapToObjectTransformer transformer = new MapToObjectTransformer(Person.class); MapToObjectTransformer transformer = new MapToObjectTransformer(Person.class);
ConfigurableBeanFactory beanFactory = this.getBeanFactory(); ConfigurableBeanFactory beanFactory = this.getBeanFactory();
((GenericConversionService)beanFactory.getConversionService()).addConverter(new StringToAddressConverter()); ((GenericConversionService)beanFactory.getConversionService()).addConverter(new StringToAddressConverter());
transformer.setBeanFactory(beanFactory); transformer.setBeanFactory(beanFactory);
Message newMessage = transformer.transform(message); Message newMessage = transformer.transform(message);
Person person = (Person) newMessage.getPayload(); Person person = (Person) newMessage.getPayload();
assertNotNull(person); assertNotNull(person);
@@ -111,7 +113,8 @@ public class MapToObjectTransformerTests {
assertNotNull(person.getAddress()); assertNotNull(person.getAddress());
assertEquals("1123 Main st", person.getAddress().getStreet()); assertEquals("1123 Main st", person.getAddress().getStreet());
} }
@SuppressWarnings("deprecation")
private ConfigurableBeanFactory getBeanFactory(){ private ConfigurableBeanFactory getBeanFactory(){
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
GenericConversionService conversionService = ConversionServiceFactory.createDefaultConversionService(); GenericConversionService conversionService = ConversionServiceFactory.createDefaultConversionService();
@@ -129,7 +132,7 @@ public class MapToObjectTransformerTests {
} }
public void setSsn(String ssn) { public void setSsn(String ssn) {
this.ssn = ssn; this.ssn = ssn;
} }
public String getFname() { public String getFname() {
return fname; return fname;
} }
@@ -149,7 +152,7 @@ public class MapToObjectTransformerTests {
this.address = address; this.address = address;
} }
} }
public static class Address { public static class Address {
private String street; private String street;
@@ -161,7 +164,7 @@ public class MapToObjectTransformerTests {
this.street = street; this.street = street;
} }
} }
public class StringToAddressConverter implements Converter<String, Address>{ public class StringToAddressConverter implements Converter<String, Address>{
public Address convert(String source) { public Address convert(String source) {
Address address = new Address(); Address address = new Address();

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2011 the original author or authors. * Copyright 2012 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@ import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.Properties; import java.util.Properties;
import com.gemstone.gemfire.cache.AttributesFactory;
import com.gemstone.gemfire.cache.Cache; import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheFactory; import com.gemstone.gemfire.cache.CacheFactory;
import com.gemstone.gemfire.cache.DataPolicy; import com.gemstone.gemfire.cache.DataPolicy;
@@ -32,13 +31,15 @@ import com.gemstone.gemfire.distributed.DistributedSystem;
/** /**
* @author Costin Leau * @author Costin Leau
* @author David Turanski * @author David Turanski
* * @author Gunnar Hillert
*
* Runs as a standalone Java app. * Runs as a standalone Java app.
* Modified from SGF implementation for testing client/server CQ features * Modified from SGF implementation for testing client/server CQ features
*/ */
@SuppressWarnings("deprecation")
public class CacheServerProcess { public class CacheServerProcess {
@SuppressWarnings({ "deprecation", "rawtypes", "unchecked" }) @SuppressWarnings({ "rawtypes", "unchecked" })
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Properties props = new Properties(); Properties props = new Properties();
@@ -46,12 +47,12 @@ public class CacheServerProcess {
props.setProperty("log-level", "info"); props.setProperty("log-level", "info");
System.out.println("\nConnecting to the distributed system and creating the cache."); System.out.println("\nConnecting to the distributed system and creating the cache.");
DistributedSystem ds = DistributedSystem.connect(props); DistributedSystem ds = DistributedSystem.connect(props);
Cache cache = CacheFactory.create(ds); Cache cache = CacheFactory.create(ds);
// Create region. // Create region.
AttributesFactory factory = new AttributesFactory(); com.gemstone.gemfire.cache.AttributesFactory factory = new com.gemstone.gemfire.cache.AttributesFactory();
factory.setDataPolicy(DataPolicy.REPLICATE); factory.setDataPolicy(DataPolicy.REPLICATE);
factory.setScope(Scope.DISTRIBUTED_ACK); factory.setScope(Scope.DISTRIBUTED_ACK);
Region testRegion = cache.createRegion("test", factory.create()); Region testRegion = cache.createRegion("test", factory.create());
@@ -65,7 +66,7 @@ public class CacheServerProcess {
server.start(); server.start();
ForkUtil.createControlFile(CacheServerProcess.class.getName()); ForkUtil.createControlFile(CacheServerProcess.class.getName());
System.out.println("Waiting for shutdown"); System.out.println("Waiting for shutdown");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
bufferedReader.readLine(); bufferedReader.readLine();

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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 Mark Fisher
* @author Oleg Zhurakousky * @author Oleg Zhurakousky
* @author Gary Russell * @author Gary Russell
* @author Gunnar Hillert
* @since 2.0 * @since 2.0
*/ */
public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMessageHandler { public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMessageHandler {
@@ -289,17 +290,36 @@ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMe
} }
Assert.isInstanceOf(GenericConversionService.class, conversionService); Assert.isInstanceOf(GenericConversionService.class, conversionService);
GenericConversionService gConversionService = (GenericConversionService) conversionService; GenericConversionService gConversionService = (GenericConversionService) conversionService;
gConversionService.addConverter(new Converter<Class<?>, String>() {
public String convert(Class<?> source) { gConversionService.addConverter(new ClassToStringConverter());
return source.getName(); gConversionService.addConverter(new ObjectToStringConverter());
}
});
if (conversionService != null) { if (conversionService != null) {
this.evaluationContext.setTypeConverter(new StandardTypeConverter(gConversionService)); 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 @Override
protected Object handleRequestMessage(Message<?> requestMessage) { protected Object handleRequestMessage(Message<?> requestMessage) {
String uri = this.uriExpression.getValue(this.evaluationContext, requestMessage, String.class); 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 Mark Fisher
* @author Oleg Zhurakousky * @author Oleg Zhurakousky
* @author Gary Russell * @author Gary Russell
* @author Gunnar Hillert
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration @ContextConfiguration
@@ -73,21 +74,21 @@ public class HttpInboundChannelAdapterParserTests {
@Autowired @Autowired
private HttpRequestHandlingMessagingGateway putOrDeleteAdapter; private HttpRequestHandlingMessagingGateway putOrDeleteAdapter;
@Autowired @Autowired
private HttpRequestHandlingMessagingGateway withMappedHeaders; private HttpRequestHandlingMessagingGateway withMappedHeaders;
@Autowired @Autowired
private HttpRequestHandlingMessagingGateway inboundAdapterWithExpressions; private HttpRequestHandlingMessagingGateway inboundAdapterWithExpressions;
@Autowired @Autowired
@Qualifier("/fname/{blah}/lname/{boo}") @Qualifier("/fname/{blah}/lname/{boo}")
private HttpRequestHandlingMessagingGateway inboundAdapterWithNameAndExpressions; private HttpRequestHandlingMessagingGateway inboundAdapterWithNameAndExpressions;
@Autowired @Autowired
@Qualifier("/fname/{f}/lname/{l}") @Qualifier("/fname/{f}/lname/{l}")
private HttpRequestHandlingMessagingGateway inboundAdapterWithNameNoPath; private HttpRequestHandlingMessagingGateway inboundAdapterWithNameNoPath;
@Autowired @Autowired
private HttpRequestHandlingController inboundController; private HttpRequestHandlingController inboundController;
@@ -117,12 +118,12 @@ public class HttpInboundChannelAdapterParserTests {
assertEquals("bar", map.getFirst("foo")); assertEquals("bar", map.getFirst("foo"));
assertNotNull(TestUtils.getPropertyValue(defaultAdapter, "errorChannel")); assertNotNull(TestUtils.getPropertyValue(defaultAdapter, "errorChannel"));
} }
@Test @Test
public void getRequestWithHeaders() throws Exception { public void getRequestWithHeaders() throws Exception {
DefaultHttpHeaderMapper headerMapper = DefaultHttpHeaderMapper headerMapper =
(DefaultHttpHeaderMapper) TestUtils.getPropertyValue(withMappedHeaders, "headerMapper"); (DefaultHttpHeaderMapper) TestUtils.getPropertyValue(withMappedHeaders, "headerMapper");
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.set("foo", "foo"); headers.set("foo", "foo");
headers.set("bar", "bar"); headers.set("bar", "bar");
@@ -132,7 +133,7 @@ public class HttpInboundChannelAdapterParserTests {
assertEquals("foo", map.get("foo")); assertEquals("foo", map.get("foo"));
assertEquals("bar", map.get("bar")); assertEquals("bar", map.get("bar"));
} }
@Test @Test
// INT-1677 // INT-1677
public void withExpressions() throws Exception { public void withExpressions() throws Exception {
@@ -142,7 +143,7 @@ public class HttpInboundChannelAdapterParserTests {
request.setParameter("foo", "bar"); request.setParameter("foo", "bar");
request.setContent("hello".getBytes()); request.setContent("hello".getBytes());
request.setRequestURI("/fname/bill/lname/clinton"); request.setRequestURI("/fname/bill/lname/clinton");
MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletResponse response = new MockHttpServletResponse();
inboundAdapterWithExpressions.handleRequest(request, response); inboundAdapterWithExpressions.handleRequest(request, response);
assertEquals(HttpServletResponse.SC_OK, response.getStatus()); assertEquals(HttpServletResponse.SC_OK, response.getStatus());
@@ -163,7 +164,7 @@ public class HttpInboundChannelAdapterParserTests {
request.setParameter("foo", "bar"); request.setParameter("foo", "bar");
request.setContent("hello".getBytes()); request.setContent("hello".getBytes());
request.setRequestURI("/fname/bill/lname/clinton"); request.setRequestURI("/fname/bill/lname/clinton");
MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletResponse response = new MockHttpServletResponse();
inboundAdapterWithNameAndExpressions.handleRequest(request, response); inboundAdapterWithNameAndExpressions.handleRequest(request, response);
assertEquals(HttpServletResponse.SC_OK, response.getStatus()); assertEquals(HttpServletResponse.SC_OK, response.getStatus());
@@ -174,7 +175,7 @@ public class HttpInboundChannelAdapterParserTests {
assertEquals("bill", payload); assertEquals("bill", payload);
assertEquals("clinton", message.getHeaders().get("lname")); assertEquals("clinton", message.getHeaders().get("lname"));
} }
@Test(expected=SpelEvaluationException.class) @Test(expected=SpelEvaluationException.class)
// INT-1677 // INT-1677
public void withNameAndExpressionsNoPath() throws Exception { public void withNameAndExpressionsNoPath() throws Exception {
@@ -184,7 +185,7 @@ public class HttpInboundChannelAdapterParserTests {
request.setParameter("foo", "bar"); request.setParameter("foo", "bar");
request.setContent("hello".getBytes()); request.setContent("hello".getBytes());
request.setRequestURI("/fname/bill/lname/clinton"); request.setRequestURI("/fname/bill/lname/clinton");
MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletResponse response = new MockHttpServletResponse();
inboundAdapterWithNameNoPath.handleRequest(request, response); inboundAdapterWithNameNoPath.handleRequest(request, response);
assertEquals(HttpServletResponse.SC_OK, response.getStatus()); assertEquals(HttpServletResponse.SC_OK, response.getStatus());
@@ -195,8 +196,8 @@ public class HttpInboundChannelAdapterParserTests {
assertEquals("hello", payload); // default payload assertEquals("hello", payload); // default payload
assertNull(message.getHeaders().get("lname")); assertNull(message.getHeaders().get("lname"));
} }
@Test @Test
public void getRequestNotAllowed() throws Exception { public void getRequestNotAllowed() throws Exception {
@@ -215,7 +216,11 @@ public class HttpInboundChannelAdapterParserTests {
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST"); request.setMethod("POST");
request.setContent("test".getBytes()); 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(); MockHttpServletResponse response = new MockHttpServletResponse();
postOnlyAdapter.handleRequest(request, response); postOnlyAdapter.handleRequest(request, response);
assertEquals(HttpServletResponse.SC_OK, response.getStatus()); assertEquals(HttpServletResponse.SC_OK, response.getStatus());
@@ -237,7 +242,11 @@ public class HttpInboundChannelAdapterParserTests {
ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
new ObjectOutputStream(byteStream).writeObject(obj); new ObjectOutputStream(byteStream).writeObject(obj);
request.setContent(byteStream.toByteArray()); 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(); MockHttpServletResponse response = new MockHttpServletResponse();
postOnlyAdapter.handleRequest(request, response); postOnlyAdapter.handleRequest(request, response);
assertEquals(HttpServletResponse.SC_OK, response.getStatus()); assertEquals(HttpServletResponse.SC_OK, response.getStatus());

View File

@@ -59,6 +59,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Iwein Fuld * @author Iwein Fuld
* @author Oleg Zhurakousky * @author Oleg Zhurakousky
* @author Gary Russell * @author Gary Russell
* @author Gunnar Hillert
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration @ContextConfiguration
@@ -109,10 +110,14 @@ public class HttpInboundGatewayParserTests {
request.setMethod("GET"); request.setMethod("GET");
request.addHeader("Accept", "application/x-java-serialized-object"); request.addHeader("Accept", "application/x-java-serialized-object");
request.setParameter("foo", "bar"); request.setParameter("foo", "bar");
MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletResponse response = new MockHttpServletResponse();
gateway.handleRequest(request, response); gateway.handleRequest(request, response);
assertThat(response.getStatus(), is(HttpServletResponse.SC_OK)); 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 @Test

View File

@@ -113,7 +113,9 @@ public class HttpOutboundGatewayWithMethodExpression {
String response = null; String response = null;
if (requestMethod.equalsIgnoreCase(this.httpMethod)){ if (requestMethod.equalsIgnoreCase(this.httpMethod)){
response = httpMethod; response = httpMethod;
t.getResponseHeaders().add("Content-Type", "text/plain"); //Required for Spring 3.0.x
t.sendResponseHeaders(200, response.length()); t.sendResponseHeaders(200, response.length());
} }
else { else {
response = "Request is NOT valid"; 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.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.integration.Message; import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel; import org.springframework.integration.MessageChannel;
@@ -139,6 +140,7 @@ public class OutboundResponseTypeTests {
String response = null; String response = null;
if (requestMethod.equalsIgnoreCase(this.httpMethod)){ if (requestMethod.equalsIgnoreCase(this.httpMethod)){
response = httpMethod; response = httpMethod;
t.getResponseHeaders().add("Content-Type", MediaType.TEXT_PLAIN.toString()); //Required for Spring 3.0.x
t.sendResponseHeaders(200, response.length()); t.sendResponseHeaders(200, response.length());
} }
else { else {

View File

@@ -48,6 +48,7 @@ import org.springframework.web.servlet.View;
/** /**
* @author Mark Fisher * @author Mark Fisher
* @author Gary Russell * @author Gary Russell
* @author Gunnar Hillert
* @since 2.0 * @since 2.0
*/ */
public class HttpRequestHandlingControllerTests { public class HttpRequestHandlingControllerTests {
@@ -61,7 +62,11 @@ public class HttpRequestHandlingControllerTests {
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST"); request.setMethod("POST");
request.setContent("hello".getBytes()); 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(); MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView modelAndView = controller.handleRequest(request, response); ModelAndView modelAndView = controller.handleRequest(request, response);
assertEquals("foo", modelAndView.getViewName()); assertEquals("foo", modelAndView.getViewName());
@@ -81,7 +86,11 @@ public class HttpRequestHandlingControllerTests {
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST"); request.setMethod("POST");
request.setContent("hello".getBytes()); 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(); MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView modelAndView = controller.handleRequest(request, response); ModelAndView modelAndView = controller.handleRequest(request, response);
assertEquals("baz", modelAndView.getViewName()); assertEquals("baz", modelAndView.getViewName());
@@ -106,8 +115,12 @@ public class HttpRequestHandlingControllerTests {
controller.setViewName("foo"); controller.setViewName("foo");
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST"); 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(); MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView modelAndView = controller.handleRequest(request, response); ModelAndView modelAndView = controller.handleRequest(request, response);
assertEquals("foo", modelAndView.getViewName()); assertEquals("foo", modelAndView.getViewName());
@@ -191,7 +204,11 @@ public class HttpRequestHandlingControllerTests {
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST"); request.setMethod("POST");
request.setContent("howdy".getBytes()); 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(); MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView modelAndView = controller.handleRequest(request, response); ModelAndView modelAndView = controller.handleRequest(request, response);
assertEquals("foo", modelAndView.getViewName()); assertEquals("foo", modelAndView.getViewName());
@@ -218,7 +235,11 @@ public class HttpRequestHandlingControllerTests {
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST"); request.setMethod("POST");
request.setContent("abc".getBytes()); 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(); MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView modelAndView = controller.handleRequest(request, response); ModelAndView modelAndView = controller.handleRequest(request, response);
assertEquals("foo", modelAndView.getViewName()); assertEquals("foo", modelAndView.getViewName());
@@ -279,7 +300,11 @@ public class HttpRequestHandlingControllerTests {
final MockHttpServletRequest request = new MockHttpServletRequest(); final MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST"); request.setMethod("POST");
request.setContent("hello".getBytes()); 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(); MockHttpServletResponse response = new MockHttpServletResponse();
final AtomicInteger active = new AtomicInteger(); final AtomicInteger active = new AtomicInteger();
final AtomicBoolean expected503 = new AtomicBoolean(); final AtomicBoolean expected503 = new AtomicBoolean();

View File

@@ -45,6 +45,7 @@ import org.springframework.util.SerializationUtils;
/** /**
* @author Mark Fisher * @author Mark Fisher
* @author Gary Russell * @author Gary Russell
* @author Gunnar Hillert
* @since 2.0 * @since 2.0
*/ */
public class HttpRequestHandlingMessagingGatewayTests { public class HttpRequestHandlingMessagingGatewayTests {
@@ -76,7 +77,11 @@ public class HttpRequestHandlingMessagingGatewayTests {
gateway.setRequestChannel(requestChannel); gateway.setRequestChannel(requestChannel);
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST"); 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()); request.setContent("hello".getBytes());
MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletResponse response = new MockHttpServletResponse();
gateway.handleRequest(request, response); gateway.handleRequest(request, response);
@@ -101,7 +106,11 @@ public class HttpRequestHandlingMessagingGatewayTests {
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST"); request.setMethod("POST");
request.addHeader("Accept", "x-application/octet-stream"); 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()); request.setContent("hello".getBytes());
MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletResponse response = new MockHttpServletResponse();
gateway.handleRequest(request, response); gateway.handleRequest(request, response);
@@ -122,7 +131,11 @@ public class HttpRequestHandlingMessagingGatewayTests {
gateway.setRequestChannel(requestChannel); gateway.setRequestChannel(requestChannel);
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST"); 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()); request.setContent("hello".getBytes());
MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletResponse response = new MockHttpServletResponse();
gateway.handleRequest(request, response); gateway.handleRequest(request, response);
@@ -183,7 +196,11 @@ public class HttpRequestHandlingMessagingGatewayTests {
gateway.setRequestPayloadType(TestBean.class); gateway.setRequestPayloadType(TestBean.class);
gateway.setRequestChannel(channel); gateway.setRequestChannel(channel);
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/test"); 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 testBean = new TestBean();
testBean.setName("T. Bean"); testBean.setName("T. Bean");
testBean.setAge(42); testBean.setAge(42);

View File

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

View File

@@ -67,11 +67,13 @@ public class CachingClientConnectionFactory extends AbstractClientConnectionFact
} }
@Override @Override
@SuppressWarnings("deprecation")
public synchronized void setPoolSize(int poolSize) { public synchronized void setPoolSize(int poolSize) {
this.pool.setPoolSize(poolSize); this.pool.setPoolSize(poolSize);
} }
@Override @Override
@SuppressWarnings("deprecation")
public int getPoolSize() { public int getPoolSize() {
return this.pool.getPoolSize(); return this.pool.getPoolSize();
} }

View File

@@ -112,6 +112,7 @@ public class TcpNioSSLConnection extends TcpNioConnection {
* is handled by the thread running in the {@link SSLChannelOutputStream#doWrite(ByteBuffer)} * is handled by the thread running in the {@link SSLChannelOutputStream#doWrite(ByteBuffer)}
* method, which is awoken here, as a result of reaching that stage in the handshaking. * method, which is awoken here, as a result of reaching that stage in the handshaking.
*/ */
@SuppressWarnings("fallthrough")
private SSLEngineResult decode(ByteBuffer networkBuffer) throws IOException { private SSLEngineResult decode(ByteBuffer networkBuffer) throws IOException {
SSLEngineResult result = new SSLEngineResult(Status.OK, this.sslEngine.getHandshakeStatus(), 0, 0); SSLEngineResult result = new SSLEngineResult(Status.OK, this.sslEngine.getHandshakeStatus(), 0, 0);
HandshakeStatus handshakeStatus = this.sslEngine.getHandshakeStatus(); HandshakeStatus handshakeStatus = this.sslEngine.getHandshakeStatus();

View File

@@ -67,14 +67,19 @@
The CI build runs with the default profile. The CI build runs with the default profile.
--> -->
<beans profile="remote"> <!-- Commented out for Spring 3.0.x backwards compatibility
<bean id="clientConnector" class="org.springframework.jmx.support.MBeanServerConnectionFactoryBean">
<property name="serviceUrl" value="service:jmx:rmi://localhost/jndi/rmi://localhost:11099/jmxrmi"/>
</bean>
</beans>
<beans profile="default"> <beans profile="remote">
<context:mbean-server id="clientConnector"/> <bean id="clientConnector" class="org.springframework.jmx.support.MBeanServerConnectionFactoryBean">
</beans> <property name="serviceUrl" value="service:jmx:rmi://localhost/jndi/rmi://localhost:11099/jmxrmi"/>
</bean>
</beans>
<beans profile="default">
<context:mbean-server id="clientConnector"/>
</beans>
-->
<context:mbean-server id="clientConnector"/>
</beans> </beans>

View File

@@ -20,7 +20,6 @@ import javax.sql.DataSource;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.ejb.Ejb3Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport; import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@@ -51,14 +50,13 @@ public class HibernateJpaOperationsTests extends AbstractJpaOperationsTests {
@Test @Test
public void generateDdl() { public void generateDdl() {
final Ejb3Configuration cfg = new Ejb3Configuration(); final org.hibernate.ejb.Ejb3Configuration cfg = new org.hibernate.ejb.Ejb3Configuration();
Map properties = fb.getJpaPropertyMap();
Map<String, Object> properties = fb.getJpaPropertyMap();
properties.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect"); properties.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
final Ejb3Configuration configured = cfg.configure( fb.getPersistenceUnitInfo(), fb.getJpaPropertyMap() ); final org.hibernate.ejb.Ejb3Configuration configured = cfg.configure( fb.getPersistenceUnitInfo(), fb.getJpaPropertyMap() );
final Configuration configuration = configured.getHibernateConfiguration(); final Configuration configuration = configured.getHibernateConfiguration();
final SchemaExport schemaExport; final SchemaExport schemaExport;

View File

@@ -24,7 +24,6 @@ import org.springframework.integration.MessagingException;
import org.springframework.integration.jpa.test.JpaTestUtils; import org.springframework.integration.jpa.test.JpaTestUtils;
import org.springframework.integration.jpa.test.entity.StudentDomain; import org.springframework.integration.jpa.test.entity.StudentDomain;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration; import org.springframework.test.context.transaction.TransactionConfiguration;
@@ -53,7 +52,6 @@ public class JpaOutboundGatewayTests {
this.jdbcTemplate.execute("delete from Student where rollNumber > 1003"); this.jdbcTemplate.execute("delete from Student where rollNumber > 1003");
} }
@Test @Test
public void getStudent() { public void getStudent() {
final StudentDomain student = studentService.getStudent(1001L); final StudentDomain student = studentService.getStudent(1001L);
@@ -61,7 +59,6 @@ public class JpaOutboundGatewayTests {
} }
@Test @Test
@Transactional
public void deleteNonExistingStudent() { public void deleteNonExistingStudent() {
StudentDomain student = JpaTestUtils.getTestStudent(); StudentDomain student = JpaTestUtils.getTestStudent();

View File

@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:jpa="http://www.springframework.org/schema/integration/jpa" xmlns:jpa="http://www.springframework.org/schema/integration/jpa"
xmlns:task="http://www.springframework.org/schema/task" xmlns:task="http://www.springframework.org/schema/task"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
@@ -24,7 +23,9 @@
<jdbc:script location="classpath:H2-PopulateData.sql" /> <jdbc:script location="classpath:H2-PopulateData.sql" />
</jdbc:initialize-database> </jdbc:initialize-database>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" c:dataSource-ref="dataSource"/> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="dataSource"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/> <tx:annotation-driven transaction-manager="transactionManager"/>

View File

@@ -98,6 +98,7 @@ public class XPathExpressionParser extends AbstractSingleBeanDefinitionParser {
} }
} }
@SuppressWarnings("deprecation")
protected Map<?,?> parseNamespaceMapElement(Element element, ParserContext parserContext, BeanDefinition parentDefinition) { protected Map<?,?> parseNamespaceMapElement(Element element, ParserContext parserContext, BeanDefinition parentDefinition) {
BeanDefinitionParserDelegate beanParser = new BeanDefinitionParserDelegate(parserContext.getReaderContext()); BeanDefinitionParserDelegate beanParser = new BeanDefinitionParserDelegate(parserContext.getReaderContext());
beanParser.initDefaults(element.getOwnerDocument().getDocumentElement()); beanParser.initDefaults(element.getOwnerDocument().getDocumentElement());