From d307496da93761c2da998a339c01c792550eaf0b Mon Sep 17 00:00:00 2001 From: Jeff Mesnil Date: Mon, 10 Feb 2014 17:56:42 +0100 Subject: [PATCH] =?UTF-8?q?[HORNETQ-1317]=C2=A0HTTP=20upgrade=20using=20HT?= =?UTF-8?q?TPS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix NettyConnector so that the use of a HTTP upgrade process is executed when a SSL handler is defined too. --- .../remoting/impl/netty/NettyConnector.java | 73 +++++++++---------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/hornetq-core-client/src/main/java/org/hornetq/core/remoting/impl/netty/NettyConnector.java b/hornetq-core-client/src/main/java/org/hornetq/core/remoting/impl/netty/NettyConnector.java index baf4cbbe0fc..7cfe815161e 100644 --- a/hornetq-core-client/src/main/java/org/hornetq/core/remoting/impl/netty/NettyConnector.java +++ b/hornetq-core-client/src/main/java/org/hornetq/core/remoting/impl/netty/NettyConnector.java @@ -719,58 +719,55 @@ public Connection createConnection() } } - else + if (httpUpgradeEnabled) { - if (httpUpgradeEnabled) + // Send a HTTP GET + Upgrade request that will be handled by the http-upgrade handler. + try { - // Send a HTTP GET + Upgrade request that will be handled by the http-upgrade handler. - try + //get this first incase it removes itself + HttpUpgradeHandler httpUpgradeHandler = (HttpUpgradeHandler) ch.pipeline().get("http-upgrade"); + URI uri = new URI("http", null, host, port, null, null, null); + HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri.getRawPath()); + request.headers().set(HttpHeaders.Names.HOST, host); + request.headers().set(HttpHeaders.Names.UPGRADE, HORNETQ_REMOTING); + request.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.UPGRADE); + + final String endpoint = ConfigurationHelper.getStringProperty(TransportConstants.HTTP_UPGRADE_ENDPOINT_PROP_NAME, + null, + configuration); + if (endpoint != null) { - //get this first incase it removes itself - HttpUpgradeHandler httpUpgradeHandler = (HttpUpgradeHandler) ch.pipeline().get("http-upgrade"); - URI uri = new URI("http", null, host, port, null, null, null); - HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri.getRawPath()); - request.headers().set(HttpHeaders.Names.HOST, host); - request.headers().set(HttpHeaders.Names.UPGRADE, HORNETQ_REMOTING); - request.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.UPGRADE); - - final String endpoint = ConfigurationHelper.getStringProperty(TransportConstants.HTTP_UPGRADE_ENDPOINT_PROP_NAME, - null, - configuration); - if (endpoint != null) - { - request.headers().set(TransportConstants.HTTP_UPGRADE_ENDPOINT_PROP_NAME, endpoint); - } + request.headers().set(TransportConstants.HTTP_UPGRADE_ENDPOINT_PROP_NAME, endpoint); + } - // Get 16 bit nonce and base 64 encode it - byte[] nonce = randomBytes(16); - String key = base64(nonce); - request.headers().set(SEC_HORNETQ_REMOTING_KEY, key); - ch.attr(REMOTING_KEY).set(key); + // Get 16 bit nonce and base 64 encode it + byte[] nonce = randomBytes(16); + String key = base64(nonce); + request.headers().set(SEC_HORNETQ_REMOTING_KEY, key); + ch.attr(REMOTING_KEY).set(key); - HornetQClientLogger.LOGGER.debugf("Sending HTTP request %s", request); + HornetQClientLogger.LOGGER.debugf("Sending HTTP request %s", request); - // Send the HTTP request. - ch.writeAndFlush(request); + // Send the HTTP request. + ch.writeAndFlush(request); - if (!httpUpgradeHandler.awaitHandshake()) - { - return null; - } - } - catch (URISyntaxException e) + if (!httpUpgradeHandler.awaitHandshake()) { - HornetQClientLogger.LOGGER.errorCreatingNettyConnection(e); return null; } } - else + catch (URISyntaxException e) { - ChannelPipeline channelPipeline = ch.pipeline(); - HornetQChannelHandler channelHandler = channelPipeline.get(HornetQChannelHandler.class); - channelHandler.active = true; + HornetQClientLogger.LOGGER.errorCreatingNettyConnection(e); + return null; } } + else + { + ChannelPipeline channelPipeline = ch.pipeline(); + HornetQChannelHandler channelHandler = channelPipeline.get(HornetQChannelHandler.class); + channelHandler.active = true; + } // No acceptor on a client connection Listener connectionListener = new Listener();