Removed WebSocket port from default configuration, end moved defaults config from ConfigParser to Config container. Fixes isse #150
This commit is contained in:
@@ -29,7 +29,7 @@ import java.util.Properties;
|
|||||||
*
|
*
|
||||||
* @author andrea
|
* @author andrea
|
||||||
*/
|
*/
|
||||||
public class ClasspathConfig implements IConfig {
|
public class ClasspathConfig extends IConfig {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ClasspathConfig.class);
|
private static final Logger LOG = LoggerFactory.getLogger(ClasspathConfig.class);
|
||||||
|
|
||||||
@@ -43,6 +43,7 @@ public class ClasspathConfig implements IConfig {
|
|||||||
}
|
}
|
||||||
Reader configReader = new InputStreamReader(is);
|
Reader configReader = new InputStreamReader(is);
|
||||||
ConfigurationParser confParser = new ConfigurationParser();
|
ConfigurationParser confParser = new ConfigurationParser();
|
||||||
|
assignDefaults();
|
||||||
try {
|
try {
|
||||||
confParser.parse(configReader);
|
confParser.parse(configReader);
|
||||||
} catch (ParseException pex) {
|
} catch (ParseException pex) {
|
||||||
|
|||||||
@@ -37,21 +37,9 @@ class ConfigurationParser {
|
|||||||
|
|
||||||
private Properties m_properties = new Properties();
|
private Properties m_properties = new Properties();
|
||||||
|
|
||||||
ConfigurationParser() {
|
// ConfigurationParser() {
|
||||||
createDefaults();
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
private void createDefaults() {
|
|
||||||
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, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the configuration from file.
|
* Parse the configuration from file.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -27,13 +27,14 @@ import java.util.Properties;
|
|||||||
*
|
*
|
||||||
* @author andrea
|
* @author andrea
|
||||||
*/
|
*/
|
||||||
public class FilesystemConfig implements IConfig {
|
public class FilesystemConfig extends IConfig {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(FilesystemConfig.class);
|
private static final Logger LOG = LoggerFactory.getLogger(FilesystemConfig.class);
|
||||||
|
|
||||||
private final Properties m_properties;
|
private Properties m_properties = new Properties();
|
||||||
|
|
||||||
public FilesystemConfig(File file) {
|
public FilesystemConfig(File file) {
|
||||||
ConfigurationParser confParser = new ConfigurationParser();
|
ConfigurationParser confParser = new ConfigurationParser();
|
||||||
|
assignDefaults();
|
||||||
try {
|
try {
|
||||||
confParser.parse(file);
|
confParser.parse(file);
|
||||||
} catch (ParseException pex) {
|
} catch (ParseException pex) {
|
||||||
|
|||||||
@@ -15,15 +15,28 @@
|
|||||||
*/
|
*/
|
||||||
package io.moquette.server.config;
|
package io.moquette.server.config;
|
||||||
|
|
||||||
|
import io.moquette.BrokerConstants;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base interface for all configuration implementations (filesystem, memory or classpath)
|
* Base interface for all configuration implementations (filesystem, memory or classpath)
|
||||||
*
|
*
|
||||||
* @author andrea
|
* @author andrea
|
||||||
*/
|
*/
|
||||||
public interface IConfig {
|
public abstract class IConfig {
|
||||||
void setProperty(String name, String value);
|
public abstract void setProperty(String name, String value);
|
||||||
|
|
||||||
String getProperty(String name);
|
public abstract String getProperty(String name);
|
||||||
|
|
||||||
String getProperty(String name, String defaultValue);
|
public abstract String getProperty(String name, String defaultValue);
|
||||||
|
|
||||||
|
void assignDefaults() {
|
||||||
|
setProperty(BrokerConstants.PORT_PROPERTY_NAME, Integer.toString(BrokerConstants.PORT));
|
||||||
|
setProperty(BrokerConstants.HOST_PROPERTY_NAME, BrokerConstants.HOST);
|
||||||
|
//setProperty(BrokerConstants.WEB_SOCKET_PORT_PROPERTY_NAME, Integer.toString(BrokerConstants.WEBSOCKET_PORT));
|
||||||
|
setProperty(BrokerConstants.PASSWORD_FILE_PROPERTY_NAME, "");
|
||||||
|
setProperty(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, BrokerConstants.DEFAULT_PERSISTENT_PATH);
|
||||||
|
setProperty(BrokerConstants.ALLOW_ANONYMOUS_PROPERTY_NAME, Boolean.TRUE.toString());
|
||||||
|
setProperty(BrokerConstants.AUTHENTICATOR_CLASS_NAME, "");
|
||||||
|
setProperty(BrokerConstants.AUTHORIZATOR_CLASS_NAME, "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,27 +25,27 @@ import java.util.Properties;
|
|||||||
*
|
*
|
||||||
* @author andrea
|
* @author andrea
|
||||||
*/
|
*/
|
||||||
public class MemoryConfig implements IConfig {
|
public class MemoryConfig extends IConfig {
|
||||||
|
|
||||||
private final Properties m_properties = new Properties();
|
private final Properties m_properties = new Properties();
|
||||||
|
|
||||||
public MemoryConfig(Properties properties) {
|
public MemoryConfig(Properties properties) {
|
||||||
createDefaults();
|
assignDefaults();
|
||||||
for (Map.Entry<Object, Object> entrySet : properties.entrySet()) {
|
for (Map.Entry<Object, Object> entrySet : properties.entrySet()) {
|
||||||
m_properties.put(entrySet.getKey(), entrySet.getValue());
|
m_properties.put(entrySet.getKey(), entrySet.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createDefaults() {
|
// private void createDefaults() {
|
||||||
m_properties.put(BrokerConstants.PORT_PROPERTY_NAME, Integer.toString(BrokerConstants.PORT));
|
// m_properties.put(BrokerConstants.PORT_PROPERTY_NAME, Integer.toString(BrokerConstants.PORT));
|
||||||
m_properties.put(BrokerConstants.HOST_PROPERTY_NAME, BrokerConstants.HOST);
|
// 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.WEB_SOCKET_PORT_PROPERTY_NAME, Integer.toString(BrokerConstants.WEBSOCKET_PORT));
|
||||||
m_properties.put(BrokerConstants.PASSWORD_FILE_PROPERTY_NAME, "");
|
// m_properties.put(BrokerConstants.PASSWORD_FILE_PROPERTY_NAME, "");
|
||||||
m_properties.put(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, BrokerConstants.DEFAULT_PERSISTENT_PATH);
|
// 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.ALLOW_ANONYMOUS_PROPERTY_NAME, true);
|
||||||
m_properties.put(BrokerConstants.AUTHENTICATOR_CLASS_NAME, "");
|
// m_properties.put(BrokerConstants.AUTHENTICATOR_CLASS_NAME, "");
|
||||||
m_properties.put(BrokerConstants.AUTHORIZATOR_CLASS_NAME, "");
|
// m_properties.put(BrokerConstants.AUTHORIZATOR_CLASS_NAME, "");
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setProperty(String name, String value) {
|
public void setProperty(String name, String value) {
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ public class ServerIntegrationWebSocketTest {
|
|||||||
protected void startServer() throws IOException {
|
protected void startServer() throws IOException {
|
||||||
m_server = new Server();
|
m_server = new Server();
|
||||||
final Properties configProps = IntegrationUtils.prepareTestPropeties();
|
final Properties configProps = IntegrationUtils.prepareTestPropeties();
|
||||||
|
configProps.put(BrokerConstants.WEB_SOCKET_PORT_PROPERTY_NAME, Integer.toString(BrokerConstants.WEBSOCKET_PORT));
|
||||||
m_config = new MemoryConfig(configProps);
|
m_config = new MemoryConfig(configProps);
|
||||||
m_server.startServer(m_config);
|
m_server.startServer(m_config);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
package io.moquette.server.config;
|
package io.moquette.server.config;
|
||||||
|
|
||||||
import io.moquette.BrokerConstants;
|
import io.moquette.BrokerConstants;
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@@ -26,6 +25,8 @@ import java.text.ParseException;
|
|||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -44,7 +45,8 @@ public class ConfigurationParserTest {
|
|||||||
public void checkDefaultOptions() {
|
public void checkDefaultOptions() {
|
||||||
Properties props = m_parser.getProperties();
|
Properties props = m_parser.getProperties();
|
||||||
|
|
||||||
verifyDefaults(props);
|
//verifyDefaults(props);
|
||||||
|
assertTrue(props.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -53,7 +55,8 @@ public class ConfigurationParserTest {
|
|||||||
m_parser.parse(conf);
|
m_parser.parse(conf);
|
||||||
|
|
||||||
//Verify
|
//Verify
|
||||||
verifyDefaults(m_parser.getProperties());
|
// verifyDefaults(m_parser.getProperties());
|
||||||
|
assertTrue(m_parser.getProperties().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -62,7 +65,8 @@ public class ConfigurationParserTest {
|
|||||||
m_parser.parse(conf);
|
m_parser.parse(conf);
|
||||||
|
|
||||||
//Verify
|
//Verify
|
||||||
verifyDefaults(m_parser.getProperties());
|
// verifyDefaults(m_parser.getProperties());
|
||||||
|
assertTrue(m_parser.getProperties().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = ParseException.class)
|
@Test(expected = ParseException.class)
|
||||||
@@ -101,7 +105,8 @@ 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(BrokerConstants.PORT, Integer.parseInt(props.getProperty("port")));
|
assertEquals(BrokerConstants.PORT, Integer.parseInt(props.getProperty(BrokerConstants.PORT_PROPERTY_NAME)));
|
||||||
Assert.assertEquals(BrokerConstants.HOST, props.getProperty("host"));
|
assertEquals(BrokerConstants.HOST, props.getProperty(BrokerConstants.HOST_PROPERTY_NAME));
|
||||||
|
assertNull(props.getProperty(BrokerConstants.WEB_SOCKET_PORT_PROPERTY_NAME));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user