Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Integration Http Module has test failures against 3.0.7.RELEASE [INT-2694] #6670

Closed
spring-operator opened this issue Jul 30, 2012 · 2 comments

Comments

@spring-operator
Copy link
Contributor

spring-operator commented Jul 30, 2012

Gunnar Hillert opened INT-2694 and commented


Affects: 2.2 M4 Sprint 2

This issue is a sub-task of #6666

Issue Links:

@spring-operator
Copy link
Contributor Author

Gunnar Hillert commented

In Spring 3.0.7.RELEASE don't use:

  • MockHttpServletRequest#setContentType()
  • MockHttpServletResponse#getContentType()

Instead do e.g.:

request.addHeader("Content-Type", "application/x-java-serialized-object");

@spring-operator
Copy link
Contributor Author

spring-operator commented Jul 31, 2012

Gunnar Hillert commented

One of the failing tests, when using Spring 3.0.7.RELEASE, was introduced with Spring Integration 2.2 as part of #5753:

OutboundResponseTypeTests#testWithResponseTypeExpressionSetAsClass()

In class HttpRequestExecutingMessageHandler we declare (and add to the conversionService) an anonymous converter, which converts a Class to a String. This works for Spring 3.1.2.RELEASE - but Spring 3.0.7 wants to do an Object-to-String conversion instead.

Reason:


In 3.1.2.RELEASE:

class ReflectivePropertyAccessor#read {
   .... return new TypedValue(value, typeDescriptor.narrow(value));
}

In 3.0.7.RELEASE:

class ReflectivePropertyAccessor#read {
   .... return new TypedValue(((Method) member).invoke(target), typeDescriptor);
}

The narrow method is new in Spring 3.1. What happens is basically that the TypeDescriptor for Message.getPayload points to java.lang.Object. In 3.1, Spring does a bit of "fine-tuning", sees that the actually returned value is of type java.lang.Class and uses that instead.

Solution:


I have refactored out the anonymous converter class and added an additional converter:

private class ClassToStringConverter implements Converter<Class<?>, String> {
    public String convert(Class<?> source) {
        return source.getName();
    }
}

private class ObjectToStringConverter implements Converter<Object, String> {
    public String convert(Object source) {
        if (source instanceof Class) {
            return ((Class<?>) source).getName();
        }
        return source.toString();
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant