From commits-return-65354-archive-asf-public=cust-asf.ponee.io@camel.apache.org Sun Sep 23 16:23:55 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 7230118066B for ; Sun, 23 Sep 2018 16:23:54 +0200 (CEST) Received: (qmail 37747 invoked by uid 500); 23 Sep 2018 14:23:53 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 37738 invoked by uid 99); 23 Sep 2018 14:23:53 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 23 Sep 2018 14:23:53 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id E634E82B65; Sun, 23 Sep 2018 14:23:52 +0000 (UTC) Date: Sun, 23 Sep 2018 14:23:52 +0000 To: "commits@camel.apache.org" Subject: [camel] branch master updated: CAMEL-12827 - HttpSendDynamicAware setting port to -1 when not defined. (#2528) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <153771263266.11703.7314853075120710482@gitbox.apache.org> From: davsclaus@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: camel X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 1babebbf3f46afdf1c6afae909173ecb438c6791 X-Git-Newrev: 902d6246c63884dfe458f4940a455156f675db18 X-Git-Rev: 902d6246c63884dfe458f4940a455156f675db18 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git The following commit(s) were added to refs/heads/master by this push: new 902d624 CAMEL-12827 - HttpSendDynamicAware setting port to -1 when not defined. (#2528) 902d624 is described below commit 902d6246c63884dfe458f4940a455156f675db18 Author: Bob Paulin AuthorDate: Sun Sep 23 09:23:48 2018 -0500 CAMEL-12827 - HttpSendDynamicAware setting port to -1 when not defined. (#2528) * CAMEL-12827 - HttpSendDynamicAware setting port to -1 when not defined. * CAMEL-12827 - Add Apache License Headers to test. --- .../camel/http/common/HttpSendDynamicAware.java | 2 +- .../http/common/HttpSendDynamicAwareTest.java | 98 ++++++++++++++++++++++ 2 files changed, 99 insertions(+), 1 deletion(-) diff --git a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpSendDynamicAware.java b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpSendDynamicAware.java index 7968952..86fb192 100644 --- a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpSendDynamicAware.java +++ b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpSendDynamicAware.java @@ -141,7 +141,7 @@ public class HttpSendDynamicAware implements SendDynamicAware { // if the path is just a trailing slash then skip it (eg it must be longer than just the slash itself) if (path != null && path.length() > 1) { int port = parse.getPort(); - if (port != 80 && port != 443) { + if (port > 0 && port != 80 && port != 443) { host += ":" + port; } if (!httpComponent) { diff --git a/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpSendDynamicAwareTest.java b/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpSendDynamicAwareTest.java new file mode 100644 index 0000000..71ec8f5 --- /dev/null +++ b/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpSendDynamicAwareTest.java @@ -0,0 +1,98 @@ +/** + * 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.http.common; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.apache.camel.spi.SendDynamicAware.DynamicAwareEntry; + +public class HttpSendDynamicAwareTest { + + private HttpSendDynamicAware httpSendDynamicAware; + @Before + public void setUp() throws Exception { + this.httpSendDynamicAware = new HttpSendDynamicAware(); + + } + + @Test + public void testHttpUndefinedPortWithPathParseUri() { + this.httpSendDynamicAware.setScheme("http"); + DynamicAwareEntry entry = new DynamicAwareEntry("http://localhost/test", null, null); + String[] result = httpSendDynamicAware.parseUri(entry); + assertEquals("Parse should not add port if http and not specified", "localhost", result[0]); + } + + @Test + public void testHttpsUndefinedPortParseUri() { + this.httpSendDynamicAware.setScheme("https"); + DynamicAwareEntry entry = new DynamicAwareEntry("https://localhost/test", null, null); + String[] result = httpSendDynamicAware.parseUri(entry); + assertEquals("Parse should not add port if https and not specified", "localhost", result[0]); + } + + @Test + public void testHttp4UndefinedPortWithPathParseUri() { + this.httpSendDynamicAware.setScheme("http4"); + DynamicAwareEntry entry = new DynamicAwareEntry("http4://localhost/test", null, null); + String[] result = httpSendDynamicAware.parseUri(entry); + assertEquals("Parse should not add port if http4 and not specified", "localhost", result[0]); + } + + @Test + public void testHttps4UndefinedPortParseUri() { + this.httpSendDynamicAware.setScheme("https4"); + DynamicAwareEntry entry = new DynamicAwareEntry("https4://localhost/test", null, null); + String[] result = httpSendDynamicAware.parseUri(entry); + assertEquals("Parse should not add port if https4 and not specified", "localhost", result[0]); + } + + @Test + public void testHttpPort80ParseUri() { + this.httpSendDynamicAware.setScheme("http"); + DynamicAwareEntry entry = new DynamicAwareEntry("http://localhost:80/test", null, null); + String[] result = httpSendDynamicAware.parseUri(entry); + assertEquals("Parse should not port if http and port 80 specified", "localhost", result[0]); + } + + @Test + public void testHttpsPort443ParseUri() { + this.httpSendDynamicAware.setScheme("https"); + DynamicAwareEntry entry = new DynamicAwareEntry("https://localhost:443/test", null, null); + String[] result = httpSendDynamicAware.parseUri(entry); + assertEquals("Parse should not port if https and port 443 specified", "localhost", result[0]); + } + + @Test + public void testHttpPort8080ParseUri() { + this.httpSendDynamicAware.setScheme("http"); + DynamicAwareEntry entry = new DynamicAwareEntry("http://localhost:8080/test", null, null); + String[] result = httpSendDynamicAware.parseUri(entry); + assertEquals("Parse should add port if http and port other than 80 specified", "localhost:8080", result[0]); + } + + @Test + public void testHttpsPort8443ParseUri() { + this.httpSendDynamicAware.setScheme("https"); + DynamicAwareEntry entry = new DynamicAwareEntry("https://localhost:8443/test", null, null); + String[] result = httpSendDynamicAware.parseUri(entry); + assertEquals("Parse should add port if https and port other than 443 specified", "localhost:8443", result[0]); + } + +}