Repository: camel
Updated Branches:
  refs/heads/camel-2.16.x 572df64ce -> b3f279ae6


CAMEL-9410: camel-netty-http - should default to port 80 and 443


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b3f279ae
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b3f279ae
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b3f279ae

Branch: refs/heads/camel-2.16.x
Commit: b3f279ae6027612df0b59682001cc5cb76e26072
Parents: 572df64
Author: Claus Ibsen <davscl...@apache.org>
Authored: Thu Dec 10 14:59:07 2015 +0100
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Thu Dec 10 15:00:13 2015 +0100

----------------------------------------------------------------------
 .../netty/http/NettyHttpComponent.java          | 36 ++++++++++++-------
 .../netty4/http/NettyHttpComponent.java         | 37 ++++++++++++--------
 2 files changed, 46 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b3f279ae/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
 
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
index 59fcc91..f551b20 100644
--- 
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
+++ 
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
@@ -58,9 +58,6 @@ public class NettyHttpComponent extends NettyComponent 
implements HeaderFilterSt
     private HeaderFilterStrategy headerFilterStrategy;
     private NettyHttpSecurityConfiguration securityConfiguration;
 
-    // If the port is not specified Netty set it to -1, we need to set it on a 
default port in this case
-    private int defaultPortIfNotProvided = 80;
-
     public NettyHttpComponent() {
         // use the http configuration and filter strategy
         super(NettyHttpEndpoint.class);
@@ -94,20 +91,36 @@ public class NettyHttpComponent extends NettyComponent 
implements HeaderFilterSt
         NettyHttpSecurityConfiguration securityConfiguration = 
resolveAndRemoveReferenceParameter(parameters, "securityConfiguration", 
NettyHttpSecurityConfiguration.class);
         Map<String, Object> securityOptions = 
IntrospectionSupport.extractProperties(parameters, "securityConfiguration.");
 
-        config = parseConfiguration(config, remaining, parameters);
-        setProperties(config, parameters);
-
-        // validate config
-        config.validateConfiguration();
-
         // are we using a shared http server?
+        int sharedPort = -1;
         NettySharedHttpServer shared = 
resolveAndRemoveReferenceParameter(parameters, "nettySharedHttpServer", 
NettySharedHttpServer.class);
         if (shared != null) {
             // use port number from the shared http server
             LOG.debug("Using NettySharedHttpServer: {} with port: {}", shared, 
shared.getPort());
-            config.setPort(shared.getPort());
+            sharedPort = shared.getPort();
+        }
+
+        // configure configuration
+        config = parseConfiguration(config, remaining, parameters);
+        // set port on configuration which is either shared or using default 
values
+        if (sharedPort != -1) {
+            config.setPort(sharedPort);
+        } else if (config.getPort() == -1) {
+            if ("http".equals(config.getProtocol())) {
+                config.setPort(80);
+            } else if ("https".equals(config.getProtocol())) {
+                config.setPort(443);
+            }
+        }
+        if (config.getPort() == -1) {
+            throw new IllegalArgumentException("Port number must be 
configured");
         }
 
+        setProperties(config, parameters);
+
+        // validate config
+        config.validateConfiguration();
+
         // create the address uri which includes the remainder parameters 
(which is not configuration parameters for this component)
         URI u = new URI(UnsafeUriCharactersEncoder.encodeHttpURI(remaining));
         
@@ -169,9 +182,6 @@ public class NettyHttpComponent extends NettyComponent 
implements HeaderFilterSt
             ((NettyHttpConfiguration) configuration).setPath(uri.getPath());
         }
 
-        if (configuration.getPort() == -1) {
-            configuration.setPort(defaultPortIfNotProvided);
-        }
         return configuration;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/b3f279ae/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpComponent.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpComponent.java
 
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpComponent.java
index 50d281c..775943b 100644
--- 
a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpComponent.java
+++ 
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpComponent.java
@@ -58,9 +58,6 @@ public class NettyHttpComponent extends NettyComponent 
implements HeaderFilterSt
     private HeaderFilterStrategy headerFilterStrategy;
     private NettyHttpSecurityConfiguration securityConfiguration;
     
-    // If the port is not specified Netty set it to -1, we need to set it on a 
default port in this case
-    private int defaultPortIfNotProvided = 80;
-
     public NettyHttpComponent() {
         // use the http configuration and filter strategy
         super(NettyHttpEndpoint.class);
@@ -94,20 +91,36 @@ public class NettyHttpComponent extends NettyComponent 
implements HeaderFilterSt
         NettyHttpSecurityConfiguration securityConfiguration = 
resolveAndRemoveReferenceParameter(parameters, "securityConfiguration", 
NettyHttpSecurityConfiguration.class);
         Map<String, Object> securityOptions = 
IntrospectionSupport.extractProperties(parameters, "securityConfiguration.");
 
-        config = parseConfiguration(config, remaining, parameters);
-        setProperties(config, parameters);
-
-        // validate config
-        config.validateConfiguration();
-
         // are we using a shared http server?
+        int sharedPort = -1;
         NettySharedHttpServer shared = 
resolveAndRemoveReferenceParameter(parameters, "nettySharedHttpServer", 
NettySharedHttpServer.class);
         if (shared != null) {
             // use port number from the shared http server
             LOG.debug("Using NettySharedHttpServer: {} with port: {}", shared, 
shared.getPort());
-            config.setPort(shared.getPort());
+            sharedPort = shared.getPort();
         }
 
+        // configure configuration
+        config = parseConfiguration(config, remaining, parameters);
+        // set port on configuration which is either shared or using default 
values
+        if (sharedPort != -1) {
+            config.setPort(sharedPort);
+        } else if (config.getPort() == -1) {
+            if ("http".equals(config.getProtocol())) {
+                config.setPort(80);
+            } else if ("https".equals(config.getProtocol())) {
+                config.setPort(443);
+            }
+        }
+        if (config.getPort() == -1) {
+            throw new IllegalArgumentException("Port number must be 
configured");
+        }
+
+        setProperties(config, parameters);
+
+        // validate config
+        config.validateConfiguration();
+
         NettyHttpBinding bindingFromUri = 
resolveAndRemoveReferenceParameter(parameters, "nettyHttpBinding", 
NettyHttpBinding.class);
 
         // create the address uri which includes the remainder parameters 
(which
@@ -176,10 +189,6 @@ public class NettyHttpComponent extends NettyComponent 
implements HeaderFilterSt
         if (configuration instanceof NettyHttpConfiguration) {
             ((NettyHttpConfiguration) configuration).setPath(uri.getPath());
         }
-
-        if (configuration.getPort() == -1) {
-            configuration.setPort(defaultPortIfNotProvided);
-        }
         return configuration;
     }
 

Reply via email to