diff --git a/broker/src/main/java/io/moquette/BrokerConstants.java b/broker/src/main/java/io/moquette/BrokerConstants.java new file mode 100644 index 00000000..062f79ef --- /dev/null +++ b/broker/src/main/java/io/moquette/BrokerConstants.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012-2015 The original author or authors + * ------------------------------------------------------ + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Apache License v2.0 which accompanies this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * The Apache License v2.0 is available at + * http://www.opensource.org/licenses/apache2.0.php + * + * You may elect to redistribute this code under either of these licenses. + */ +package io.moquette; + +import java.io.File; + +/** + * Created by andrea on 08/12/15. + */ +public class BrokerConstants { + public static final String PERSISTENT_STORE_PROPERTY_NAME = "persistent_store"; + public static final String AUTOSAVE_INTERVAL_PROPERTY_NAME = "autosave_interval"; + public static final String PASSWORD_FILE_PROPERTY_NAME = "password_file"; + public static final String PORT_PROPERTY_NAME = "port"; + public static final String HOST_PROPERTY_NAME = "host"; + public static final String DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME = "moquette_store.mapdb"; + public static final String DEFAULT_PERSISTENT_PATH = System.getProperty("user.dir") + File.separator + DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME; + public static final String WEB_SOCKET_PORT_PROPERTY_NAME = "websocket_port"; + public static final String WSS_PORT_PROPERTY_NAME = "secure_websocket_port"; + public static final String SSL_PORT_PROPERTY_NAME = "ssl_port"; + public static final String JKS_PATH_PROPERTY_NAME = "jks_path"; + public static final String KEY_STORE_PASSWORD_PROPERTY_NAME = "key_store_password"; + public static final String KEY_MANAGER_PASSWORD_PROPERTY_NAME = "key_manager_password"; + public static final String ALLOW_ANONYMOUS_PROPERTY_NAME = "allow_anonymous"; + public static final String ACL_FILE_PROPERTY_NAME = "acl_file"; + public static final String AUTHORIZATOR_CLASS_NAME = "authorizator_class"; + public static final String AUTHENTICATOR_CLASS_NAME = "authenticator_class"; + public static final int PORT = 1883; + public static final int WEBSOCKET_PORT = 8080; + public static final String HOST = "0.0.0.0"; +} diff --git a/broker/src/main/java/io/moquette/server/Server.java b/broker/src/main/java/io/moquette/server/Server.java index 24423214..f75e047c 100644 --- a/broker/src/main/java/io/moquette/server/Server.java +++ b/broker/src/main/java/io/moquette/server/Server.java @@ -15,6 +15,7 @@ */ package io.moquette.server; +import io.moquette.BrokerConstants; import io.moquette.interception.InterceptHandler; import io.moquette.server.config.MemoryConfig; import io.moquette.spi.impl.SimpleMessaging; @@ -27,7 +28,6 @@ import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Properties; @@ -106,7 +106,7 @@ public class Server { if (handlerProp != null) { config.setProperty("intercept.handler", handlerProp); } - LOG.info("Persistent store file: " + config.getProperty(io.moquette.commons.Constants.PERSISTENT_STORE_PROPERTY_NAME)); + LOG.info("Persistent store file: " + config.getProperty(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME)); final ProtocolProcessor processor = SimpleMessaging.getInstance().init(config, handlers); m_acceptor = new NettyAcceptor(); diff --git a/broker/src/main/java/io/moquette/server/config/ConfigurationParser.java b/broker/src/main/java/io/moquette/server/config/ConfigurationParser.java index 9a560efa..094c68a5 100644 --- a/broker/src/main/java/io/moquette/server/config/ConfigurationParser.java +++ b/broker/src/main/java/io/moquette/server/config/ConfigurationParser.java @@ -15,7 +15,7 @@ */ package io.moquette.server.config; -import io.moquette.commons.Constants; +import io.moquette.BrokerConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,14 +42,14 @@ class ConfigurationParser { } private void createDefaults() { - m_properties.put(Constants.PORT_PROPERTY_NAME, Integer.toString(Constants.PORT)); - m_properties.put(Constants.HOST_PROPERTY_NAME, Constants.HOST); - m_properties.put(Constants.WEB_SOCKET_PORT_PROPERTY_NAME, Integer.toString(Constants.WEBSOCKET_PORT)); - m_properties.put(Constants.PASSWORD_FILE_PROPERTY_NAME, ""); - m_properties.put(Constants.PERSISTENT_STORE_PROPERTY_NAME, Constants.DEFAULT_PERSISTENT_PATH); - m_properties.put(Constants.ALLOW_ANONYMOUS_PROPERTY_NAME, true); - m_properties.put(Constants.AUTHENTICATOR_CLASS_NAME, ""); - m_properties.put(Constants.AUTHORIZATOR_CLASS_NAME, ""); + m_properties.put(BrokerConstants.PORT_PROPERTY_NAME, Integer.toString(BrokerConstants.PORT)); + m_properties.put(BrokerConstants.HOST_PROPERTY_NAME, BrokerConstants.HOST); + m_properties.put(BrokerConstants.WEB_SOCKET_PORT_PROPERTY_NAME, Integer.toString(BrokerConstants.WEBSOCKET_PORT)); + m_properties.put(BrokerConstants.PASSWORD_FILE_PROPERTY_NAME, ""); + m_properties.put(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, BrokerConstants.DEFAULT_PERSISTENT_PATH); + m_properties.put(BrokerConstants.ALLOW_ANONYMOUS_PROPERTY_NAME, true); + m_properties.put(BrokerConstants.AUTHENTICATOR_CLASS_NAME, ""); + m_properties.put(BrokerConstants.AUTHORIZATOR_CLASS_NAME, ""); } /** diff --git a/broker/src/main/java/io/moquette/server/config/MemoryConfig.java b/broker/src/main/java/io/moquette/server/config/MemoryConfig.java index 9ed22cfc..43534486 100644 --- a/broker/src/main/java/io/moquette/server/config/MemoryConfig.java +++ b/broker/src/main/java/io/moquette/server/config/MemoryConfig.java @@ -15,7 +15,7 @@ */ package io.moquette.server.config; -import io.moquette.commons.Constants; +import io.moquette.BrokerConstants; import java.util.Map; import java.util.Properties; @@ -37,14 +37,14 @@ public class MemoryConfig implements IConfig { } private void createDefaults() { - m_properties.put(Constants.PORT_PROPERTY_NAME, Integer.toString(Constants.PORT)); - m_properties.put(Constants.HOST_PROPERTY_NAME, Constants.HOST); - m_properties.put(Constants.WEB_SOCKET_PORT_PROPERTY_NAME, Integer.toString(Constants.WEBSOCKET_PORT)); - m_properties.put(Constants.PASSWORD_FILE_PROPERTY_NAME, ""); - m_properties.put(Constants.PERSISTENT_STORE_PROPERTY_NAME, Constants.DEFAULT_PERSISTENT_PATH); - m_properties.put(Constants.ALLOW_ANONYMOUS_PROPERTY_NAME, true); - m_properties.put(Constants.AUTHENTICATOR_CLASS_NAME, ""); - m_properties.put(Constants.AUTHORIZATOR_CLASS_NAME, ""); + m_properties.put(BrokerConstants.PORT_PROPERTY_NAME, Integer.toString(BrokerConstants.PORT)); + m_properties.put(BrokerConstants.HOST_PROPERTY_NAME, BrokerConstants.HOST); + m_properties.put(BrokerConstants.WEB_SOCKET_PORT_PROPERTY_NAME, Integer.toString(BrokerConstants.WEBSOCKET_PORT)); + m_properties.put(BrokerConstants.PASSWORD_FILE_PROPERTY_NAME, ""); + m_properties.put(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, BrokerConstants.DEFAULT_PERSISTENT_PATH); + m_properties.put(BrokerConstants.ALLOW_ANONYMOUS_PROPERTY_NAME, true); + m_properties.put(BrokerConstants.AUTHENTICATOR_CLASS_NAME, ""); + m_properties.put(BrokerConstants.AUTHORIZATOR_CLASS_NAME, ""); } @Override 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 056b96df..abc3870b 100644 --- a/broker/src/main/java/io/moquette/server/netty/NettyAcceptor.java +++ b/broker/src/main/java/io/moquette/server/netty/NettyAcceptor.java @@ -15,6 +15,7 @@ */ package io.moquette.server.netty; +import io.moquette.BrokerConstants; import io.moquette.commons.Constants; import io.moquette.parser.netty.MQTTDecoder; import io.moquette.server.config.IConfig; @@ -100,8 +101,8 @@ public class NettyAcceptor implements ServerAcceptor { initializePlainTCPTransport(handler, props); initializeWebSocketTransport(handler, props); - String sslTcpPortProp = props.getProperty(Constants.SSL_PORT_PROPERTY_NAME); - String wssPortProp = props.getProperty(Constants.WSS_PORT_PROPERTY_NAME); + String sslTcpPortProp = props.getProperty(BrokerConstants.SSL_PORT_PROPERTY_NAME); + String wssPortProp = props.getProperty(BrokerConstants.WSS_PORT_PROPERTY_NAME); if (sslTcpPortProp != null || wssPortProp != null) { SslHandlerFactory sslHandlerFactory = initSSLHandlerFactory(props); if (!sslHandlerFactory.canCreate()) { @@ -145,8 +146,8 @@ public class NettyAcceptor implements ServerAcceptor { private void initializePlainTCPTransport(final NettyMQTTHandler handler, IConfig props) throws IOException { final MoquetteIdleTimoutHandler timeoutHandler = new MoquetteIdleTimoutHandler(); - String host = props.getProperty(Constants.HOST_PROPERTY_NAME); - int port = Integer.parseInt(props.getProperty(Constants.PORT_PROPERTY_NAME)); + String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME); + int port = Integer.parseInt(props.getProperty(BrokerConstants.PORT_PROPERTY_NAME)); initFactory(host, port, new PipelineInitializer() { @Override void init(ChannelPipeline pipeline) { @@ -163,7 +164,7 @@ public class NettyAcceptor implements ServerAcceptor { } private void initializeWebSocketTransport(final NettyMQTTHandler handler, IConfig props) throws IOException { - String webSocketPortProp = props.getProperty(Constants.WEB_SOCKET_PORT_PROPERTY_NAME); + String webSocketPortProp = props.getProperty(BrokerConstants.WEB_SOCKET_PORT_PROPERTY_NAME); if (webSocketPortProp == null) { //Do nothing no WebSocket configured LOG.info("WebSocket is disabled"); @@ -173,7 +174,7 @@ public class NettyAcceptor implements ServerAcceptor { final MoquetteIdleTimoutHandler timeoutHandler = new MoquetteIdleTimoutHandler(); - String host = props.getProperty(Constants.HOST_PROPERTY_NAME); + String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME); initFactory(host, port, new PipelineInitializer() { @Override void init(ChannelPipeline pipeline) { @@ -195,7 +196,7 @@ public class NettyAcceptor implements ServerAcceptor { } private void initializeSSLTCPTransport(final NettyMQTTHandler handler, IConfig props, final SslHandlerFactory sslHandlerFactory) throws IOException { - String sslPortProp = props.getProperty(Constants.SSL_PORT_PROPERTY_NAME); + String sslPortProp = props.getProperty(BrokerConstants.SSL_PORT_PROPERTY_NAME); if (sslPortProp == null) { //Do nothing no SSL configured LOG.info("SSL is disabled"); @@ -206,7 +207,7 @@ public class NettyAcceptor implements ServerAcceptor { LOG.info("Starting SSL on port {}", sslPort); final MoquetteIdleTimoutHandler timeoutHandler = new MoquetteIdleTimoutHandler(); - String host = props.getProperty(Constants.HOST_PROPERTY_NAME); + String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME); initFactory(host, sslPort, new PipelineInitializer() { @Override void init(ChannelPipeline pipeline) throws Exception { @@ -224,7 +225,7 @@ public class NettyAcceptor implements ServerAcceptor { } private void initializeWSSTransport(final NettyMQTTHandler handler, IConfig props, final SslHandlerFactory sslHandlerFactory) throws IOException { - String sslPortProp = props.getProperty(Constants.WSS_PORT_PROPERTY_NAME); + String sslPortProp = props.getProperty(BrokerConstants.WSS_PORT_PROPERTY_NAME); if (sslPortProp == null) { //Do nothing no SSL configured LOG.info("SSL is disabled"); @@ -232,7 +233,7 @@ public class NettyAcceptor implements ServerAcceptor { } int sslPort = Integer.parseInt(sslPortProp); final MoquetteIdleTimoutHandler timeoutHandler = new MoquetteIdleTimoutHandler(); - String host = props.getProperty(Constants.HOST_PROPERTY_NAME); + String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME); initFactory(host, sslPort, new PipelineInitializer() { @Override void init(ChannelPipeline pipeline) throws Exception { @@ -301,7 +302,7 @@ public class NettyAcceptor implements ServerAcceptor { return this.sslContext != null; } private SSLContext initSSLContext(IConfig props) { - final String jksPath = props.getProperty(Constants.JKS_PATH_PROPERTY_NAME); + final String jksPath = props.getProperty(BrokerConstants.JKS_PATH_PROPERTY_NAME); LOG.info("Starting SSL using keystore at {}", jksPath); if (jksPath == null || jksPath.isEmpty()) { //key_store_password or key_manager_password are empty @@ -311,8 +312,8 @@ public class NettyAcceptor implements ServerAcceptor { //if we have the port also the jks then keyStorePassword and keyManagerPassword //has to be defined - final String keyStorePassword = props.getProperty(Constants.KEY_STORE_PASSWORD_PROPERTY_NAME); - final String keyManagerPassword = props.getProperty(Constants.KEY_MANAGER_PASSWORD_PROPERTY_NAME); + final String keyStorePassword = props.getProperty(BrokerConstants.KEY_STORE_PASSWORD_PROPERTY_NAME); + final String keyManagerPassword = props.getProperty(BrokerConstants.KEY_MANAGER_PASSWORD_PROPERTY_NAME); if (keyStorePassword == null || keyStorePassword.isEmpty()) { //key_store_password or key_manager_password are empty LOG.warn("You have configured the SSL port but not the key_store_password, SSL not started"); diff --git a/broker/src/main/java/io/moquette/spi/impl/SimpleMessaging.java b/broker/src/main/java/io/moquette/spi/impl/SimpleMessaging.java index 83f74f1f..8e71eeb9 100644 --- a/broker/src/main/java/io/moquette/spi/impl/SimpleMessaging.java +++ b/broker/src/main/java/io/moquette/spi/impl/SimpleMessaging.java @@ -15,15 +15,14 @@ */ package io.moquette.spi.impl; +import io.moquette.BrokerConstants; import io.moquette.spi.IMessagesStore; -import io.moquette.commons.Constants; import io.moquette.interception.InterceptHandler; import io.moquette.server.config.IConfig; import io.moquette.spi.ISessionsStore; import io.moquette.spi.impl.security.*; import io.moquette.spi.impl.subscriptions.SubscriptionsStore; import io.moquette.spi.persistence.MapDBPersistentStore; -import static io.moquette.commons.Constants.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -89,7 +88,7 @@ public class SimpleMessaging { subscriptions.init(sessionsStore); String configPath = System.getProperty("moquette.path", null); - String authenticatorClassName = props.getProperty(Constants.AUTHENTICATOR_CLASS_NAME, ""); + String authenticatorClassName = props.getProperty(BrokerConstants.AUTHENTICATOR_CLASS_NAME, ""); IAuthenticator authenticator = null; if (!authenticatorClassName.isEmpty()) { @@ -98,7 +97,7 @@ public class SimpleMessaging { } if (authenticator == null) { - String passwdPath = props.getProperty(PASSWORD_FILE_PROPERTY_NAME, ""); + String passwdPath = props.getProperty(BrokerConstants.PASSWORD_FILE_PROPERTY_NAME, ""); if (passwdPath.isEmpty()) { authenticator = new AcceptAllAuthenticator(); } else { @@ -107,14 +106,14 @@ public class SimpleMessaging { } IAuthorizator authorizator = null; - String authorizatorClassName = props.getProperty(Constants.AUTHORIZATOR_CLASS_NAME, ""); + String authorizatorClassName = props.getProperty(BrokerConstants.AUTHORIZATOR_CLASS_NAME, ""); if (!authorizatorClassName.isEmpty()) { authorizator = (IAuthorizator)loadClass(authorizatorClassName, IAuthorizator.class); LOG.info("Loaded custom authorizator {}", authorizatorClassName); } if (authorizator == null) { - String aclFilePath = props.getProperty(ACL_FILE_PROPERTY_NAME, ""); + String aclFilePath = props.getProperty(BrokerConstants.ACL_FILE_PROPERTY_NAME, ""); if (aclFilePath != null && !aclFilePath.isEmpty()) { authorizator = new DenyAllAuthorizator(); File aclFile = new File(configPath, aclFilePath); @@ -131,7 +130,7 @@ public class SimpleMessaging { } - boolean allowAnonymous = Boolean.parseBoolean(props.getProperty(ALLOW_ANONYMOUS_PROPERTY_NAME, "true")); + boolean allowAnonymous = Boolean.parseBoolean(props.getProperty(BrokerConstants.ALLOW_ANONYMOUS_PROPERTY_NAME, "true")); m_processor.init(subscriptions, messagesStore, sessionsStore, authenticator, allowAnonymous, authorizator, m_interceptor); return m_processor; } diff --git a/broker/src/main/java/io/moquette/spi/persistence/MapDBPersistentStore.java b/broker/src/main/java/io/moquette/spi/persistence/MapDBPersistentStore.java index 590043ad..4d355990 100644 --- a/broker/src/main/java/io/moquette/spi/persistence/MapDBPersistentStore.java +++ b/broker/src/main/java/io/moquette/spi/persistence/MapDBPersistentStore.java @@ -32,8 +32,8 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; -import static io.moquette.commons.Constants.PERSISTENT_STORE_PROPERTY_NAME; -import static io.moquette.commons.Constants.AUTOSAVE_INTERVAL_PROPERTY_NAME; +import static io.moquette.BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME; +import static io.moquette.BrokerConstants.AUTOSAVE_INTERVAL_PROPERTY_NAME; /** * MapDB main persistence implementation diff --git a/broker/src/test/java/io/moquette/server/ConfigurationClassLoaderTest.java b/broker/src/test/java/io/moquette/server/ConfigurationClassLoaderTest.java index 449e98b3..1344b004 100644 --- a/broker/src/test/java/io/moquette/server/ConfigurationClassLoaderTest.java +++ b/broker/src/test/java/io/moquette/server/ConfigurationClassLoaderTest.java @@ -15,15 +15,13 @@ */ package io.moquette.server; -import io.moquette.commons.Constants; +import io.moquette.BrokerConstants; import io.moquette.server.config.IConfig; import io.moquette.server.config.MemoryConfig; import io.moquette.spi.impl.security.IAuthenticator; import io.moquette.spi.impl.security.IAuthorizator; import org.junit.After; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; @@ -49,7 +47,7 @@ public class ConfigurationClassLoaderTest implements IAuthenticator, IAuthorizat @After public void tearDown() throws Exception { m_server.stopServer(); - File dbFile = new File(m_config.getProperty(io.moquette.commons.Constants.PERSISTENT_STORE_PROPERTY_NAME)); + File dbFile = new File(m_config.getProperty(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME)); if (dbFile.exists()) { dbFile.delete(); } @@ -58,7 +56,7 @@ public class ConfigurationClassLoaderTest implements IAuthenticator, IAuthorizat @Test public void loadAuthenticator() throws Exception { Properties props = new Properties(IntegrationUtils.prepareTestPropeties()); - props.setProperty(Constants.AUTHENTICATOR_CLASS_NAME, "io.moquette.server.ConfigurationClassLoaderTest"); + props.setProperty(BrokerConstants.AUTHENTICATOR_CLASS_NAME, "io.moquette.server.ConfigurationClassLoaderTest"); startServer(props); assertTrue(true); m_server.stopServer(); @@ -67,7 +65,7 @@ public class ConfigurationClassLoaderTest implements IAuthenticator, IAuthorizat @Test public void loadAuthorizator() throws Exception { Properties props = new Properties(IntegrationUtils.prepareTestPropeties()); - props.setProperty(Constants.AUTHORIZATOR_CLASS_NAME, "io.moquette.server.ConfigurationClassLoaderTest"); + props.setProperty(BrokerConstants.AUTHORIZATOR_CLASS_NAME, "io.moquette.server.ConfigurationClassLoaderTest"); startServer(props); assertTrue(true); m_server.stopServer(); diff --git a/broker/src/test/java/io/moquette/server/IntegrationUtils.java b/broker/src/test/java/io/moquette/server/IntegrationUtils.java index 67b2e883..b212e1da 100644 --- a/broker/src/test/java/io/moquette/server/IntegrationUtils.java +++ b/broker/src/test/java/io/moquette/server/IntegrationUtils.java @@ -20,8 +20,8 @@ import io.moquette.server.config.IConfig; import java.io.File; import java.util.Properties; -import static io.moquette.commons.Constants.DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME; -import static io.moquette.commons.Constants.PERSISTENT_STORE_PROPERTY_NAME; +import static io.moquette.BrokerConstants.DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME; +import static io.moquette.BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME; import static org.junit.Assert.assertFalse; /** diff --git a/broker/src/test/java/io/moquette/server/ServerIntegrationSSLTest.java b/broker/src/test/java/io/moquette/server/ServerIntegrationSSLTest.java index f424a12c..735dcd3f 100644 --- a/broker/src/test/java/io/moquette/server/ServerIntegrationSSLTest.java +++ b/broker/src/test/java/io/moquette/server/ServerIntegrationSSLTest.java @@ -34,7 +34,7 @@ import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; -import io.moquette.commons.Constants; +import io.moquette.BrokerConstants; import org.eclipse.paho.client.mqttv3.IMqttClient; import org.eclipse.paho.client.mqttv3.MqttClient; import org.eclipse.paho.client.mqttv3.MqttClientPersistence; @@ -75,11 +75,11 @@ public class ServerIntegrationSSLTest { m_server = new Server(); Properties sslProps = new Properties(); - sslProps.put(io.moquette.commons.Constants.SSL_PORT_PROPERTY_NAME, "8883"); - sslProps.put(Constants.JKS_PATH_PROPERTY_NAME, "serverkeystore.jks"); - sslProps.put(Constants.KEY_STORE_PASSWORD_PROPERTY_NAME, "passw0rdsrv"); - sslProps.put(Constants.KEY_MANAGER_PASSWORD_PROPERTY_NAME, "passw0rdsrv"); - sslProps.put(Constants.PERSISTENT_STORE_PROPERTY_NAME, IntegrationUtils.localMapDBPath()); + sslProps.put(BrokerConstants.SSL_PORT_PROPERTY_NAME, "8883"); + sslProps.put(BrokerConstants.JKS_PATH_PROPERTY_NAME, "serverkeystore.jks"); + sslProps.put(BrokerConstants.KEY_STORE_PASSWORD_PROPERTY_NAME, "passw0rdsrv"); + sslProps.put(BrokerConstants.KEY_MANAGER_PASSWORD_PROPERTY_NAME, "passw0rdsrv"); + sslProps.put(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, IntegrationUtils.localMapDBPath()); m_server.startServer(sslProps); } diff --git a/broker/src/test/java/io/moquette/server/ServerIntegrationWebSocketTest.java b/broker/src/test/java/io/moquette/server/ServerIntegrationWebSocketTest.java index 218f3138..3f97582f 100644 --- a/broker/src/test/java/io/moquette/server/ServerIntegrationWebSocketTest.java +++ b/broker/src/test/java/io/moquette/server/ServerIntegrationWebSocketTest.java @@ -15,6 +15,7 @@ */ package io.moquette.server; +import io.moquette.BrokerConstants; import io.moquette.server.config.MemoryConfig; import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; import org.eclipse.jetty.websocket.client.WebSocketClient; @@ -69,7 +70,7 @@ public class ServerIntegrationWebSocketTest { @Test public void checkPlainConnect() throws Exception { LOG.info("*** checkPlainConnect ***"); - String destUri = "ws://localhost:" + io.moquette.commons.Constants.WEBSOCKET_PORT; + String destUri = "ws://localhost:" + BrokerConstants.WEBSOCKET_PORT; MQTTWebSocket socket = new MQTTWebSocket(); client.start(); diff --git a/broker/src/test/java/io/moquette/server/config/ConfigurationParserTest.java b/broker/src/test/java/io/moquette/server/config/ConfigurationParserTest.java index f94d24eb..dddfef62 100644 --- a/broker/src/test/java/io/moquette/server/config/ConfigurationParserTest.java +++ b/broker/src/test/java/io/moquette/server/config/ConfigurationParserTest.java @@ -15,7 +15,7 @@ */ package io.moquette.server.config; -import io.moquette.commons.Constants; +import io.moquette.BrokerConstants; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -101,7 +101,7 @@ public class ConfigurationParserTest { * Helper method to verify default options. */ private void verifyDefaults(Properties props) { - Assert.assertEquals(Constants.PORT, Integer.parseInt(props.getProperty("port"))); - Assert.assertEquals(Constants.HOST, props.getProperty("host")); + Assert.assertEquals(BrokerConstants.PORT, Integer.parseInt(props.getProperty("port"))); + Assert.assertEquals(BrokerConstants.HOST, props.getProperty("host")); } } \ No newline at end of file diff --git a/broker/src/test/java/io/moquette/spec/v3_1_1/connection/ConnectionIT.java b/broker/src/test/java/io/moquette/spec/v3_1_1/connection/ConnectionIT.java index fbe86d14..669f958a 100644 --- a/broker/src/test/java/io/moquette/spec/v3_1_1/connection/ConnectionIT.java +++ b/broker/src/test/java/io/moquette/spec/v3_1_1/connection/ConnectionIT.java @@ -21,7 +21,7 @@ import static org.junit.Assert.assertTrue; import java.io.File; import java.io.IOException; -import io.moquette.commons.Constants; +import io.moquette.BrokerConstants; import io.moquette.server.Server; import io.moquette.testclient.RawClient; import org.junit.After; @@ -52,9 +52,9 @@ public class ConnectionIT { public void tearDown() throws Exception { m_server.stopServer(); - File dbFile = new File(Constants.DEFAULT_PERSISTENT_PATH); + File dbFile = new File(BrokerConstants.DEFAULT_PERSISTENT_PATH); if (dbFile.exists()) { - assertTrue("Error deleting the moquette db file " + Constants.DEFAULT_PERSISTENT_PATH, dbFile.delete()); + assertTrue("Error deleting the moquette db file " + BrokerConstants.DEFAULT_PERSISTENT_PATH, dbFile.delete()); } assertFalse(dbFile.exists()); } diff --git a/broker/src/test/java/io/moquette/spi/persistence/MapDBPersistentStoreTest.java b/broker/src/test/java/io/moquette/spi/persistence/MapDBPersistentStoreTest.java index 9121820d..ea0cab6a 100644 --- a/broker/src/test/java/io/moquette/spi/persistence/MapDBPersistentStoreTest.java +++ b/broker/src/test/java/io/moquette/spi/persistence/MapDBPersistentStoreTest.java @@ -15,8 +15,7 @@ */ package io.moquette.spi.persistence; -import io.moquette.commons.Constants; -import static io.moquette.commons.Constants.*; +import io.moquette.BrokerConstants; import io.moquette.server.IntegrationUtils; import io.moquette.server.config.IConfig; import io.moquette.server.config.MemoryConfig; @@ -48,9 +47,9 @@ public class MapDBPersistentStoreTest { @Before public void setUp() throws Exception { - IntegrationUtils.cleanPersistenceFile(Constants.DEFAULT_PERSISTENT_PATH); + IntegrationUtils.cleanPersistenceFile(BrokerConstants.DEFAULT_PERSISTENT_PATH); Properties props = new Properties(); - props.setProperty(PERSISTENT_STORE_PROPERTY_NAME, DEFAULT_PERSISTENT_PATH); + props.setProperty(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, BrokerConstants.DEFAULT_PERSISTENT_PATH); IConfig conf = new MemoryConfig(props); m_storageService = new MapDBPersistentStore(conf); m_storageService.initStore(); @@ -64,7 +63,7 @@ public class MapDBPersistentStoreTest { m_storageService.close(); } - IntegrationUtils.cleanPersistenceFile(Constants.DEFAULT_PERSISTENT_PATH); + IntegrationUtils.cleanPersistenceFile(BrokerConstants.DEFAULT_PERSISTENT_PATH); } @Test diff --git a/broker/src/test/java/io/moquette/testclient/Client.java b/broker/src/test/java/io/moquette/testclient/Client.java index 5445fe38..89b57234 100644 --- a/broker/src/test/java/io/moquette/testclient/Client.java +++ b/broker/src/test/java/io/moquette/testclient/Client.java @@ -15,7 +15,7 @@ */ package io.moquette.testclient; -import io.moquette.commons.Constants; +import io.moquette.BrokerConstants; import io.moquette.parser.netty.MQTTDecoder; import io.moquette.parser.netty.MQTTEncoder; import io.netty.bootstrap.Bootstrap; @@ -50,7 +50,7 @@ public class Client { private boolean m_connectionLost = false; public Client(String host) { - this(host, Constants.PORT); + this(host, BrokerConstants.PORT); } public Client(String host, int port) { diff --git a/parser_commons/src/main/java/io/moquette/commons/Constants.java b/parser_commons/src/main/java/io/moquette/commons/Constants.java index 4389d2a4..508053e4 100644 --- a/parser_commons/src/main/java/io/moquette/commons/Constants.java +++ b/parser_commons/src/main/java/io/moquette/commons/Constants.java @@ -21,26 +21,6 @@ import java.io.File; * Contains some useful constants. */ public class Constants { - public static final int PORT = 1883; - public static final int WEBSOCKET_PORT = 8080; - public static final String HOST = "0.0.0.0"; public static final int DEFAULT_CONNECT_TIMEOUT = 10; - public static final String DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME = "moquette_store.mapdb"; - public static final String DEFAULT_PERSISTENT_PATH = System.getProperty("user.dir") + File.separator + DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME; - public static final String PERSISTENT_STORE_PROPERTY_NAME = "persistent_store"; - public static final String AUTOSAVE_INTERVAL_PROPERTY_NAME = "autosave_interval"; - public static final String PASSWORD_FILE_PROPERTY_NAME = "password_file"; - public static final String PORT_PROPERTY_NAME = "port"; - public static final String HOST_PROPERTY_NAME = "host"; - public static final String WEB_SOCKET_PORT_PROPERTY_NAME = "websocket_port"; - public static final String WSS_PORT_PROPERTY_NAME = "secure_websocket_port"; - public static final String SSL_PORT_PROPERTY_NAME = "ssl_port"; - public static final String JKS_PATH_PROPERTY_NAME = "jks_path"; - public static final String KEY_STORE_PASSWORD_PROPERTY_NAME = "key_store_password"; - public static final String KEY_MANAGER_PASSWORD_PROPERTY_NAME = "key_manager_password"; - public static final String ALLOW_ANONYMOUS_PROPERTY_NAME = "allow_anonymous"; - public static final String ACL_FILE_PROPERTY_NAME = "acl_file"; - public static final String AUTHORIZATOR_CLASS_NAME = "authorizator_class"; - public static final String AUTHENTICATOR_CLASS_NAME = "authenticator_class"; - + }