Make header-enricher &header-filter functions as auto-config

* Fix Checkstyle violations in those module
This commit is contained in:
Artem Bilan
2024-01-10 10:09:31 -05:00
parent 97c3be83af
commit e1874eee92
13 changed files with 32 additions and 40 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2020-2022 the original author or authors.
* Copyright 2020-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@ import java.util.Properties;
import java.util.function.Function;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -33,6 +32,8 @@ import org.springframework.integration.transformer.support.ExpressionEvaluatingH
import org.springframework.messaging.Message;
/**
* Auto-configuration for Header Enricher function.
*
* @author Gary Russell
* @author Christian Tzolov
* @author Soby Chacko
@@ -43,18 +44,15 @@ import org.springframework.messaging.Message;
@ConditionalOnProperty(prefix = "header.enricher", value = "headers")
public class HeaderEnricherFunctionConfiguration {
@Autowired
private HeaderEnricherFunctionProperties properties;
@Bean
public Function<Message<?>, Message<?>> headerEnricherFunction(HeaderEnricher headerEnricher) {
return headerEnricher::transform;
}
@Bean
public HeaderEnricher headerEnricher(BeanFactory beanFactory) {
public HeaderEnricher headerEnricher(HeaderEnricherFunctionProperties properties, BeanFactory beanFactory) {
Map<String, ExpressionEvaluatingHeaderValueMessageProcessor<?>> headersToAdd = new HashMap<>();
Properties props = this.properties.getHeaders();
Properties props = properties.getHeaders();
Enumeration<?> enumeration = props.propertyNames();
while (enumeration.hasMoreElements()) {
String propertyName = (String) enumeration.nextElement();
@@ -64,7 +62,7 @@ public class HeaderEnricherFunctionConfiguration {
headersToAdd.put(propertyName, headerValueMessageProcessor);
}
HeaderEnricher headerEnricher = new HeaderEnricher(headersToAdd);
headerEnricher.setDefaultOverwrite(this.properties.isOverwrite());
headerEnricher.setDefaultOverwrite(properties.isOverwrite());
return headerEnricher;
}

View File

@@ -0,0 +1,4 @@
/**
* The Header Enricher function support classes.
*/
package org.springframework.cloud.fn.header.enricher;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2020-2020 the original author or authors.
* Copyright 2020-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -59,7 +59,7 @@ public class HeaderEnricherFunctionApplicationTests {
static class HeaderEnricherFunctionTestApplication {
@Bean
public String value() {
String value() {
return "beanValue";
}