You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by da...@apache.org on 2013/10/31 12:12:49 UTC
git commit: AMQ-4433: Validate socket.xxx transport connector options,
to detect invalud/unused options and fail. Thanks to Christoffer Sawicki for
the patch.
Updated Branches:
refs/heads/trunk 3ed52ef8a -> 7dfb0a2a3
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/7dfb0a2a
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/7dfb0a2a
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/7dfb0a2a
Branch: refs/heads/trunk
Commit: 7dfb0a2a3c86528d3b7bfeef1fe2df38339b450b
Parents: 3ed52ef
Author: Claus Ibsen <cl...@gmail.com>
Authored: Thu Oct 31 12:13:32 2013 +0100
Committer: Claus Ibsen <cl...@gmail.com>
Committed: Thu Oct 31 12:13:40 2013 +0100
----------------------------------------------------------------------
.../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/7dfb0a2a/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/7dfb0a2a/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();
+ }
+ }
+ }
+
+}