diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompNIOTransportFactory.java b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompNIOTransportFactory.java index bc1fcfeeda..4f20df377c 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompNIOTransportFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompNIOTransportFactory.java @@ -87,5 +87,14 @@ public class StompNIOTransportFactory extends NIOTransportFactory implements Bro this.brokerContext = brokerService.getBrokerContext(); } + @Override + protected Transport createInactivityMonitor(Transport transport, WireFormat format) { + StompInactivityMonitor monitor = new StompInactivityMonitor(transport, format); + + StompTransportFilter filter = (StompTransportFilter) transport.narrow(StompTransportFilter.class); + filter.setInactivityMonitor(monitor); + + return monitor; + } } diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompSslTransportFactory.java b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompSslTransportFactory.java index 8a3792899b..fbeabc5659 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompSslTransportFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompSslTransportFactory.java @@ -65,4 +65,13 @@ public class StompSslTransportFactory extends SslTransportFactory implements Bro this.brokerContext = brokerService.getBrokerContext(); } + @Override + protected Transport createInactivityMonitor(Transport transport, WireFormat format) { + StompInactivityMonitor monitor = new StompInactivityMonitor(transport, format); + + StompTransportFilter filter = (StompTransportFilter) transport.narrow(StompTransportFilter.class); + filter.setInactivityMonitor(monitor); + + return monitor; + } } diff --git a/activemq-core/src/test/java/org/apache/activemq/transport/stomp/Stomp11NIOSSLTest.java b/activemq-core/src/test/java/org/apache/activemq/transport/stomp/Stomp11NIOSSLTest.java new file mode 100644 index 0000000000..52936422d7 --- /dev/null +++ b/activemq-core/src/test/java/org/apache/activemq/transport/stomp/Stomp11NIOSSLTest.java @@ -0,0 +1,44 @@ +/** + * 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.stomp; + +import java.io.IOException; +import java.net.Socket; +import java.net.URI; + +import javax.net.SocketFactory; +import javax.net.ssl.SSLSocketFactory; + +public class Stomp11NIOSSLTest extends Stomp11Test { + + protected void setUp() throws Exception { + bindAddress = "stomp+nio+ssl://localhost:61613"; + confUri = "xbean:org/apache/activemq/transport/stomp/sslstomp-auth-broker.xml"; + System.setProperty("javax.net.ssl.trustStore", "src/test/resources/client.keystore"); + System.setProperty("javax.net.ssl.trustStorePassword", "password"); + System.setProperty("javax.net.ssl.trustStoreType", "jks"); + System.setProperty("javax.net.ssl.keyStore", "src/test/resources/server.keystore"); + System.setProperty("javax.net.ssl.keyStorePassword", "password"); + System.setProperty("javax.net.ssl.keyStoreType", "jks"); + super.setUp(); + } + + protected Socket createSocket(URI connectUri) throws IOException { + SocketFactory factory = SSLSocketFactory.getDefault(); + return factory.createSocket("127.0.0.1", connectUri.getPort()); + } +} diff --git a/activemq-core/src/test/java/org/apache/activemq/transport/stomp/Stomp11NIOTest.java b/activemq-core/src/test/java/org/apache/activemq/transport/stomp/Stomp11NIOTest.java new file mode 100644 index 0000000000..d449f1f9b3 --- /dev/null +++ b/activemq-core/src/test/java/org/apache/activemq/transport/stomp/Stomp11NIOTest.java @@ -0,0 +1,27 @@ +/** + * 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.stomp; + +public class Stomp11NIOTest extends Stomp11Test { + + @Override + protected void setUp() throws Exception { + bindAddress = "stomp+nio://localhost:61612"; + confUri = "xbean:org/apache/activemq/transport/stomp/niostomp-auth-broker.xml"; + super.setUp(); + } +} diff --git a/activemq-core/src/test/java/org/apache/activemq/transport/stomp/Stomp11SslAuthTest.java b/activemq-core/src/test/java/org/apache/activemq/transport/stomp/Stomp11SslAuthTest.java new file mode 100644 index 0000000000..7b5a6ec3fa --- /dev/null +++ b/activemq-core/src/test/java/org/apache/activemq/transport/stomp/Stomp11SslAuthTest.java @@ -0,0 +1,56 @@ +/** + * 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.stomp; + +import java.io.IOException; +import java.net.Socket; +import java.net.URI; + +import javax.net.SocketFactory; +import javax.net.ssl.SSLSocketFactory; + + + +/** + * + */ +public class Stomp11SslAuthTest extends Stomp11Test { + + + protected void setUp() throws Exception { + + // Test mutual authentication on both stomp and standard ssl transports + bindAddress = "stomp+ssl://localhost:61612"; + confUri = "xbean:org/apache/activemq/transport/stomp/sslstomp-mutual-auth-broker.xml"; + jmsUri="ssl://localhost:61617"; + + System.setProperty("javax.net.ssl.trustStore", "src/test/resources/client.keystore"); + System.setProperty("javax.net.ssl.trustStorePassword", "password"); + System.setProperty("javax.net.ssl.trustStoreType", "jks"); + System.setProperty("javax.net.ssl.keyStore", "src/test/resources/server.keystore"); + System.setProperty("javax.net.ssl.keyStorePassword", "password"); + System.setProperty("javax.net.ssl.keyStoreType", "jks"); + //System.setProperty("javax.net.debug","ssl,handshake"); + super.setUp(); + } + + protected Socket createSocket(URI connectUri) throws IOException { + SocketFactory factory = SSLSocketFactory.getDefault(); + return factory.createSocket("127.0.0.1", connectUri.getPort()); + } + +} diff --git a/activemq-core/src/test/java/org/apache/activemq/transport/stomp/Stomp11Test.java b/activemq-core/src/test/java/org/apache/activemq/transport/stomp/Stomp11Test.java index ef76f8a0e3..43c5bdbc1d 100644 --- a/activemq-core/src/test/java/org/apache/activemq/transport/stomp/Stomp11Test.java +++ b/activemq-core/src/test/java/org/apache/activemq/transport/stomp/Stomp11Test.java @@ -197,12 +197,12 @@ public class Stomp11Test extends CombinationTestSupport { stompConnection.sendFrame(connectFrame); String f = stompConnection.receiveFrame(); - assertTrue(f.startsWith("CONNECTED")); - assertTrue(f.indexOf("version:1.1") >= 0); - assertTrue(f.indexOf("heart-beat:") >= 0); - assertTrue(f.indexOf("session:") >= 0); + assertTrue("Failed to receive a connected frame.", f.startsWith("CONNECTED")); + assertTrue("Frame should have a versoion 1.1 header.", f.indexOf("version:1.1") >= 0); + assertTrue("Frame should have a heart beat header.", f.indexOf("heart-beat:") >= 0); + assertTrue("Frame should have a session header.", f.indexOf("session:") >= 0); - LOG.debug("Broker sent: " + f); + LOG.info("Broker sent: " + f); stompConnection.getStompSocket().getOutputStream().write('\n'); @@ -278,11 +278,13 @@ public class Stomp11Test extends CombinationTestSupport { Thread.sleep(TimeUnit.SECONDS.toMillis(10)); try { - String message = "SEND\n" + "destination:/queue/" + getQueueName() + "\n\n" + "Hello World" + Stomp.NULL; + String message = "SEND\n" + "destination:/queue/" + getQueueName() + "\n" + + "receipt:1\n\n" + "Hello World" + Stomp.NULL; stompConnection.sendFrame(message); + stompConnection.receiveFrame(); fail("SEND frame has been accepted after missing heart beat"); } catch (Exception ex) { - System.out.println(ex.getMessage()); + LOG.info(ex.getMessage()); } }