Skip to content

Commit

Permalink
Fix FunctionConfiguration.sanitize() for generics
Browse files Browse the repository at this point in the history
The `FunctionConfiguration.sanitize()` use a `rawtypes` trying to hide
generics routines.

Spring Integration 6.4 has introduced a `BaseMessageBuilder` which does not work
with `rawtypes`.

* Fix `FunctionConfiguration.sanitize()` to expose a `<P>` generic argument
to satisfy a new `MessageBuilder` byte code, plus to meet all the expectations
of this method consumers
* In addition perform some code clean to optimize a usage of `MessageBuilder`:
 - `setHeader()` does set the value overriding existing one
 - `setHeader()` removes the entry if provided value is `null`
 - This way we just can go ahead with `MessageBuilder` method chain avoiding extra conditions
  • Loading branch information
artembilan committed Nov 4, 2024
1 parent ffb62cb commit 17ac635
Showing 1 changed file with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -389,17 +389,13 @@ private <T> Message<T> wrapToMessageIfNecessary(T value) {
: MessageBuilder.withPayload(value).build();
}

@SuppressWarnings({ "unchecked", "rawtypes" })
private static Message sanitize(Message inputMessage) {
MessageBuilder builder = MessageBuilder
.fromMessage(inputMessage)
.removeHeader("spring.cloud.stream.sendto.destination")
.removeHeader(MessageUtils.SOURCE_TYPE);
if (builder.getHeaders().containsKey(MessageUtils.TARGET_PROTOCOL)) {
builder = builder.setHeader(MessageUtils.SOURCE_TYPE, builder.getHeaders().get(MessageUtils.TARGET_PROTOCOL));
}
builder = builder.removeHeader(MessageUtils.TARGET_PROTOCOL);
return builder.build();
private static <P> Message<P> sanitize(Message<P> inputMessage) {
return MessageBuilder
.fromMessage(inputMessage)
.removeHeader("spring.cloud.stream.sendto.destination")
.setHeader(MessageUtils.SOURCE_TYPE, inputMessage.getHeaders().get(MessageUtils.TARGET_PROTOCOL))
.removeHeader(MessageUtils.TARGET_PROTOCOL)
.build();
}

private static class FunctionToDestinationBinder implements InitializingBean, ApplicationContextAware {
Expand Down

0 comments on commit 17ac635

Please sign in to comment.