diff --git a/function/spring-header-enricher-function/README.adoc b/function/spring-header-enricher-function/README.adoc index 29f4ff6d..515504e7 100644 --- a/function/spring-header-enricher-function/README.adoc +++ b/function/spring-header-enricher-function/README.adoc @@ -4,7 +4,7 @@ This module provides a header enricher function that can be reused and composed ## Beans for injection -You can import the `HeaderEnricherFunctionConfiguration` in a Spring Boot application and then inject the following bean. +The `HeaderEnricherFunctionConfiguration` auto-configuration provides the following bean: `headerEnricherFunction` diff --git a/function/spring-header-enricher-function/src/main/java/org/springframework/cloud/fn/header/enricher/HeaderEnricherFunctionConfiguration.java b/function/spring-header-enricher-function/src/main/java/org/springframework/cloud/fn/header/enricher/HeaderEnricherFunctionConfiguration.java index 938c5dad..2041f448 100644 --- a/function/spring-header-enricher-function/src/main/java/org/springframework/cloud/fn/header/enricher/HeaderEnricherFunctionConfiguration.java +++ b/function/spring-header-enricher-function/src/main/java/org/springframework/cloud/fn/header/enricher/HeaderEnricherFunctionConfiguration.java @@ -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.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.messaging.Message; /** + * Auto-configuration for Header Enricher function. + * * @author Gary Russell * @author Christian Tzolov * @author Soby Chacko @@ -43,18 +44,15 @@ @ConditionalOnProperty(prefix = "header.enricher", value = "headers") public class HeaderEnricherFunctionConfiguration { - @Autowired - private HeaderEnricherFunctionProperties properties; - @Bean public Function, Message> headerEnricherFunction(HeaderEnricher headerEnricher) { return headerEnricher::transform; } @Bean - public HeaderEnricher headerEnricher(BeanFactory beanFactory) { + public HeaderEnricher headerEnricher(HeaderEnricherFunctionProperties properties, BeanFactory beanFactory) { Map> 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 HeaderEnricher headerEnricher(BeanFactory beanFactory) { headersToAdd.put(propertyName, headerValueMessageProcessor); } HeaderEnricher headerEnricher = new HeaderEnricher(headersToAdd); - headerEnricher.setDefaultOverwrite(this.properties.isOverwrite()); + headerEnricher.setDefaultOverwrite(properties.isOverwrite()); return headerEnricher; } diff --git a/function/spring-header-enricher-function/src/main/java/org/springframework/cloud/fn/header/enricher/package-info.java b/function/spring-header-enricher-function/src/main/java/org/springframework/cloud/fn/header/enricher/package-info.java new file mode 100644 index 00000000..aa4c1e5a --- /dev/null +++ b/function/spring-header-enricher-function/src/main/java/org/springframework/cloud/fn/header/enricher/package-info.java @@ -0,0 +1,4 @@ +/** + * The Header Enricher function support classes. + */ +package org.springframework.cloud.fn.header.enricher; diff --git a/function/spring-header-enricher-function/src/test/java/org/springframework/cloud/fn/header/enricher/HeaderEnricherFunctionApplicationTests.java b/function/spring-header-enricher-function/src/test/java/org/springframework/cloud/fn/header/enricher/HeaderEnricherFunctionApplicationTests.java index 86729ffe..a67974dd 100644 --- a/function/spring-header-enricher-function/src/test/java/org/springframework/cloud/fn/header/enricher/HeaderEnricherFunctionApplicationTests.java +++ b/function/spring-header-enricher-function/src/test/java/org/springframework/cloud/fn/header/enricher/HeaderEnricherFunctionApplicationTests.java @@ -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 void testDefault() { static class HeaderEnricherFunctionTestApplication { @Bean - public String value() { + String value() { return "beanValue"; } diff --git a/function/spring-header-filter-function/README.adoc b/function/spring-header-filter-function/README.adoc index b9c9f93e..741e6145 100644 --- a/function/spring-header-filter-function/README.adoc +++ b/function/spring-header-filter-function/README.adoc @@ -4,7 +4,7 @@ This module provides a header enricher function that can be reused and composed == Beans for injection -You can import the `HeaderEnricherFunctionConfiguration` in a Spring Boot application and then inject the following bean. +The `HeaderEnricherFunctionConfiguration` auto-configuration provides the following bean: `headerFilterFunction` diff --git a/function/spring-header-filter-function/src/main/java/org/springframework/cloud/fn/header/filter/HeaderFilterFunctionConfiguration.java b/function/spring-header-filter-function/src/main/java/org/springframework/cloud/fn/header/filter/HeaderFilterFunctionConfiguration.java index 06767079..1d00a4f0 100644 --- a/function/spring-header-filter-function/src/main/java/org/springframework/cloud/fn/header/filter/HeaderFilterFunctionConfiguration.java +++ b/function/spring-header-filter-function/src/main/java/org/springframework/cloud/fn/header/filter/HeaderFilterFunctionConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2023 the original author or authors. + * Copyright 2023-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. @@ -29,7 +29,7 @@ import org.springframework.util.StringUtils; /** - * Configure a function using {@link HeaderFilter}. + * Auto-configure a function using {@link HeaderFilter}. * * @author Corneil du Plessis */ @@ -38,14 +38,9 @@ @ConditionalOnExpression("'${header.filter.remove}'!='' or '${header.filter.delete-all}' != ''") public class HeaderFilterFunctionConfiguration { - private final HeaderFilterFunctionProperties properties; - - public HeaderFilterFunctionConfiguration(HeaderFilterFunctionProperties properties) { - this.properties = properties; - } - @Bean - public Function, Message> headerFilterFunction() { + public Function, Message> headerFilterFunction(HeaderFilterFunctionProperties properties, + HeaderFilter headerFilter) { if (properties.isDeleteAll()) { return (message) -> { var accessor = new IntegrationMessageHeaderAccessor(message); @@ -56,12 +51,12 @@ public Function, Message> headerFilterFunction() { }; } else { - return headerFilter()::transform; + return headerFilter::transform; } } @Bean - public HeaderFilter headerFilter() { + public HeaderFilter headerFilter(HeaderFilterFunctionProperties properties) { if (properties.getRemove() != null) { String[] remove = StringUtils.tokenizeToStringArray(properties.getRemove(), ", ", true, true); HeaderFilter filter = new HeaderFilter(remove); diff --git a/function/spring-header-filter-function/src/main/java/org/springframework/cloud/fn/header/filter/HeaderFilterFunctionProperties.java b/function/spring-header-filter-function/src/main/java/org/springframework/cloud/fn/header/filter/HeaderFilterFunctionProperties.java index 138c0bd7..5d3570b6 100644 --- a/function/spring-header-filter-function/src/main/java/org/springframework/cloud/fn/header/filter/HeaderFilterFunctionProperties.java +++ b/function/spring-header-filter-function/src/main/java/org/springframework/cloud/fn/header/filter/HeaderFilterFunctionProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2023 the original author or authors. + * Copyright 2023-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. @@ -38,7 +38,7 @@ public class HeaderFilterFunctionProperties { private String remove; public boolean isDeleteAll() { - return deleteAll; + return this.deleteAll; } public void setDeleteAll(boolean deleteAll) { @@ -46,7 +46,7 @@ public void setDeleteAll(boolean deleteAll) { } public String getRemove() { - return remove; + return this.remove; } public void setRemove(String remove) { diff --git a/function/spring-header-filter-function/src/main/java/org/springframework/cloud/fn/header/filter/package-info.java b/function/spring-header-filter-function/src/main/java/org/springframework/cloud/fn/header/filter/package-info.java new file mode 100644 index 00000000..327a50e5 --- /dev/null +++ b/function/spring-header-filter-function/src/main/java/org/springframework/cloud/fn/header/filter/package-info.java @@ -0,0 +1,4 @@ +/** + * The Header Filter function support classes. + */ +package org.springframework.cloud.fn.header.filter; diff --git a/function/spring-header-filter-function/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/function/spring-header-filter-function/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 00000000..64bf7c7c --- /dev/null +++ b/function/spring-header-filter-function/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +org.springframework.cloud.fn.header.filter.HeaderFilterFunctionConfiguration diff --git a/function/spring-header-filter-function/src/test/java/org/springframework/cloud/fn/header/filter/HeaderFilterFunctionApplicationDeleteAllTests.java b/function/spring-header-filter-function/src/test/java/org/springframework/cloud/fn/header/filter/HeaderFilterFunctionApplicationDeleteAllTests.java index d3cf6cef..6c5a9a34 100644 --- a/function/spring-header-filter-function/src/test/java/org/springframework/cloud/fn/header/filter/HeaderFilterFunctionApplicationDeleteAllTests.java +++ b/function/spring-header-filter-function/src/test/java/org/springframework/cloud/fn/header/filter/HeaderFilterFunctionApplicationDeleteAllTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2023 the original author or authors. + * Copyright 2023-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. @@ -22,7 +22,6 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.messaging.Message; @@ -52,10 +51,6 @@ public void testRemoveLeavesIdTimestampAll() { @SpringBootApplication static class HeaderFilterFunctionTestApplication { - public static void main(String[] args) throws Exception { - SpringApplication.main(args); - } - } } diff --git a/function/spring-header-filter-function/src/test/java/org/springframework/cloud/fn/header/filter/HeaderFilterFunctionApplicationTests.java b/function/spring-header-filter-function/src/test/java/org/springframework/cloud/fn/header/filter/HeaderFilterFunctionApplicationTests.java index 3cc112d4..9f45374d 100644 --- a/function/spring-header-filter-function/src/test/java/org/springframework/cloud/fn/header/filter/HeaderFilterFunctionApplicationTests.java +++ b/function/spring-header-filter-function/src/test/java/org/springframework/cloud/fn/header/filter/HeaderFilterFunctionApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2023 the original author or authors. + * Copyright 2023-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. @@ -91,10 +91,6 @@ public void testRemoveLeavesIdTimestampAll() { @SpringBootApplication static class HeaderFilterFunctionTestApplication { - public static void main(String[] main) { - - } - } } diff --git a/function/spring-header-filter-function/src/test/java/org/springframework/cloud/fn/header/filter/HeaderUtils.java b/function/spring-header-filter-function/src/test/java/org/springframework/cloud/fn/header/filter/HeaderUtils.java index 927bb69d..c57f3b7b 100644 --- a/function/spring-header-filter-function/src/test/java/org/springframework/cloud/fn/header/filter/HeaderUtils.java +++ b/function/spring-header-filter-function/src/test/java/org/springframework/cloud/fn/header/filter/HeaderUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2023 the original author or authors. + * Copyright 2023-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. @@ -24,7 +24,7 @@ import org.springframework.integration.IntegrationMessageHeaderAccessor; import org.springframework.messaging.Message; -final public class HeaderUtils { +public final class HeaderUtils { private HeaderUtils() { } diff --git a/function/spring-header-filter-function/src/test/resources/test.properties b/function/spring-header-filter-function/src/test/resources/test.properties deleted file mode 100644 index 4f937e4c..00000000 --- a/function/spring-header-filter-function/src/test/resources/test.properties +++ /dev/null @@ -1 +0,0 @@ -logging.level.root=debug