Repository: camel Updated Branches: refs/heads/master 1b7c19622 -> e6cf6f110
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/e6cf6f11 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e6cf6f11 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e6cf6f11 Branch: refs/heads/master Commit: e6cf6f110ca5e04b1fe4b9156c9df5ffa7b505df Parents: 1b7c196 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 14:59:07 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/e6cf6f11/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/e6cf6f11/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; }