Skip to content

INT-4397: Fix headers filtering for @Transformer #2445

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

Merged
merged 2 commits into from
May 16, 2018

Conversation

artembilan
Copy link
Member

JIRA: https://jira.spring.io/browse/INT-4397

The AbstractMessageProcessingTransformer doesn't honor a configured
notPropagatedHeaders and copies all the request headers to the
message to return

  • Add setNotPropagatedHeaders() into the AbstractMessageProcessingTransformer
    and implement there a logic to filter headers, similar to what we have
    in the AbstractMessageProducingHandler
  • Overrider updateNotPropagatedHeaders() in the MessageTransformingHandler
    to propagate notPropagatedHeaders to the AbstractMessageProcessingTransformer
    delegate

@@ -139,7 +139,7 @@ public void setNotPropagatedHeaders(String... headers) {
* @param merge true to merge with existing patterns; false to replace.
* @since 5.0.2
*/
protected final void updateNotPropagatedHeaders(String[] headers, boolean merge) {
protected void updateNotPropagatedHeaders(String[] headers, boolean merge) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be final - it is called from a CTOR in SIK.

The javadoc explicitly explains that.

                    Exposed so that subclasses can set specific
 * headers in a constructor, since {@link #setNotPropagatedHeaders(String...)} is not
 * final.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I see now JavaDocs. Not sure why I have missed to read them 😢

The problem that this method nowhere is used from the ctor...

What am I missing? Maybe we should just relax this method and let end-user to deal with it on its own?

I think otherwise I will override the setter and adder in the MessageTransformingHandler.

Thanks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KafkaProducerMessageHandler CTOR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, but those headers are not mapped by the AbstractKafkaHeaderMapper anyway.
Don't we use there a headerMapper for gateway reply messages?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has nothing to do with header mapping either outbound or reply; those headers might be present on the outbound message received by the gateway, and we don't want them to appear in the reply message. Hence they are added to the notPropagatedHeaders.

getMessageBuilderFactory()
.withPayload(result);

if (this.selectiveHeaderPropagation) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should move this to a utility to avoid duplicating code (be careful about tangles, though 😄 )

JIRA: https://jira.spring.io/browse/INT-4397

The `AbstractMessageProcessingTransformer` doesn't honor a configured
`notPropagatedHeaders` and copies all the request headers to the
message to return

* Add `setNotPropagatedHeaders()` into the `AbstractMessageProcessingTransformer`
and implement there a logic to filter headers, similar to what we have
in the `AbstractMessageProducingHandler`
* Overrider `updateNotPropagatedHeaders()` in the `MessageTransformingHandler`
to propagate `notPropagatedHeaders` to the `AbstractMessageProcessingTransformer`
delegate
…opagatedHeaders()`

* Override `addNotPropagatedHeaders()` for the `MessageTransformingHandler()`
and populate `notPropagatedHeaders` into the target `AbstractMessageProcessingTransformer`
from there
* Also populate `notPropagatedHeaders` from the `AbstractMessageProcessingTransformer.doInit()`
* Implement a `AbstractIntegrationMessageBuilder.filterAndCopyHeadersIfAbsent()`
for a general logic to filter `notPropagatedHeaders` and copy the result
headers set into the target message if they are absent
* Use an new `filterAndCopyHeadersIfAbsent()` in the `AbstractMessageProducingHandler`
and `AbstractMessageProcessingTransformer`to avoid code block duplication
@garyrussell garyrussell merged commit 470d6d8 into spring-projects:master May 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants