Minor change, moved const definition from Constants inside parser-commons to BrokerConstants inside broker project

This commit is contained in:
andsel
2015-12-08 14:04:35 +01:00
parent f41f7dafb9
commit 8c88567c78
16 changed files with 113 additions and 91 deletions
@@ -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";
}
@@ -15,6 +15,7 @@
*/ */
package io.moquette.server; package io.moquette.server;
import io.moquette.BrokerConstants;
import io.moquette.interception.InterceptHandler; import io.moquette.interception.InterceptHandler;
import io.moquette.server.config.MemoryConfig; import io.moquette.server.config.MemoryConfig;
import io.moquette.spi.impl.SimpleMessaging; import io.moquette.spi.impl.SimpleMessaging;
@@ -27,7 +28,6 @@ import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
@@ -106,7 +106,7 @@ public class Server {
if (handlerProp != null) { if (handlerProp != null) {
config.setProperty("intercept.handler", handlerProp); 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); final ProtocolProcessor processor = SimpleMessaging.getInstance().init(config, handlers);
m_acceptor = new NettyAcceptor(); m_acceptor = new NettyAcceptor();
@@ -15,7 +15,7 @@
*/ */
package io.moquette.server.config; package io.moquette.server.config;
import io.moquette.commons.Constants; import io.moquette.BrokerConstants;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -42,14 +42,14 @@ class ConfigurationParser {
} }
private void createDefaults() { private void createDefaults() {
m_properties.put(Constants.PORT_PROPERTY_NAME, Integer.toString(Constants.PORT)); m_properties.put(BrokerConstants.PORT_PROPERTY_NAME, Integer.toString(BrokerConstants.PORT));
m_properties.put(Constants.HOST_PROPERTY_NAME, Constants.HOST); m_properties.put(BrokerConstants.HOST_PROPERTY_NAME, BrokerConstants.HOST);
m_properties.put(Constants.WEB_SOCKET_PORT_PROPERTY_NAME, Integer.toString(Constants.WEBSOCKET_PORT)); m_properties.put(BrokerConstants.WEB_SOCKET_PORT_PROPERTY_NAME, Integer.toString(BrokerConstants.WEBSOCKET_PORT));
m_properties.put(Constants.PASSWORD_FILE_PROPERTY_NAME, ""); m_properties.put(BrokerConstants.PASSWORD_FILE_PROPERTY_NAME, "");
m_properties.put(Constants.PERSISTENT_STORE_PROPERTY_NAME, Constants.DEFAULT_PERSISTENT_PATH); m_properties.put(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, BrokerConstants.DEFAULT_PERSISTENT_PATH);
m_properties.put(Constants.ALLOW_ANONYMOUS_PROPERTY_NAME, true); m_properties.put(BrokerConstants.ALLOW_ANONYMOUS_PROPERTY_NAME, true);
m_properties.put(Constants.AUTHENTICATOR_CLASS_NAME, ""); m_properties.put(BrokerConstants.AUTHENTICATOR_CLASS_NAME, "");
m_properties.put(Constants.AUTHORIZATOR_CLASS_NAME, ""); m_properties.put(BrokerConstants.AUTHORIZATOR_CLASS_NAME, "");
} }
/** /**
@@ -15,7 +15,7 @@
*/ */
package io.moquette.server.config; package io.moquette.server.config;
import io.moquette.commons.Constants; import io.moquette.BrokerConstants;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
@@ -37,14 +37,14 @@ public class MemoryConfig implements IConfig {
} }
private void createDefaults() { private void createDefaults() {
m_properties.put(Constants.PORT_PROPERTY_NAME, Integer.toString(Constants.PORT)); m_properties.put(BrokerConstants.PORT_PROPERTY_NAME, Integer.toString(BrokerConstants.PORT));
m_properties.put(Constants.HOST_PROPERTY_NAME, Constants.HOST); m_properties.put(BrokerConstants.HOST_PROPERTY_NAME, BrokerConstants.HOST);
m_properties.put(Constants.WEB_SOCKET_PORT_PROPERTY_NAME, Integer.toString(Constants.WEBSOCKET_PORT)); m_properties.put(BrokerConstants.WEB_SOCKET_PORT_PROPERTY_NAME, Integer.toString(BrokerConstants.WEBSOCKET_PORT));
m_properties.put(Constants.PASSWORD_FILE_PROPERTY_NAME, ""); m_properties.put(BrokerConstants.PASSWORD_FILE_PROPERTY_NAME, "");
m_properties.put(Constants.PERSISTENT_STORE_PROPERTY_NAME, Constants.DEFAULT_PERSISTENT_PATH); m_properties.put(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, BrokerConstants.DEFAULT_PERSISTENT_PATH);
m_properties.put(Constants.ALLOW_ANONYMOUS_PROPERTY_NAME, true); m_properties.put(BrokerConstants.ALLOW_ANONYMOUS_PROPERTY_NAME, true);
m_properties.put(Constants.AUTHENTICATOR_CLASS_NAME, ""); m_properties.put(BrokerConstants.AUTHENTICATOR_CLASS_NAME, "");
m_properties.put(Constants.AUTHORIZATOR_CLASS_NAME, ""); m_properties.put(BrokerConstants.AUTHORIZATOR_CLASS_NAME, "");
} }
@Override @Override
@@ -15,6 +15,7 @@
*/ */
package io.moquette.server.netty; package io.moquette.server.netty;
import io.moquette.BrokerConstants;
import io.moquette.commons.Constants; import io.moquette.commons.Constants;
import io.moquette.parser.netty.MQTTDecoder; import io.moquette.parser.netty.MQTTDecoder;
import io.moquette.server.config.IConfig; import io.moquette.server.config.IConfig;
@@ -100,8 +101,8 @@ public class NettyAcceptor implements ServerAcceptor {
initializePlainTCPTransport(handler, props); initializePlainTCPTransport(handler, props);
initializeWebSocketTransport(handler, props); initializeWebSocketTransport(handler, props);
String sslTcpPortProp = props.getProperty(Constants.SSL_PORT_PROPERTY_NAME); String sslTcpPortProp = props.getProperty(BrokerConstants.SSL_PORT_PROPERTY_NAME);
String wssPortProp = props.getProperty(Constants.WSS_PORT_PROPERTY_NAME); String wssPortProp = props.getProperty(BrokerConstants.WSS_PORT_PROPERTY_NAME);
if (sslTcpPortProp != null || wssPortProp != null) { if (sslTcpPortProp != null || wssPortProp != null) {
SslHandlerFactory sslHandlerFactory = initSSLHandlerFactory(props); SslHandlerFactory sslHandlerFactory = initSSLHandlerFactory(props);
if (!sslHandlerFactory.canCreate()) { if (!sslHandlerFactory.canCreate()) {
@@ -145,8 +146,8 @@ public class NettyAcceptor implements ServerAcceptor {
private void initializePlainTCPTransport(final NettyMQTTHandler handler, IConfig props) throws IOException { private void initializePlainTCPTransport(final NettyMQTTHandler handler, IConfig props) throws IOException {
final MoquetteIdleTimoutHandler timeoutHandler = new MoquetteIdleTimoutHandler(); final MoquetteIdleTimoutHandler timeoutHandler = new MoquetteIdleTimoutHandler();
String host = props.getProperty(Constants.HOST_PROPERTY_NAME); String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME);
int port = Integer.parseInt(props.getProperty(Constants.PORT_PROPERTY_NAME)); int port = Integer.parseInt(props.getProperty(BrokerConstants.PORT_PROPERTY_NAME));
initFactory(host, port, new PipelineInitializer() { initFactory(host, port, new PipelineInitializer() {
@Override @Override
void init(ChannelPipeline pipeline) { void init(ChannelPipeline pipeline) {
@@ -163,7 +164,7 @@ public class NettyAcceptor implements ServerAcceptor {
} }
private void initializeWebSocketTransport(final NettyMQTTHandler handler, IConfig props) throws IOException { 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) { if (webSocketPortProp == null) {
//Do nothing no WebSocket configured //Do nothing no WebSocket configured
LOG.info("WebSocket is disabled"); LOG.info("WebSocket is disabled");
@@ -173,7 +174,7 @@ public class NettyAcceptor implements ServerAcceptor {
final MoquetteIdleTimoutHandler timeoutHandler = new MoquetteIdleTimoutHandler(); 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() { initFactory(host, port, new PipelineInitializer() {
@Override @Override
void init(ChannelPipeline pipeline) { 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 { 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) { if (sslPortProp == null) {
//Do nothing no SSL configured //Do nothing no SSL configured
LOG.info("SSL is disabled"); LOG.info("SSL is disabled");
@@ -206,7 +207,7 @@ public class NettyAcceptor implements ServerAcceptor {
LOG.info("Starting SSL on port {}", sslPort); LOG.info("Starting SSL on port {}", sslPort);
final MoquetteIdleTimoutHandler timeoutHandler = new MoquetteIdleTimoutHandler(); 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() { initFactory(host, sslPort, new PipelineInitializer() {
@Override @Override
void init(ChannelPipeline pipeline) throws Exception { 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 { 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) { if (sslPortProp == null) {
//Do nothing no SSL configured //Do nothing no SSL configured
LOG.info("SSL is disabled"); LOG.info("SSL is disabled");
@@ -232,7 +233,7 @@ public class NettyAcceptor implements ServerAcceptor {
} }
int sslPort = Integer.parseInt(sslPortProp); int sslPort = Integer.parseInt(sslPortProp);
final MoquetteIdleTimoutHandler timeoutHandler = new MoquetteIdleTimoutHandler(); 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() { initFactory(host, sslPort, new PipelineInitializer() {
@Override @Override
void init(ChannelPipeline pipeline) throws Exception { void init(ChannelPipeline pipeline) throws Exception {
@@ -301,7 +302,7 @@ public class NettyAcceptor implements ServerAcceptor {
return this.sslContext != null; return this.sslContext != null;
} }
private SSLContext initSSLContext(IConfig props) { 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); LOG.info("Starting SSL using keystore at {}", jksPath);
if (jksPath == null || jksPath.isEmpty()) { if (jksPath == null || jksPath.isEmpty()) {
//key_store_password or key_manager_password are empty //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 //if we have the port also the jks then keyStorePassword and keyManagerPassword
//has to be defined //has to be defined
final String keyStorePassword = props.getProperty(Constants.KEY_STORE_PASSWORD_PROPERTY_NAME); final String keyStorePassword = props.getProperty(BrokerConstants.KEY_STORE_PASSWORD_PROPERTY_NAME);
final String keyManagerPassword = props.getProperty(Constants.KEY_MANAGER_PASSWORD_PROPERTY_NAME); final String keyManagerPassword = props.getProperty(BrokerConstants.KEY_MANAGER_PASSWORD_PROPERTY_NAME);
if (keyStorePassword == null || keyStorePassword.isEmpty()) { if (keyStorePassword == null || keyStorePassword.isEmpty()) {
//key_store_password or key_manager_password are empty //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"); LOG.warn("You have configured the SSL port but not the key_store_password, SSL not started");
@@ -15,15 +15,14 @@
*/ */
package io.moquette.spi.impl; package io.moquette.spi.impl;
import io.moquette.BrokerConstants;
import io.moquette.spi.IMessagesStore; import io.moquette.spi.IMessagesStore;
import io.moquette.commons.Constants;
import io.moquette.interception.InterceptHandler; import io.moquette.interception.InterceptHandler;
import io.moquette.server.config.IConfig; import io.moquette.server.config.IConfig;
import io.moquette.spi.ISessionsStore; import io.moquette.spi.ISessionsStore;
import io.moquette.spi.impl.security.*; import io.moquette.spi.impl.security.*;
import io.moquette.spi.impl.subscriptions.SubscriptionsStore; import io.moquette.spi.impl.subscriptions.SubscriptionsStore;
import io.moquette.spi.persistence.MapDBPersistentStore; import io.moquette.spi.persistence.MapDBPersistentStore;
import static io.moquette.commons.Constants.*;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -89,7 +88,7 @@ public class SimpleMessaging {
subscriptions.init(sessionsStore); subscriptions.init(sessionsStore);
String configPath = System.getProperty("moquette.path", null); 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; IAuthenticator authenticator = null;
if (!authenticatorClassName.isEmpty()) { if (!authenticatorClassName.isEmpty()) {
@@ -98,7 +97,7 @@ public class SimpleMessaging {
} }
if (authenticator == null) { if (authenticator == null) {
String passwdPath = props.getProperty(PASSWORD_FILE_PROPERTY_NAME, ""); String passwdPath = props.getProperty(BrokerConstants.PASSWORD_FILE_PROPERTY_NAME, "");
if (passwdPath.isEmpty()) { if (passwdPath.isEmpty()) {
authenticator = new AcceptAllAuthenticator(); authenticator = new AcceptAllAuthenticator();
} else { } else {
@@ -107,14 +106,14 @@ public class SimpleMessaging {
} }
IAuthorizator authorizator = null; IAuthorizator authorizator = null;
String authorizatorClassName = props.getProperty(Constants.AUTHORIZATOR_CLASS_NAME, ""); String authorizatorClassName = props.getProperty(BrokerConstants.AUTHORIZATOR_CLASS_NAME, "");
if (!authorizatorClassName.isEmpty()) { if (!authorizatorClassName.isEmpty()) {
authorizator = (IAuthorizator)loadClass(authorizatorClassName, IAuthorizator.class); authorizator = (IAuthorizator)loadClass(authorizatorClassName, IAuthorizator.class);
LOG.info("Loaded custom authorizator {}", authorizatorClassName); LOG.info("Loaded custom authorizator {}", authorizatorClassName);
} }
if (authorizator == null) { 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()) { if (aclFilePath != null && !aclFilePath.isEmpty()) {
authorizator = new DenyAllAuthorizator(); authorizator = new DenyAllAuthorizator();
File aclFile = new File(configPath, aclFilePath); 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); m_processor.init(subscriptions, messagesStore, sessionsStore, authenticator, allowAnonymous, authorizator, m_interceptor);
return m_processor; return m_processor;
} }
@@ -32,8 +32,8 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static io.moquette.commons.Constants.PERSISTENT_STORE_PROPERTY_NAME; import static io.moquette.BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME;
import static io.moquette.commons.Constants.AUTOSAVE_INTERVAL_PROPERTY_NAME; import static io.moquette.BrokerConstants.AUTOSAVE_INTERVAL_PROPERTY_NAME;
/** /**
* MapDB main persistence implementation * MapDB main persistence implementation
@@ -15,15 +15,13 @@
*/ */
package io.moquette.server; package io.moquette.server;
import io.moquette.commons.Constants; import io.moquette.BrokerConstants;
import io.moquette.server.config.IConfig; import io.moquette.server.config.IConfig;
import io.moquette.server.config.MemoryConfig; import io.moquette.server.config.MemoryConfig;
import io.moquette.spi.impl.security.IAuthenticator; import io.moquette.spi.impl.security.IAuthenticator;
import io.moquette.spi.impl.security.IAuthorizator; import io.moquette.spi.impl.security.IAuthorizator;
import org.junit.After; import org.junit.After;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -49,7 +47,7 @@ public class ConfigurationClassLoaderTest implements IAuthenticator, IAuthorizat
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
m_server.stopServer(); 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()) { if (dbFile.exists()) {
dbFile.delete(); dbFile.delete();
} }
@@ -58,7 +56,7 @@ public class ConfigurationClassLoaderTest implements IAuthenticator, IAuthorizat
@Test @Test
public void loadAuthenticator() throws Exception { public void loadAuthenticator() throws Exception {
Properties props = new Properties(IntegrationUtils.prepareTestPropeties()); 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); startServer(props);
assertTrue(true); assertTrue(true);
m_server.stopServer(); m_server.stopServer();
@@ -67,7 +65,7 @@ public class ConfigurationClassLoaderTest implements IAuthenticator, IAuthorizat
@Test @Test
public void loadAuthorizator() throws Exception { public void loadAuthorizator() throws Exception {
Properties props = new Properties(IntegrationUtils.prepareTestPropeties()); 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); startServer(props);
assertTrue(true); assertTrue(true);
m_server.stopServer(); m_server.stopServer();
@@ -20,8 +20,8 @@ import io.moquette.server.config.IConfig;
import java.io.File; import java.io.File;
import java.util.Properties; import java.util.Properties;
import static io.moquette.commons.Constants.DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME; import static io.moquette.BrokerConstants.DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME;
import static io.moquette.commons.Constants.PERSISTENT_STORE_PROPERTY_NAME; import static io.moquette.BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
/** /**
@@ -34,7 +34,7 @@ import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory; 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.IMqttClient;
import org.eclipse.paho.client.mqttv3.MqttClient; import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttClientPersistence; import org.eclipse.paho.client.mqttv3.MqttClientPersistence;
@@ -75,11 +75,11 @@ public class ServerIntegrationSSLTest {
m_server = new Server(); m_server = new Server();
Properties sslProps = new Properties(); Properties sslProps = new Properties();
sslProps.put(io.moquette.commons.Constants.SSL_PORT_PROPERTY_NAME, "8883"); sslProps.put(BrokerConstants.SSL_PORT_PROPERTY_NAME, "8883");
sslProps.put(Constants.JKS_PATH_PROPERTY_NAME, "serverkeystore.jks"); sslProps.put(BrokerConstants.JKS_PATH_PROPERTY_NAME, "serverkeystore.jks");
sslProps.put(Constants.KEY_STORE_PASSWORD_PROPERTY_NAME, "passw0rdsrv"); sslProps.put(BrokerConstants.KEY_STORE_PASSWORD_PROPERTY_NAME, "passw0rdsrv");
sslProps.put(Constants.KEY_MANAGER_PASSWORD_PROPERTY_NAME, "passw0rdsrv"); sslProps.put(BrokerConstants.KEY_MANAGER_PASSWORD_PROPERTY_NAME, "passw0rdsrv");
sslProps.put(Constants.PERSISTENT_STORE_PROPERTY_NAME, IntegrationUtils.localMapDBPath()); sslProps.put(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, IntegrationUtils.localMapDBPath());
m_server.startServer(sslProps); m_server.startServer(sslProps);
} }
@@ -15,6 +15,7 @@
*/ */
package io.moquette.server; package io.moquette.server;
import io.moquette.BrokerConstants;
import io.moquette.server.config.MemoryConfig; import io.moquette.server.config.MemoryConfig;
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
import org.eclipse.jetty.websocket.client.WebSocketClient; import org.eclipse.jetty.websocket.client.WebSocketClient;
@@ -69,7 +70,7 @@ public class ServerIntegrationWebSocketTest {
@Test @Test
public void checkPlainConnect() throws Exception { public void checkPlainConnect() throws Exception {
LOG.info("*** checkPlainConnect ***"); LOG.info("*** checkPlainConnect ***");
String destUri = "ws://localhost:" + io.moquette.commons.Constants.WEBSOCKET_PORT; String destUri = "ws://localhost:" + BrokerConstants.WEBSOCKET_PORT;
MQTTWebSocket socket = new MQTTWebSocket(); MQTTWebSocket socket = new MQTTWebSocket();
client.start(); client.start();
@@ -15,7 +15,7 @@
*/ */
package io.moquette.server.config; package io.moquette.server.config;
import io.moquette.commons.Constants; import io.moquette.BrokerConstants;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -101,7 +101,7 @@ public class ConfigurationParserTest {
* Helper method to verify default options. * Helper method to verify default options.
*/ */
private void verifyDefaults(Properties props) { private void verifyDefaults(Properties props) {
Assert.assertEquals(Constants.PORT, Integer.parseInt(props.getProperty("port"))); Assert.assertEquals(BrokerConstants.PORT, Integer.parseInt(props.getProperty("port")));
Assert.assertEquals(Constants.HOST, props.getProperty("host")); Assert.assertEquals(BrokerConstants.HOST, props.getProperty("host"));
} }
} }
@@ -21,7 +21,7 @@ import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import io.moquette.commons.Constants; import io.moquette.BrokerConstants;
import io.moquette.server.Server; import io.moquette.server.Server;
import io.moquette.testclient.RawClient; import io.moquette.testclient.RawClient;
import org.junit.After; import org.junit.After;
@@ -52,9 +52,9 @@ public class ConnectionIT {
public void tearDown() throws Exception { public void tearDown() throws Exception {
m_server.stopServer(); m_server.stopServer();
File dbFile = new File(Constants.DEFAULT_PERSISTENT_PATH); File dbFile = new File(BrokerConstants.DEFAULT_PERSISTENT_PATH);
if (dbFile.exists()) { 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()); assertFalse(dbFile.exists());
} }
@@ -15,8 +15,7 @@
*/ */
package io.moquette.spi.persistence; package io.moquette.spi.persistence;
import io.moquette.commons.Constants; import io.moquette.BrokerConstants;
import static io.moquette.commons.Constants.*;
import io.moquette.server.IntegrationUtils; import io.moquette.server.IntegrationUtils;
import io.moquette.server.config.IConfig; import io.moquette.server.config.IConfig;
import io.moquette.server.config.MemoryConfig; import io.moquette.server.config.MemoryConfig;
@@ -48,9 +47,9 @@ public class MapDBPersistentStoreTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
IntegrationUtils.cleanPersistenceFile(Constants.DEFAULT_PERSISTENT_PATH); IntegrationUtils.cleanPersistenceFile(BrokerConstants.DEFAULT_PERSISTENT_PATH);
Properties props = new Properties(); 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); IConfig conf = new MemoryConfig(props);
m_storageService = new MapDBPersistentStore(conf); m_storageService = new MapDBPersistentStore(conf);
m_storageService.initStore(); m_storageService.initStore();
@@ -64,7 +63,7 @@ public class MapDBPersistentStoreTest {
m_storageService.close(); m_storageService.close();
} }
IntegrationUtils.cleanPersistenceFile(Constants.DEFAULT_PERSISTENT_PATH); IntegrationUtils.cleanPersistenceFile(BrokerConstants.DEFAULT_PERSISTENT_PATH);
} }
@Test @Test
@@ -15,7 +15,7 @@
*/ */
package io.moquette.testclient; package io.moquette.testclient;
import io.moquette.commons.Constants; import io.moquette.BrokerConstants;
import io.moquette.parser.netty.MQTTDecoder; import io.moquette.parser.netty.MQTTDecoder;
import io.moquette.parser.netty.MQTTEncoder; import io.moquette.parser.netty.MQTTEncoder;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
@@ -50,7 +50,7 @@ public class Client {
private boolean m_connectionLost = false; private boolean m_connectionLost = false;
public Client(String host) { public Client(String host) {
this(host, Constants.PORT); this(host, BrokerConstants.PORT);
} }
public Client(String host, int port) { public Client(String host, int port) {
@@ -21,26 +21,6 @@ import java.io.File;
* Contains some useful constants. * Contains some useful constants.
*/ */
public class 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 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";
} }