This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-4.4.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-4.4.x by this push:
     new f190012b4f2 CAMEL-21211: Azure Service Bus - filter unknown header 
types (#15540)
f190012b4f2 is described below

commit f190012b4f2a7fa2720d6da256ccba1d1fb3b091
Author: Dylan Piergies <[email protected]>
AuthorDate: Fri Sep 13 05:34:43 2024 +0100

    CAMEL-21211: Azure Service Bus - filter unknown header types (#15540)
    
    * CAMEL-21211: Azure Service Bus - filter unknown header types
    
    * Add AssertJ to camel-azure-servicebus test scope
---
 .../camel-azure/camel-azure-servicebus/pom.xml     |  6 +++
 .../servicebus/ServiceBusHeaderFilterStrategy.java | 28 ++++++++--
 .../ServiceBusHeaderFilterStrategyTest.java        | 63 ++++++++++++++++++++++
 3 files changed, 93 insertions(+), 4 deletions(-)

diff --git a/components/camel-azure/camel-azure-servicebus/pom.xml 
b/components/camel-azure/camel-azure-servicebus/pom.xml
index 2324401e3cf..c025e8be274 100644
--- a/components/camel-azure/camel-azure-servicebus/pom.xml
+++ b/components/camel-azure/camel-azure-servicebus/pom.xml
@@ -64,6 +64,12 @@
             <artifactId>camel-test-junit5</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <version>${assertj-version}</version>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.mockito</groupId>
             <artifactId>mockito-core</artifactId>
diff --git 
a/components/camel-azure/camel-azure-servicebus/src/main/java/org/apache/camel/component/azure/servicebus/ServiceBusHeaderFilterStrategy.java
 
b/components/camel-azure/camel-azure-servicebus/src/main/java/org/apache/camel/component/azure/servicebus/ServiceBusHeaderFilterStrategy.java
index 5ab2a97e08a..4ea6a0f0ba6 100644
--- 
a/components/camel-azure/camel-azure-servicebus/src/main/java/org/apache/camel/component/azure/servicebus/ServiceBusHeaderFilterStrategy.java
+++ 
b/components/camel-azure/camel-azure-servicebus/src/main/java/org/apache/camel/component/azure/servicebus/ServiceBusHeaderFilterStrategy.java
@@ -16,16 +16,36 @@
  */
 package org.apache.camel.component.azure.servicebus;
 
+import java.util.Date;
+import java.util.Set;
+import java.util.UUID;
+
+import org.apache.camel.Exchange;
 import org.apache.camel.support.DefaultHeaderFilterStrategy;
 
 public class ServiceBusHeaderFilterStrategy extends 
DefaultHeaderFilterStrategy {
+    private static final Set<Class<?>> SUPPORTED_TYPES = Set.of(
+            Boolean.class,
+            Byte.class,
+            Character.class,
+            Double.class,
+            Float.class,
+            Integer.class,
+            Long.class,
+            Short.class,
+            String.class,
+            Date.class,
+            UUID.class);
+
     public ServiceBusHeaderFilterStrategy() {
         super();
-        initialise();
+        
setOutFilterStartsWith(DefaultHeaderFilterStrategy.CAMEL_FILTER_STARTS_WITH);
+        
setInFilterStartsWith(DefaultHeaderFilterStrategy.CAMEL_FILTER_STARTS_WITH);
     }
 
-    private void initialise() {
-        setOutFilterStartsWith("Camel", "camel", "org.apache.camel.");
-        setInFilterStartsWith("Camel", "camel", "org.apache.camel.");
+    @Override
+    public boolean applyFilterToCamelHeaders(String headerName, Object 
headerValue, Exchange exchange) {
+        return headerValue == null || 
!SUPPORTED_TYPES.contains(headerValue.getClass())
+                || super.applyFilterToCamelHeaders(headerName, headerValue, 
exchange);
     }
 }
diff --git 
a/components/camel-azure/camel-azure-servicebus/src/test/java/org/apache/camel/component/azure/servicebus/ServiceBusHeaderFilterStrategyTest.java
 
b/components/camel-azure/camel-azure-servicebus/src/test/java/org/apache/camel/component/azure/servicebus/ServiceBusHeaderFilterStrategyTest.java
new file mode 100644
index 00000000000..d54f22811af
--- /dev/null
+++ 
b/components/camel-azure/camel-azure-servicebus/src/test/java/org/apache/camel/component/azure/servicebus/ServiceBusHeaderFilterStrategyTest.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.azure.servicebus;
+
+import java.util.Date;
+import java.util.UUID;
+import java.util.stream.Stream;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.ArgumentsProvider;
+import org.junit.jupiter.params.provider.ArgumentsSource;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class ServiceBusHeaderFilterStrategyTest {
+    private final ServiceBusHeaderFilterStrategy headerFilterStrategy = new 
ServiceBusHeaderFilterStrategy();
+
+    @ParameterizedTest
+    @ArgumentsSource(HeaderArgumentsProvider.class)
+    void testApplyFilterToCamelHeadersPassesKnownTypes(String headerName, 
Object headerValue) {
+        assertThat(headerFilterStrategy.applyFilterToCamelHeaders(headerName, 
headerValue, null)).isFalse();
+    }
+
+    @Test
+    void testApplyFilterToCamelHeadersFiltersUnknownType() {
+        
assertThat(headerFilterStrategy.applyFilterToCamelHeaders("objectHeader", new 
Object(), null)).isTrue();
+    }
+
+    static class HeaderArgumentsProvider implements ArgumentsProvider {
+        @Override
+        public Stream<? extends Arguments> provideArguments(ExtensionContext 
context) throws Exception {
+            return Stream.of(
+                    Arguments.of("booleanHeader", true),
+                    Arguments.of("byteHeader", (byte) 1),
+                    Arguments.of("characterHeader", '1'),
+                    Arguments.of("doubleHeader", 1.0D),
+                    Arguments.of("floatHeader", 1.0F),
+                    Arguments.of("integerHeader", 1),
+                    Arguments.of("longHeader", 1L),
+                    Arguments.of("shortHeader", (short) 1),
+                    Arguments.of("stringHeader", "stringHeader"),
+                    Arguments.of("timestampHeader", new Date()),
+                    Arguments.of("uuidHeader", UUID.randomUUID()));
+        }
+    }
+}

Reply via email to