INT-1953 refactored CORE and HTTP modules to make them compatible with Spring v3.1 while maintaining the target version of 3.0.*

This commit is contained in:
Oleg Zhurakousky
2011-06-24 15:20:04 -04:00
parent b60525a259
commit c00888f537
8 changed files with 47 additions and 9 deletions

View File

@@ -92,13 +92,13 @@ public class MessagePublishingInterceptor implements MethodInterceptor {
String[] argumentNames = this.resolveArgumentNames(method);
context.setVariable(PublisherMetadataSource.METHOD_NAME_VARIABLE_NAME, method.getName());
if (invocation.getArguments().length > 0 && argumentNames != null) {
Map<String, Object> argumentMap = new HashMap<String, Object>();
Map<Object, Object> argumentMap = new HashMap<Object, Object>();
for (int i = 0; i < argumentNames.length; i++) {
if (invocation.getArguments().length <= i) {
break;
}
Object argValue = invocation.getArguments()[i];
argumentMap.put("" + i, argValue);
argumentMap.put(i, argValue);
argumentMap.put(argumentNames[i], argValue);
}
context.setVariable(PublisherMetadataSource.ARGUMENT_MAP_VARIABLE_NAME, argumentMap);

View File

@@ -114,7 +114,7 @@ public class MethodAnnotationPublisherMetadataSource implements PublisherMetadat
if (!StringUtils.hasText(name)) {
name = parameterNames[i];
}
headerExpressions.put(name, "#" + PublisherMetadataSource.ARGUMENT_MAP_VARIABLE_NAME + "['" + i + "']");
headerExpressions.put(name, "#" + PublisherMetadataSource.ARGUMENT_MAP_VARIABLE_NAME + "[" + i + "]");
}
}
}

View File

@@ -19,7 +19,9 @@ package org.springframework.integration.util;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Proxy;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -517,7 +519,15 @@ public class MessagingMethodInvokerHelper<T> extends AbstractExpressionEvaluator
}
else if (Iterator.class.isAssignableFrom(parameterType)) {
if (canProcessMessageList) {
if (parameterTypeDescriptor.getElementType()!=null && Message.class.isAssignableFrom(parameterTypeDescriptor.getElementType())) {
Type type = method.getGenericParameterTypes()[0];
Type parameterizedType = null;
if (type instanceof ParameterizedType){
parameterizedType = ((ParameterizedType)type).getActualTypeArguments()[0];
if (parameterizedType instanceof ParameterizedType){
parameterizedType = ((ParameterizedType) parameterizedType).getRawType();
}
}
if (parameterizedType != null && Message.class.isAssignableFrom((Class<?>)parameterizedType)){
sb.append("messages.iterator()");
}
else {

View File

@@ -16,6 +16,7 @@
package org.springframework.integration.aggregator;
import static junit.framework.Assert.assertTrue;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
@@ -278,6 +279,32 @@ public class MethodInvokingMessageGroupProcessorTests {
Object result = processor.processMessageGroup(messageGroupMock);
assertThat((Integer) ((Message<?>) result).getPayload(), is(7));
}
@Test
public void shouldFindFittingMethodForIteratorOfMessages() {
@SuppressWarnings("unused")
class UnannotatedAggregator {
public Iterator<?> and(Iterator<Message<?>> flags) {
return flags;
}
public void voidMethodShouldBeIgnored(List<Integer> flags) {
fail("this method should not be invoked");
}
public String methodAcceptingNoCollectionShouldBeIgnored(String irrelevant) {
fail("this method should not be invoked");
return null;
}
}
MessageGroupProcessor processor = new MethodInvokingMessageGroupProcessor(new UnannotatedAggregator());
when(messageGroupMock.getUnmarked()).thenReturn(messagesUpForProcessing);
Object result = processor.processMessageGroup(messageGroupMock);
assertTrue(((Message<?>)result).getPayload() instanceof Iterator<?>);
}
@Test(expected = IllegalArgumentException.class)
public void testTwoMethodsWithSameParameterTypesAmbiguous() {

View File

@@ -94,6 +94,7 @@ public class MessagePublishingAnnotationUsageTests {
@Publisher(channel="messagePublishingAnnotationUsageTestChannel")
public String argumentAsPayload(@Payload String fname, @Header String lname) {
System.out.println("###### INVOKING");
return fname + " " + lname;
}
}

View File

@@ -73,8 +73,8 @@ public class MethodAnnotationPublisherMetadataSourceTests {
Map<String, String> headerMap = source.getHeaderExpressions(method);
assertNotNull(headerMap);
assertEquals(2, headerMap.size());
assertEquals("#args['1']", headerMap.get("foo"));
assertEquals("#args['2']", headerMap.get("bar"));
assertEquals("#args[1]", headerMap.get("foo"));
assertEquals("#args[2]", headerMap.get("bar"));
}
@Test

View File

@@ -283,7 +283,7 @@ public class MethodInvokingMessageProcessorTests {
@Test
public void testProcessMessageBadExpression() throws Exception {
// TODO: should this be MessageHandlingException or NumberFormatException?
expected.expect(new ExceptionCauseMatcher(NumberFormatException.class));
expected.expect(new ExceptionCauseMatcher(Exception.class));
AnnotatedTestService service = new AnnotatedTestService();
Method method = service.getClass().getMethod("integerMethod", Integer.class);
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);

View File

@@ -174,11 +174,11 @@ public class DefaultHttpHeaderMapperFromMessageInboundTests {
public void validateETag(){
HeaderMapper<HttpHeaders> mapper = DefaultHttpHeaderMapper.inboundMapper();
Map<String, Object> messageHeaders = new HashMap<String, Object>();
messageHeaders.put("ETag", "1234");
messageHeaders.put("ETag", "\"1234\"");
HttpHeaders headers = new HttpHeaders();
mapper.fromHeaders(new MessageHeaders(messageHeaders), headers);
assertEquals("1234", headers.getETag());
assertEquals("\"1234\"", headers.getETag());
}
// Expires tests