Skip to content

Commit

Permalink
GH-1920 Add MessageConverter filtering logic
Browse files Browse the repository at this point in the history
This way we ensure that only custom converters and converters defined by stream are included
effectively eliminating the possibility of other auto-configuration interfering with their converters

Resolves #1920
  • Loading branch information
olegz committed Mar 2, 2020
1 parent ad7bf95 commit eee1b13
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Role;
import org.springframework.integration.context.IntegrationContextUtils;
import org.springframework.integration.support.converter.DefaultDatatypeChannelMessageConverter;
import org.springframework.messaging.converter.CompositeMessageConverter;
import org.springframework.messaging.converter.MessageConverter;

Expand All @@ -47,12 +46,26 @@ public CompositeMessageConverter configurableCompositeMessageConverter(
List<MessageConverter> customMessageConverters) {

customMessageConverters = customMessageConverters.stream()
.filter(c -> !(c instanceof DefaultDatatypeChannelMessageConverter)).collect(Collectors.toList());
.filter(c -> isConverterEligible(c)).collect(Collectors.toList());

CompositeMessageConverterFactory factory =
new CompositeMessageConverterFactory(customMessageConverters, objectMapperObjectProvider.getIfAvailable(ObjectMapper::new));

return factory.getMessageConverterForAllRegistered();
}

/*
* We want to filter out all non-stream MessageConverters, given that other
* auto-configurations may interfere with their MessageConverters.
*/
private boolean isConverterEligible(Object messageConverter) {
String messageConverterName = messageConverter.getClass().getName();
if (messageConverterName.startsWith("org.springframework.cloud.")) {
return true;
}
else if (!messageConverterName.startsWith("org.springframework.")) {
return true;
}
return false;
}
}

0 comments on commit eee1b13

Please sign in to comment.