INT-2712 Fix ConversionService Initialization

Fix initialization of the ConversionService logic
in HttpRequestExecutingMessageHandler to NOT throw an exception if
ConversionService is not an instance of GenericConversionService.

Check for ConfigurableConversionService instead.

INT-2712 polishing

INT-2712 Polishing Tests
This commit is contained in:
Oleg Zhurakousky
2012-08-10 08:43:19 -04:00
committed by Gary Russell
parent c2d6486f9b
commit ad3af54ed6
2 changed files with 54 additions and 6 deletions

View File

@@ -32,6 +32,7 @@ import org.springframework.context.expression.BeanFactoryResolver;
import org.springframework.context.expression.MapAccessor;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.support.ConfigurableConversionService;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.expression.Expression;
import org.springframework.expression.common.LiteralExpression;
@@ -290,13 +291,19 @@ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMe
if (conversionService == null){
conversionService = new GenericConversionService();
}
Assert.isInstanceOf(GenericConversionService.class, conversionService);
GenericConversionService gConversionService = (GenericConversionService) conversionService;
if (conversionService instanceof ConfigurableConversionService){
ConfigurableConversionService configurableConversionService =
(ConfigurableConversionService) conversionService;
gConversionService.addConverter(new ClassToStringConverter());
gConversionService.addConverter(new ObjectToStringConverter());
configurableConversionService.addConverter(new ClassToStringConverter());
configurableConversionService.addConverter(new ObjectToStringConverter());
this.evaluationContext.setTypeConverter(new StandardTypeConverter(gConversionService));
this.evaluationContext.setTypeConverter(new StandardTypeConverter(configurableConversionService));
}
else {
logger.warn("ConversionService is not an instance of ConfigurableConversionService therefore" +
"ClassToStringConverter and ObjectToStringConverter will not be registered");
}
}
private class ClassToStringConverter implements Converter<Class<?>, String> {