diff --git a/broker/src/main/java/io/moquette/BrokerConstants.java b/broker/src/main/java/io/moquette/BrokerConstants.java index 6ad87c0f..3031b7fe 100644 --- a/broker/src/main/java/io/moquette/BrokerConstants.java +++ b/broker/src/main/java/io/moquette/BrokerConstants.java @@ -44,6 +44,7 @@ public class BrokerConstants { public static final String DB_AUTHENTICATOR_DIGEST = "authenticator.db.digest"; public static final int PORT = 1883; public static final int WEBSOCKET_PORT = 8080; + public static final String DISABLED_PORT_BIND = "disabled"; public static final String HOST = "0.0.0.0"; public static final String NEED_CLIENT_AUTH = "need_client_auth"; } diff --git a/broker/src/main/java/io/moquette/server/netty/NettyAcceptor.java b/broker/src/main/java/io/moquette/server/netty/NettyAcceptor.java index 44a415c3..0e766eb5 100644 --- a/broker/src/main/java/io/moquette/server/netty/NettyAcceptor.java +++ b/broker/src/main/java/io/moquette/server/netty/NettyAcceptor.java @@ -16,6 +16,7 @@ package io.moquette.server.netty; import io.moquette.BrokerConstants; +import static io.moquette.BrokerConstants.*; import io.moquette.parser.commons.Constants; import io.moquette.parser.netty.MQTTDecoder; import io.moquette.parser.netty.MQTTEncoder; @@ -146,9 +147,9 @@ public class NettyAcceptor implements ServerAcceptor { private void initializePlainTCPTransport(final NettyMQTTHandler handler, IConfig props) throws IOException { final MoquetteIdleTimeoutHandler timeoutHandler = new MoquetteIdleTimeoutHandler(); String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME); - String tcpPortProp = props.getProperty(BrokerConstants.PORT_PROPERTY_NAME); - if (tcpPortProp == null || "".equals(tcpPortProp)) { - LOG.info("tcp MQTT is disabled because the value for the property with key BrokerConstants.PORT_PROPERTY_NAME is null"); + String tcpPortProp = props.getProperty(PORT_PROPERTY_NAME, DISABLED_PORT_BIND); + if (DISABLED_PORT_BIND.equals(tcpPortProp)) { + LOG.info("tcp MQTT is disabled because the value for the property with key {}", BrokerConstants.PORT_PROPERTY_NAME); return; } int port = Integer.parseInt(tcpPortProp); @@ -168,8 +169,8 @@ public class NettyAcceptor implements ServerAcceptor { } private void initializeWebSocketTransport(final NettyMQTTHandler handler, IConfig props) throws IOException { - String webSocketPortProp = props.getProperty(BrokerConstants.WEB_SOCKET_PORT_PROPERTY_NAME); - if (webSocketPortProp == null || "".equals(webSocketPortProp)) { + String webSocketPortProp = props.getProperty(WEB_SOCKET_PORT_PROPERTY_NAME, DISABLED_PORT_BIND); + if (DISABLED_PORT_BIND.equals(webSocketPortProp)) { //Do nothing no WebSocket configured LOG.info("WebSocket is disabled"); return; @@ -200,10 +201,10 @@ public class NettyAcceptor implements ServerAcceptor { } private void initializeSSLTCPTransport(final NettyMQTTHandler handler, IConfig props, final SSLContext sslContext) throws IOException { - String sslPortProp = props.getProperty(BrokerConstants.SSL_PORT_PROPERTY_NAME); - if (sslPortProp == null || "".equals(sslPortProp)) { + String sslPortProp = props.getProperty(SSL_PORT_PROPERTY_NAME, DISABLED_PORT_BIND); + if (DISABLED_PORT_BIND.equals(sslPortProp)) { //Do nothing no SSL configured - LOG.info("SSL MQTT is disabled because there is no value in properties for key BrokerConstants.SSL_PORT_PROPERTY_NAME"); + LOG.info("SSL MQTT is disabled because there is no value in properties for key {}", BrokerConstants.SSL_PORT_PROPERTY_NAME); return; } @@ -231,10 +232,10 @@ public class NettyAcceptor implements ServerAcceptor { } private void initializeWSSTransport(final NettyMQTTHandler handler, IConfig props, final SSLContext sslContext) throws IOException { - String sslPortProp = props.getProperty(BrokerConstants.WSS_PORT_PROPERTY_NAME); - if (sslPortProp == null || "".equals(sslPortProp)) { + String sslPortProp = props.getProperty(WSS_PORT_PROPERTY_NAME, DISABLED_PORT_BIND); + if (DISABLED_PORT_BIND.equals(sslPortProp)) { //Do nothing no SSL configured - LOG.info("SSL websocket is disabled because there is no value in properties for key BrokerConstants.WSS_PORT_PROPERTY_NAME"); + LOG.info("SSL websocket is disabled because there is no value in properties for key {}", BrokerConstants.WSS_PORT_PROPERTY_NAME); return; } int sslPort = Integer.parseInt(sslPortProp); diff --git a/broker/src/test/java/io/moquette/server/ConfigurationClassLoaderTest.java b/broker/src/test/java/io/moquette/server/ConfigurationClassLoaderTest.java index b91735cd..68ac1f18 100644 --- a/broker/src/test/java/io/moquette/server/ConfigurationClassLoaderTest.java +++ b/broker/src/test/java/io/moquette/server/ConfigurationClassLoaderTest.java @@ -55,7 +55,7 @@ public class ConfigurationClassLoaderTest implements IAuthenticator, IAuthorizat @Test public void loadAuthenticator() throws Exception { - Properties props = new Properties(IntegrationUtils.prepareTestPropeties()); + Properties props = new Properties(IntegrationUtils.prepareTestProperties()); props.setProperty(BrokerConstants.AUTHENTICATOR_CLASS_NAME, "io.moquette.server.ConfigurationClassLoaderTest"); startServer(props); assertTrue(true); @@ -64,7 +64,7 @@ public class ConfigurationClassLoaderTest implements IAuthenticator, IAuthorizat @Test public void loadAuthorizator() throws Exception { - Properties props = new Properties(IntegrationUtils.prepareTestPropeties()); + Properties props = new Properties(IntegrationUtils.prepareTestProperties()); props.setProperty(BrokerConstants.AUTHORIZATOR_CLASS_NAME, "io.moquette.server.ConfigurationClassLoaderTest"); startServer(props); assertTrue(true); diff --git a/broker/src/test/java/io/moquette/server/IntegrationUtils.java b/broker/src/test/java/io/moquette/server/IntegrationUtils.java index b212e1da..a065aa69 100644 --- a/broker/src/test/java/io/moquette/server/IntegrationUtils.java +++ b/broker/src/test/java/io/moquette/server/IntegrationUtils.java @@ -22,6 +22,7 @@ import java.util.Properties; import static io.moquette.BrokerConstants.DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME; import static io.moquette.BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME; +import static io.moquette.BrokerConstants.PORT_PROPERTY_NAME; import static org.junit.Assert.assertFalse; /** @@ -35,9 +36,10 @@ public class IntegrationUtils { return currentDir + File.separator + DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME; } - public static Properties prepareTestPropeties() { + public static Properties prepareTestProperties() { Properties testProperties = new Properties(); testProperties.put(PERSISTENT_STORE_PROPERTY_NAME, IntegrationUtils.localMapDBPath()); + testProperties.put(PORT_PROPERTY_NAME, "1883"); return testProperties; } diff --git a/broker/src/test/java/io/moquette/server/ServerIntegrationEmbeddedPublishTest.java b/broker/src/test/java/io/moquette/server/ServerIntegrationEmbeddedPublishTest.java index 4d9a4afa..8def3ec8 100644 --- a/broker/src/test/java/io/moquette/server/ServerIntegrationEmbeddedPublishTest.java +++ b/broker/src/test/java/io/moquette/server/ServerIntegrationEmbeddedPublishTest.java @@ -49,7 +49,7 @@ public class ServerIntegrationEmbeddedPublishTest { protected void startServer() throws IOException { m_server = new Server(); - final Properties configProps = IntegrationUtils.prepareTestPropeties(); + final Properties configProps = IntegrationUtils.prepareTestProperties(); m_config = new MemoryConfig(configProps); m_server.startServer(m_config); } diff --git a/broker/src/test/java/io/moquette/server/ServerIntegrationFuseTest.java b/broker/src/test/java/io/moquette/server/ServerIntegrationFuseTest.java index 8faaef59..4b564245 100644 --- a/broker/src/test/java/io/moquette/server/ServerIntegrationFuseTest.java +++ b/broker/src/test/java/io/moquette/server/ServerIntegrationFuseTest.java @@ -45,7 +45,7 @@ public class ServerIntegrationFuseTest { protected void startServer() throws IOException { m_server = new Server(); - final Properties configProps = IntegrationUtils.prepareTestPropeties(); + final Properties configProps = IntegrationUtils.prepareTestProperties(); m_config = new MemoryConfig(configProps); m_server.startServer(m_config); } diff --git a/broker/src/test/java/io/moquette/server/ServerIntegrationPahoTest.java b/broker/src/test/java/io/moquette/server/ServerIntegrationPahoTest.java index 47670394..ef780315 100644 --- a/broker/src/test/java/io/moquette/server/ServerIntegrationPahoTest.java +++ b/broker/src/test/java/io/moquette/server/ServerIntegrationPahoTest.java @@ -54,7 +54,7 @@ public class ServerIntegrationPahoTest { protected void startServer() throws IOException { m_server = new Server(); - final Properties configProps = IntegrationUtils.prepareTestPropeties(); + final Properties configProps = IntegrationUtils.prepareTestProperties(); m_config = new MemoryConfig(configProps); m_server.startServer(m_config); } @@ -193,7 +193,7 @@ public class ServerIntegrationPahoTest { m_server.stopServer(); - m_server.startServer(IntegrationUtils.prepareTestPropeties()); + m_server.startServer(IntegrationUtils.prepareTestProperties()); //reconnect and publish m_client.connect(options); diff --git a/broker/src/test/java/io/moquette/server/ServerIntegrationQoSValidationTest.java b/broker/src/test/java/io/moquette/server/ServerIntegrationQoSValidationTest.java index d7b7fb3f..f7d39bc4 100644 --- a/broker/src/test/java/io/moquette/server/ServerIntegrationQoSValidationTest.java +++ b/broker/src/test/java/io/moquette/server/ServerIntegrationQoSValidationTest.java @@ -62,7 +62,7 @@ public class ServerIntegrationQoSValidationTest { protected void startServer() throws IOException { m_server = new Server(); - final Properties configProps = IntegrationUtils.prepareTestPropeties(); + final Properties configProps = IntegrationUtils.prepareTestProperties(); m_config = new MemoryConfig(configProps); m_server.startServer(m_config); } diff --git a/broker/src/test/java/io/moquette/server/ServerIntegrationWebSocketTest.java b/broker/src/test/java/io/moquette/server/ServerIntegrationWebSocketTest.java index a6031354..3f7de183 100644 --- a/broker/src/test/java/io/moquette/server/ServerIntegrationWebSocketTest.java +++ b/broker/src/test/java/io/moquette/server/ServerIntegrationWebSocketTest.java @@ -48,7 +48,7 @@ public class ServerIntegrationWebSocketTest { protected void startServer() throws IOException { m_server = new Server(); - final Properties configProps = IntegrationUtils.prepareTestPropeties(); + final Properties configProps = IntegrationUtils.prepareTestProperties(); configProps.put(BrokerConstants.WEB_SOCKET_PORT_PROPERTY_NAME, Integer.toString(BrokerConstants.WEBSOCKET_PORT)); m_config = new MemoryConfig(configProps); m_server.startServer(m_config); diff --git a/broker/src/test/java/io/moquette/server/ServerLowlevelMessagesIntegrationTests.java b/broker/src/test/java/io/moquette/server/ServerLowlevelMessagesIntegrationTests.java index 2cbc05a7..864776a5 100644 --- a/broker/src/test/java/io/moquette/server/ServerLowlevelMessagesIntegrationTests.java +++ b/broker/src/test/java/io/moquette/server/ServerLowlevelMessagesIntegrationTests.java @@ -17,7 +17,6 @@ package io.moquette.server; import io.moquette.parser.proto.messages.ConnectMessage; import io.moquette.parser.proto.messages.AbstractMessage; -import io.moquette.parser.proto.messages.AbstractMessage.QOSType; import io.moquette.parser.proto.messages.ConnAckMessage; import io.moquette.server.config.IConfig; import io.moquette.server.config.MemoryConfig; @@ -50,7 +49,7 @@ public class ServerLowlevelMessagesIntegrationTests { protected void startServer() throws IOException { m_server = new Server(); - final Properties configProps = IntegrationUtils.prepareTestPropeties(); + final Properties configProps = IntegrationUtils.prepareTestProperties(); m_config = new MemoryConfig(configProps); m_server.startServer(m_config); } diff --git a/broker/src/test/java/io/moquette/server/ServerRestartIntegrationTest.java b/broker/src/test/java/io/moquette/server/ServerRestartIntegrationTest.java index b693afd4..369be309 100644 --- a/broker/src/test/java/io/moquette/server/ServerRestartIntegrationTest.java +++ b/broker/src/test/java/io/moquette/server/ServerRestartIntegrationTest.java @@ -48,7 +48,7 @@ public class ServerRestartIntegrationTest { protected void startServer() throws IOException { m_server = new Server(); - final Properties configProps = IntegrationUtils.prepareTestPropeties(); + final Properties configProps = IntegrationUtils.prepareTestProperties(); m_config = new MemoryConfig(configProps); m_server.startServer(m_config); } @@ -101,7 +101,7 @@ public class ServerRestartIntegrationTest { IntegrationUtils.cleanPersistenceFile(m_config); //restart the server - m_server.startServer(IntegrationUtils.prepareTestPropeties()); + m_server.startServer(IntegrationUtils.prepareTestProperties()); //reconnect the Subscriber subscribing to the same /topic but different QoS m_subscriber.connect(CLEAN_SESSION_OPT); @@ -128,7 +128,7 @@ public class ServerRestartIntegrationTest { m_server.stopServer(); //restart the server - m_server.startServer(IntegrationUtils.prepareTestPropeties()); + m_server.startServer(IntegrationUtils.prepareTestProperties()); m_publisher.connect(); m_publisher.publish("/topic", "Hello world MQTT!!".getBytes(), 0, false); @@ -148,7 +148,7 @@ public class ServerRestartIntegrationTest { m_server.stopServer(); //restart the server - m_server.startServer(IntegrationUtils.prepareTestPropeties()); + m_server.startServer(IntegrationUtils.prepareTestProperties()); //subscriber reconnects m_subscriber = new MqttClient("tcp://localhost:1883", "Subscriber", s_dataStore); m_subscriber.setCallback(m_messageCollector);