Moving hard coded strings to constants

Adding more hard coded strings to the constants.  I am not really sure
why there are 2 constants java classes either.
This commit is contained in:
swarwick
2015-03-14 16:37:55 +01:00
committed by andrea
parent 6cc5b0edb9
commit d7f2493811
7 changed files with 25 additions and 26 deletions
@@ -57,10 +57,10 @@ class ConfigurationParser {
} }
private void createDefaults() { private void createDefaults() {
m_properties.put("port", Integer.toString(Constants.PORT)); m_properties.put(Constants.PORT_PROPERTY_NAME, Integer.toString(Constants.PORT));
m_properties.put("host", Constants.HOST); m_properties.put(Constants.HOST_PROPERTY_NAME, Constants.HOST);
m_properties.put("websocket_port", Integer.toString(Constants.WEBSOCKET_PORT)); m_properties.put(Constants.WEB_SOCKET_PORT_PROPERTY_NAME, Integer.toString(Constants.WEBSOCKET_PORT));
m_properties.put("password_file", ""); m_properties.put(Constants.PASSWORD_FILE_PROPERTY_NAME, "");
m_properties.put(Constants.PERSISTENT_STORE_PROPERTY_NAME, Constants.DEFAULT_PERSISTENT_PATH); m_properties.put(Constants.PERSISTENT_STORE_PROPERTY_NAME, Constants.DEFAULT_PERSISTENT_PATH);
} }
@@ -96,10 +96,10 @@ public class Server {
} }
public void stopServer() { public void stopServer() {
System.out.println("Server stopping..."); LOG.info("Server stopping...");
messaging.stop(); messaging.stop();
m_acceptor.close(); m_acceptor.close();
System.out.println("Server stopped"); LOG.info("Server stopped");
} }
public Properties getProperties() { public Properties getProperties() {
@@ -17,7 +17,6 @@ package org.eclipse.moquette.server.netty;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
@@ -135,8 +134,8 @@ public class NettyAcceptor implements ServerAcceptor {
private void initializePlainTCPTransport(IMessaging messaging, Properties props) throws IOException { private void initializePlainTCPTransport(IMessaging messaging, Properties props) throws IOException {
final NettyMQTTHandler handler = new NettyMQTTHandler(); final NettyMQTTHandler handler = new NettyMQTTHandler();
handler.setMessaging(messaging); handler.setMessaging(messaging);
String host = props.getProperty("host"); String host = props.getProperty(Constants.HOST_PROPERTY_NAME);
int port = Integer.parseInt(props.getProperty("port")); int port = Integer.parseInt(props.getProperty(Constants.PORT_PROPERTY_NAME));
initFactory(host, port, new PipelineInitializer() { initFactory(host, port, new PipelineInitializer() {
@Override @Override
void init(ChannelPipeline pipeline) { void init(ChannelPipeline pipeline) {
@@ -152,7 +151,7 @@ public class NettyAcceptor implements ServerAcceptor {
} }
private void initializeWebSocketTransport(IMessaging messaging, Properties props) throws IOException { private void initializeWebSocketTransport(IMessaging messaging, Properties props) throws IOException {
String webSocketPortProp = props.getProperty("websocket_port"); String webSocketPortProp = props.getProperty(Constants.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");
@@ -163,7 +162,7 @@ public class NettyAcceptor implements ServerAcceptor {
final NettyMQTTHandler handler = new NettyMQTTHandler(); final NettyMQTTHandler handler = new NettyMQTTHandler();
handler.setMessaging(messaging); handler.setMessaging(messaging);
String host = props.getProperty("host"); String host = props.getProperty(Constants.HOST_PROPERTY_NAME);
initFactory(host, port, new PipelineInitializer() { initFactory(host, port, new PipelineInitializer() {
@Override @Override
void init(ChannelPipeline pipeline) { void init(ChannelPipeline pipeline) {
@@ -186,13 +185,13 @@ public class NettyAcceptor implements ServerAcceptor {
private void initializeSSLTCPTransport(IMessaging messaging, Properties props) throws IOException { private void initializeSSLTCPTransport(IMessaging messaging, Properties props) throws IOException {
String sslPortProp = props.getProperty("ssl_port"); String sslPortProp = props.getProperty(Constants.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");
return; return;
} }
final String jksPath = props.getProperty("jks_path"); final String jksPath = props.getProperty(Constants.JKS_PATH_PROPERTY_NAME);
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
LOG.warn("You have configured the SSL port but not the jks_path, SSL not started"); LOG.warn("You have configured the SSL port but not the jks_path, SSL not started");
@@ -201,8 +200,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("key_store_password"); final String keyStorePassword = props.getProperty(Constants.KEY_STORE_PASSWORD_PROPERTY_NAME);
final String keyManagerPassword = props.getProperty("key_manager_password"); final String keyManagerPassword = props.getProperty(Constants.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");
@@ -215,7 +214,7 @@ public class NettyAcceptor implements ServerAcceptor {
} }
int sslPort = Integer.parseInt(sslPortProp); int sslPort = Integer.parseInt(sslPortProp);
String host = props.getProperty("host"); String host = props.getProperty(Constants.HOST_PROPERTY_NAME);
final NettyMQTTHandler handler = new NettyMQTTHandler(); final NettyMQTTHandler handler = new NettyMQTTHandler();
handler.setMessaging(messaging); handler.setMessaging(messaging);
@@ -19,8 +19,6 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.timeout.IdleStateHandler; import io.netty.handler.timeout.IdleStateHandler;
import io.netty.util.Attribute; import io.netty.util.Attribute;
import io.netty.util.AttributeKey; import io.netty.util.AttributeKey;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.moquette.server.Constants; import org.eclipse.moquette.server.Constants;
import org.eclipse.moquette.server.ServerChannel; import org.eclipse.moquette.server.ServerChannel;
@@ -25,7 +25,6 @@ import org.eclipse.moquette.proto.Utils;
import org.eclipse.moquette.proto.messages.AbstractMessage; import org.eclipse.moquette.proto.messages.AbstractMessage;
import static org.eclipse.moquette.proto.messages.AbstractMessage.*; import static org.eclipse.moquette.proto.messages.AbstractMessage.*;
import org.eclipse.moquette.proto.messages.PingRespMessage; import org.eclipse.moquette.proto.messages.PingRespMessage;
import org.eclipse.moquette.server.Constants;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -41,15 +41,10 @@ public class ServerRestartIntegrationTest {
MQTT m_mqtt; MQTT m_mqtt;
BlockingConnection m_subscriber; BlockingConnection m_subscriber;
BlockingConnection m_publisher; BlockingConnection m_publisher;
Properties properties;
private final static String PERSISTENT_STORE_PROPERTY_NAME = "persistent_store";
private final static String PERSISTENT_STORE_FILE_NAME = System.getProperty("user.home") + File.separator + "moquette_store.mapdb";
protected void startServer() throws IOException { protected void startServer() throws IOException {
properties = new Properties();
properties.put(PERSISTENT_STORE_PROPERTY_NAME, PERSISTENT_STORE_FILE_NAME);
m_server = new Server(); m_server = new Server();
m_server.startServer(properties); m_server.startServer(new Properties());
} }
@Before @Before
@@ -28,4 +28,12 @@ public class Constants {
public static final String DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME = "moquette_store.mapdb"; public static final String DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME = "moquette_store.mapdb";
public static final String DEFAULT_PERSISTENT_PATH = System.getProperty("user.home") + File.separator + DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME; public static final String DEFAULT_PERSISTENT_PATH = System.getProperty("user.home") + File.separator + DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME;
public static final String PERSISTENT_STORE_PROPERTY_NAME = "persistence_store"; public static final String PERSISTENT_STORE_PROPERTY_NAME = "persistence_store";
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 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";
} }