You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/07/27 09:11:45 UTC

[camel] branch camel-3.x updated: CAMEL-19663: camel-core - ToD EIP multi-value property lost problem. Thanks to EvanMi for the PR.

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

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


The following commit(s) were added to refs/heads/camel-3.x by this push:
     new 80b55726eb9 CAMEL-19663: camel-core - ToD EIP multi-value property lost problem. Thanks to EvanMi for the PR.
80b55726eb9 is described below

commit 80b55726eb99995a26805e6dc9b0b02927031d6f
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Jul 27 11:09:16 2023 +0200

    CAMEL-19663: camel-core - ToD EIP multi-value property lost problem. Thanks to EvanMi for the PR.
---
 .../http/HttpSendDynamicAwareMultiValueTest.java   | 105 +++++++++++++++++++++
 .../support/component/SendDynamicAwareSupport.java |   8 +-
 2 files changed, 112 insertions(+), 1 deletion(-)

diff --git a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpSendDynamicAwareMultiValueTest.java b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpSendDynamicAwareMultiValueTest.java
new file mode 100644
index 00000000000..d32ed98d565
--- /dev/null
+++ b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpSendDynamicAwareMultiValueTest.java
@@ -0,0 +1,105 @@
+/*
+ * 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.http;
+
+import java.lang.reflect.Field;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.http.handler.BasicValidationHandler;
+import org.apache.hc.client5.http.classic.HttpClient;
+import org.apache.hc.client5.http.config.RequestConfig;
+import org.apache.hc.core5.http.impl.bootstrap.HttpServer;
+import org.apache.hc.core5.http.impl.bootstrap.ServerBootstrap;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class HttpSendDynamicAwareMultiValueTest extends BaseHttpTest {
+
+    private HttpServer localServer;
+
+    @BeforeEach
+    @Override
+    public void setUp() throws Exception {
+        localServer = ServerBootstrap.bootstrap()
+                .setHttpProcessor(getBasicHttpProcessor())
+                .setConnectionReuseStrategy(getConnectionReuseStrategy())
+                .setResponseFactory(getHttpResponseFactory())
+                .setSslContext(getSSLContext())
+                .register("/dynamicAware", new BasicValidationHandler("GET", null, null, null))
+                .create();
+        localServer.start();
+
+        super.setUp();
+    }
+
+    @AfterEach
+    @Override
+    public void tearDown() throws Exception {
+        super.tearDown();
+
+        if (localServer != null) {
+            localServer.stop();
+        }
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:dynamicAwareWithMultiValue")
+                        .toD("http://localhost:" + localServer.getLocalPort()
+                             + "/dynamicAware?httpClient.responseTimeout=60000&okStatusCodeRange=200-500&foo=foo");
+            }
+        };
+    }
+
+    @Test
+    public void testSendDynamicAwareMultiValue() throws Exception {
+        Exchange e = fluentTemplate
+                .to("direct:dynamicAwareWithMultiValue")
+                .send();
+
+        boolean found = context.getEndpointRegistry().containsKey("http://localhost:" + localServer.getLocalPort()
+                                                                  + "?httpClient.responseTimeout=60000&okStatusCodeRange=200-500");
+
+        assertTrue(found, "Should find static uri with multi-value");
+        assertEquals("/dynamicAware", e.getIn().getHeader(Exchange.HTTP_PATH));
+        assertEquals("foo=foo", e.getIn().getHeader(Exchange.HTTP_QUERY));
+
+        HttpEndpoint httpEndpoint = (HttpEndpoint) context.getEndpoint("http://localhost:" + localServer.getLocalPort()
+                                                                       + "?httpClient.responseTimeout=60000&okStatusCodeRange=200-500");
+
+        String okStatusCodeRange = httpEndpoint.getOkStatusCodeRange();
+        assertEquals("200-500", okStatusCodeRange);
+
+        HttpClient httpClient = httpEndpoint.getHttpClient();
+
+        Class<?> internalHttpClientClass = Class
+                .forName("org.apache.hc.client5.http.impl.classic.InternalHttpClient");
+        Field defaultConfig = internalHttpClientClass.getDeclaredField("defaultConfig");
+        defaultConfig.setAccessible(true);
+        RequestConfig config = (RequestConfig) defaultConfig.get(httpClient);
+        assertEquals(60000, config.getResponseTimeout().getDuration());
+    }
+}
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/component/SendDynamicAwareSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/component/SendDynamicAwareSupport.java
index 0120ef9e5f8..c8140942215 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/component/SendDynamicAwareSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/component/SendDynamicAwareSupport.java
@@ -90,7 +90,13 @@ public abstract class SendDynamicAwareSupport extends ServiceSupport implements
             // okay so only add the known properties as they are the non lenient properties
             properties = new LinkedHashMap<>();
             map.forEach((k, v) -> {
-                if (knownProperties.contains(k)) {
+                boolean accept = knownProperties.contains(k);
+                // we should put the key from a multi-value (prefix) in the
+                // properties too, or the property may be lost
+                if (!accept && !knownPrefixes.isEmpty()) {
+                    accept = knownPrefixes.stream().anyMatch(k::startsWith);
+                }
+                if (accept) {
                     properties.put(k, v);
                 }
             });