activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hadr...@apache.org
Subject [13/20] git commit: AMQ-4433: Validate socket.xxx transport connector options, to detect invalud/unused options and fail. Thanks to Christoffer Sawicki for the patch.
Date Wed, 12 Mar 2014 02:21:39 GMT
AMQ-4433: Validate socket.xxx transport connector options, to detect invalud/unused options
and fail. Thanks to Christoffer Sawicki for the patch.


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

Branch: refs/heads/activemq-5.9
Commit: 926a43533fcb58f1bb43a16b7a510af0ff059e98
Parents: 5161087
Author: Claus Ibsen <claus.ibsen@gmail.com>
Authored: Thu Oct 31 12:13:32 2013 +0100
Committer: Hadrian Zbarcea <hadrian@apache.org>
Committed: Tue Mar 11 21:18:33 2014 -0400

----------------------------------------------------------------------
 .../activemq/transport/tcp/TcpTransport.java    | 15 +++--
 ...nsportConnectorInvalidSocketOptionsTest.java | 65 ++++++++++++++++++++
 2 files changed, 75 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/926a4353/activemq-client/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java
b/activemq-client/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java
index 4a22e6b..367a8fc 100755
--- a/activemq-client/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java
+++ b/activemq-client/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java
@@ -418,14 +418,19 @@ public class TcpTransport extends TransportThreadSupport implements
Transport, S
     /**
      * Configures the socket for use
      *
-     * @param sock
+     * @param sock  the socket
      * @throws SocketException, IllegalArgumentException if setting the options
      *         on the socket failed.
      */
-    protected void initialiseSocket(Socket sock) throws SocketException,
-            IllegalArgumentException {
+    protected void initialiseSocket(Socket sock) throws SocketException, IllegalArgumentException
{
         if (socketOptions != null) {
-            IntrospectionSupport.setProperties(socket, socketOptions);
+            // copy the map as its used values is being removed when calling setProperties
+            // and we need to be able to set the options again in case socket is re-initailized
+            Map<String, Object> copy = new HashMap<String, Object>(socketOptions);
+            IntrospectionSupport.setProperties(socket, copy);
+            if (!copy.isEmpty()) {
+                throw new IllegalArgumentException("Invalid socket parameters: " + copy);
+            }
         }
 
         try {
@@ -433,7 +438,7 @@ public class TcpTransport extends TransportThreadSupport implements Transport,
S
             sock.setSendBufferSize(socketBufferSize);
         } catch (SocketException se) {
             LOG.warn("Cannot set socket buffer size = " + socketBufferSize);
-            LOG.debug("Cannot set socket buffer size. Reason: " + se, se);
+            LOG.debug("Cannot set socket buffer size. Reason: " + se.getMessage() + ". This
exception is ignored.", se);
         }
         sock.setSoTimeout(soTimeout);
 

http://git-wip-us.apache.org/repos/asf/activemq/blob/926a4353/activemq-unit-tests/src/test/java/org/apache/activemq/transport/tcp/TransportConnectorInvalidSocketOptionsTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/transport/tcp/TransportConnectorInvalidSocketOptionsTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/transport/tcp/TransportConnectorInvalidSocketOptionsTest.java
new file mode 100644
index 0000000..5a171b7
--- /dev/null
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/transport/tcp/TransportConnectorInvalidSocketOptionsTest.java
@@ -0,0 +1,65 @@
+/**
+ * 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.activemq.transport.tcp;
+
+import javax.jms.JMSException;
+
+import junit.framework.TestCase;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.junit.Test;
+
+public class TransportConnectorInvalidSocketOptionsTest extends TestCase {
+
+    @Test
+    public void testClientParameters() throws Exception {
+        try {
+            new ActiveMQConnectionFactory("tcp://localhost:42?foo=bar").createConnection();
+            fail("Should have thrown an exception");
+        } catch (Exception e) {
+            assertEquals(JMSException.class, e.getClass());
+            assertEquals(IllegalArgumentException.class, e.getCause().getClass());
+            assertEquals("Invalid connect parameters: {foo=bar}", e.getCause().getMessage());
+        }
+    }
+
+    @Test
+    public void testClientSocketParameters() throws Exception {
+        BrokerService broker = null;
+
+        try {
+            broker = new BrokerService();
+            broker.setPersistent(false);
+            broker.addConnector("tcp://localhost:61616");
+            broker.start();
+
+            try {
+                new ActiveMQConnectionFactory("tcp://localhost:61616?socket.foo=bar").createConnection();
+                fail("Should have thrown an exception");
+            } catch (Exception e) {
+                assertEquals(JMSException.class, e.getClass());
+                assertEquals(IllegalArgumentException.class, e.getCause().getClass());
+                assertEquals("Invalid socket parameters: {foo=bar}", e.getCause().getMessage());
+            }
+        } finally {
+            if (broker != null) {
+                broker.stop();
+            }
+        }
+    }
+
+}


Mime
View raw message