INT-4288: Add blacklist headers at runtime
JIRA: https://jira.spring.io/browse/INT-4288 - Add `AbstractMessageProducingHandler.addNotPropagatedHeaders()` so that new headers can be added without overriding existing ones. - Add `AbstractMessageProducingHandler.getNotPropagatedHeaders()` so that existing excluded headers can be consulted. * Polishing JavaDocs and imports order **Cherry-pick to 4.3.x**
This commit is contained in:
committed by
Artem Bilan
parent
f58106ec3c
commit
ecc3006179
@@ -17,6 +17,7 @@
|
||||
package org.springframework.integration.handler;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -56,6 +57,7 @@ import reactor.core.publisher.Mono;
|
||||
* @author David Liu
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
* @author Marius Bogoevici
|
||||
*
|
||||
* since 4.1
|
||||
*/
|
||||
@@ -119,14 +121,44 @@ public abstract class AbstractMessageProducingHandler extends AbstractMessageHan
|
||||
* @since 4.3.10
|
||||
*/
|
||||
public void setNotPropagatedHeaders(String... headers) {
|
||||
updateNotPropagatedHeaders(headers, false);
|
||||
}
|
||||
|
||||
private void updateNotPropagatedHeaders(String[] headers, boolean merge) {
|
||||
if (!ObjectUtils.isEmpty(headers)) {
|
||||
Assert.noNullElements(headers, "null elements are not allowed in 'headers'");
|
||||
this.notPropagatedHeaders.clear();
|
||||
if (!merge) {
|
||||
this.notPropagatedHeaders.clear();
|
||||
}
|
||||
this.notPropagatedHeaders.addAll(Arrays.asList(headers));
|
||||
}
|
||||
this.selectiveHeaderPropagation = this.notPropagatedHeaders.size() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the header names this handler doesn't propagate.
|
||||
* @return an immutable {@link java.util.Collection} of headers that will
|
||||
* not be copied from the inbound message if
|
||||
* {@link #shouldCopyRequestHeaders()} is true.
|
||||
* @since 4.3.10
|
||||
* @see #setNotPropagatedHeaders(String...)
|
||||
*/
|
||||
public Collection<String> getNotPropagatedHeaders() {
|
||||
return Collections.unmodifiableSet(this.notPropagatedHeaders);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add headers that will NOT be copied from the inbound message if
|
||||
* {@link #shouldCopyRequestHeaders()} is true, instead of overwriting
|
||||
* the existing set.
|
||||
* @param headers the headers to not propagate from the inbound message.
|
||||
* @since 4.3.10
|
||||
* @see #setNotPropagatedHeaders(String...)
|
||||
*/
|
||||
public void addNotPropagatedHeaders(String... headers) {
|
||||
updateNotPropagatedHeaders(headers, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onInit() throws Exception {
|
||||
super.onInit();
|
||||
|
||||
Reference in New Issue
Block a user