activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [1/2] activemq-artemis git commit: [ARTEMIS-931] Improve HTTP Upgrade connection
Date Fri, 20 Jan 2017 14:54:44 GMT
Repository: activemq-artemis
Updated Branches:
  refs/heads/master 6c97067e1 -> 5edf940ed


[ARTEMIS-931] Improve HTTP Upgrade connection

If the object received is not an expected HttpResponse, close the
ChannelHandlerContext and countdown the latch

JIRA: https://issues.apache.org/jira/browse/ARTEMIS-931


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/5a59cd19
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/5a59cd19
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/5a59cd19

Branch: refs/heads/master
Commit: 5a59cd19f82bd7dd93919ad09470d2feda21de49
Parents: 6c97067
Author: Jeff Mesnil <jmesnil@gmail.com>
Authored: Fri Jan 20 15:22:25 2017 +0100
Committer: Jeff Mesnil <jmesnil@gmail.com>
Committed: Fri Jan 20 15:22:25 2017 +0100

----------------------------------------------------------------------
 .../artemis/core/client/ActiveMQClientLogger.java      |  4 ++++
 .../core/remoting/impl/netty/NettyConnector.java       | 13 ++++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/5a59cd19/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/ActiveMQClientLogger.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/ActiveMQClientLogger.java
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/ActiveMQClientLogger.java
index 6ed0e12..eeff924 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/ActiveMQClientLogger.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/ActiveMQClientLogger.java
@@ -433,4 +433,8 @@ public interface ActiveMQClientLogger extends BasicLogger {
       format = Message.Format.MESSAGE_FORMAT)
    void reconnectCreatingNewSession(long id);
 
+   @LogMessage(level = Logger.Level.ERROR)
+   @Message(id = 214029, value = "Unexpected response from HTTP server: %s")
+   void unexpectedResponseFromHttpServer(Object response);
+
 }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/5a59cd19/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnector.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnector.java
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnector.java
index c809b96..c317ec9 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnector.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnector.java
@@ -70,6 +70,7 @@ import io.netty.handler.codec.http.DefaultHttpRequest;
 import io.netty.handler.codec.http.FullHttpRequest;
 import io.netty.handler.codec.http.FullHttpResponse;
 import io.netty.handler.codec.http.HttpClientCodec;
+import io.netty.handler.codec.http.HttpHeaderNames;
 import io.netty.handler.codec.http.HttpHeaders;
 import io.netty.handler.codec.http.HttpMethod;
 import io.netty.handler.codec.http.HttpObject;
@@ -737,9 +738,14 @@ public class NettyConnector extends AbstractConnector {
 
       @Override
       public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception
{
-         if (msg instanceof HttpResponse) {
+         try {
+            if (!(msg instanceof HttpResponse)) {
+               ActiveMQClientLogger.LOGGER.unexpectedResponseFromHttpServer(msg);
+               ctx.close();
+               return;
+            }
             HttpResponse response = (HttpResponse) msg;
-            if (response.getStatus().code() == HttpResponseStatus.SWITCHING_PROTOCOLS.code()
&& response.headers().get(HttpHeaders.Names.UPGRADE).equals(ACTIVEMQ_REMOTING)) {
+            if (response.status().code() == HttpResponseStatus.SWITCHING_PROTOCOLS.code()
&& response.headers().get(HttpHeaderNames.UPGRADE).equals(ACTIVEMQ_REMOTING)) {
                String accept = response.headers().get(SEC_ACTIVEMQ_REMOTING_ACCEPT);
                String expectedResponse = createExpectedResponse(MAGIC_NUMBER, ctx.channel().attr(REMOTING_KEY).get());
 
@@ -754,10 +760,11 @@ public class NettyConnector extends AbstractConnector {
                   ActiveMQClientLogger.LOGGER.httpHandshakeFailed(accept, expectedResponse);
                   ctx.close();
                }
-            } else if (response.getStatus().code() == HttpResponseStatus.FORBIDDEN.code())
{
+            } else if (response.status().code() == HttpResponseStatus.FORBIDDEN.code()) {
                ActiveMQClientLogger.LOGGER.httpUpgradeNotSupportedByRemoteAcceptor();
                ctx.close();
             }
+         } finally {
             latch.countDown();
          }
       }


Mime
View raw message