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 2022/01/21 12:02:58 UTC

[camel] 01/03: CAMEL-17521: camel-http - Added unit test reproducing bug

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

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

commit cc05305b05c8e3e165871c5a811f88e476251b0d
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Jan 21 11:32:38 2022 +0100

    CAMEL-17521: camel-http - Added unit test reproducing bug
---
 .../camel/component/http/HttpToDSOTimeoutTest.java | 100 +++++++++++++++++++++
 .../http/handler/BasicValidationHandler.java       |  15 ++++
 2 files changed, 115 insertions(+)

diff --git a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpToDSOTimeoutTest.java b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpToDSOTimeoutTest.java
new file mode 100644
index 0000000..2495853
--- /dev/null
+++ b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpToDSOTimeoutTest.java
@@ -0,0 +1,100 @@
+/*
+ * 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 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.http.impl.bootstrap.HttpServer;
+import org.apache.http.impl.bootstrap.ServerBootstrap;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.camel.component.http.HttpMethods.GET;
+
+public class HttpToDSOTimeoutTest extends BaseHttpTest {
+
+    private HttpServer localServer;
+
+    private String baseUrl;
+
+    @BeforeEach
+    @Override
+    public void setUp() throws Exception {
+        localServer = ServerBootstrap.bootstrap().setHttpProcessor(getBasicHttpProcessor())
+                .setConnectionReuseStrategy(getConnectionReuseStrategy()).setResponseFactory(getHttpResponseFactory())
+                .setExpectationVerifier(getHttpExpectationVerifier()).setSslContext(getSSLContext())
+                .registerHandler("/foo",
+                        new BasicValidationHandler(
+                                "/foo", GET.name(), null, null,
+                                getExpectedContent()))
+                .registerHandler("/bar",
+                        new BasicValidationHandler(
+                                "/bar", GET.name(), null, null,
+                                getExpectedContent()))
+                .create();
+        localServer.start();
+
+        baseUrl = "http://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort();
+
+        super.setUp();
+    }
+
+    @AfterEach
+    @Override
+    public void tearDown() throws Exception {
+        super.tearDown();
+
+        if (localServer != null) {
+            localServer.stop();
+        }
+    }
+
+    @Test
+    public void httpTo() throws Exception {
+        Exchange exchange = template.request("direct:to",
+                exchange1 -> {
+                });
+        assertExchange(exchange);
+    }
+
+    @Test
+    @Disabled("TODO: https://issues.apache.org/jira/browse/CAMEL-17521")
+    public void httpToD() throws Exception {
+        Exchange exchange = template.request("direct:toD",
+                exchange1 -> {
+                });
+        assertExchange(exchange);
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:to")
+                        .to(baseUrl + "/foo?httpClient.SocketTimeout=5000");
+
+                from("direct:toD")
+                        .toD(baseUrl + "/bar?httpClient.SocketTimeout=5000");
+            }
+        };
+    }
+}
diff --git a/components/camel-http/src/test/java/org/apache/camel/component/http/handler/BasicValidationHandler.java b/components/camel-http/src/test/java/org/apache/camel/component/http/handler/BasicValidationHandler.java
index 1679681..186c025 100644
--- a/components/camel-http/src/test/java/org/apache/camel/component/http/handler/BasicValidationHandler.java
+++ b/components/camel-http/src/test/java/org/apache/camel/component/http/handler/BasicValidationHandler.java
@@ -33,6 +33,7 @@ import org.apache.http.util.EntityUtils;
 
 public class BasicValidationHandler implements HttpRequestHandler {
 
+    protected String expectedUri;
     protected String expectedMethod;
     protected String expectedQuery;
     protected Object expectedContent;
@@ -46,12 +47,26 @@ public class BasicValidationHandler implements HttpRequestHandler {
         this.responseContent = responseContent;
     }
 
+    public BasicValidationHandler(String expectedUri, String expectedMethod, String expectedQuery,
+                                  Object expectedContent, String responseContent) {
+        this.expectedUri = expectedUri;
+        this.expectedMethod = expectedMethod;
+        this.expectedQuery = expectedQuery;
+        this.expectedContent = expectedContent;
+        this.responseContent = responseContent;
+    }
+
     @Override
     public void handle(
             final HttpRequest request, final HttpResponse response,
             final HttpContext context)
             throws HttpException, IOException {
 
+        if (expectedUri != null && !expectedUri.equals(request.getRequestLine().getUri())) {
+            response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
+            return;
+        }
+
         if (expectedMethod != null && !expectedMethod.equals(request.getRequestLine().getMethod())) {
             response.setStatusCode(HttpStatus.SC_METHOD_FAILURE);
             return;