Skip to content
Snippets Groups Projects
Commit 7a7a401d authored by ribeaudc's avatar ribeaudc
Browse files

change: - Improve log output by writing out the property values during startup.

SVN: 8120
parent d585d235
No related branches found
No related tags found
No related merge requests found
......@@ -18,83 +18,90 @@ package ch.systemsx.cisd.openbis.datasetdownload;
import java.util.Properties;
import org.apache.log4j.Logger;
import ch.systemsx.cisd.common.exceptions.ConfigurationFailureException;
import ch.systemsx.cisd.common.logging.LogCategory;
import ch.systemsx.cisd.common.logging.LogFactory;
import ch.systemsx.cisd.common.utilities.PropertyUtils;
/**
* Configuration parameters for the Data Set Download Server.
*
*
* @author Franz-Josef Elmer
*/
class ConfigParameters
final class ConfigParameters
{
private static final Logger operationLog =
LogFactory.getLogger(LogCategory.OPERATION, ConfigParameters.class);
static final String SERVER_URL_KEY = "server-url";
static final String PORT_KEY = "port";
static final String STOREROOT_DIR_KEY = "storeroot-dir";
static final String SESSION_TIMEOUT_KEY = "session-timeout";
private static final String KEYSTORE = "keystore.";
static final String KEYSTORE_PATH_KEY = KEYSTORE + "path";
static final String KEYSTORE_PASSWORD_KEY = KEYSTORE + "password";
static final String KEYSTORE_KEY_PASSWORD_KEY = KEYSTORE + "key-password";
private final String storePath;
private final int port;
private final String serverURL;
private final int sessionTimeout;
private final String keystorePath;
private final String keystorePassword;
private final String keystoreKeyPassword;
/**
* Creates an instance based on the specified properties.
*
* @throws ConfigurationFailureException if a property is missed or has an invalid value.
*/
public ConfigParameters(Properties properties)
public ConfigParameters(final Properties properties)
{
storePath = getProperty(properties, STOREROOT_DIR_KEY);
port = getIntegerProperty(properties, PORT_KEY);
serverURL = getProperty(properties, SERVER_URL_KEY);
sessionTimeout = getIntegerProperty(properties, SESSION_TIMEOUT_KEY) * 60;
keystorePath = getProperty(properties, KEYSTORE_PATH_KEY);
keystorePassword = getProperty(properties, KEYSTORE_PASSWORD_KEY);
keystoreKeyPassword = getProperty(properties, KEYSTORE_KEY_PASSWORD_KEY);
storePath = PropertyUtils.getMandatoryProperty(properties, STOREROOT_DIR_KEY);
port = getMandatoryIntegerProperty(properties, PORT_KEY);
serverURL = PropertyUtils.getMandatoryProperty(properties, SERVER_URL_KEY);
sessionTimeout = getMandatoryIntegerProperty(properties, SESSION_TIMEOUT_KEY) * 60;
keystorePath = PropertyUtils.getMandatoryProperty(properties, KEYSTORE_PATH_KEY);
keystorePassword = PropertyUtils.getMandatoryProperty(properties, KEYSTORE_PASSWORD_KEY);
keystoreKeyPassword =
PropertyUtils.getMandatoryProperty(properties, KEYSTORE_KEY_PASSWORD_KEY);
}
private int getIntegerProperty(Properties properties, String key)
private final static int getMandatoryIntegerProperty(final Properties properties,
final String key)
{
String property = getProperty(properties, key);
final String property = PropertyUtils.getMandatoryProperty(properties, key);
try
{
return Integer.parseInt(property);
} catch (NumberFormatException ex)
} catch (final NumberFormatException ex)
{
throw new ConfigurationFailureException("Configuration parameter '" + key
+ "' is not an integer number: " + property);
}
}
private String getProperty(Properties properties, String key)
{
String property = properties.getProperty(key);
if (property == null)
{
throw new ConfigurationFailureException("Configuration parameter '" + key
+ "' not specified.");
}
return property;
}
public final String getStorePath()
{
return storePath;
}
public final int getPort()
{
return port;
......@@ -124,6 +131,16 @@ class ConfigParameters
{
return keystoreKeyPassword;
}
public final void log()
{
if (operationLog.isInfoEnabled())
{
operationLog.info(String.format("Store root directory: '%s'.", storePath));
operationLog.info(String.format("Port number: %d.", port));
operationLog.info(String.format("URL of openBIS server: '%s'.", serverURL));
operationLog.info(String.format("Session timeout (minutes): %d.", sessionTimeout));
operationLog.info(String.format("Keystore path: '%s'.", keystorePath));
}
}
}
......@@ -39,58 +39,60 @@ import ch.systemsx.cisd.lims.base.ServiceRegistry;
/**
* Main class of the service. Starts up jetty with {@link DatasetDownloadServlet}.
*
*
* @author Franz-Josef Elmer
*/
public class DatasetDownloadService
{
static final String APPLICATION_CONTEXT_KEY = "application-context";
private static final String PREFIX = "data-set-download.";
private static final int PREFIX_LENGTH = PREFIX.length();
private static final String SERVICE_PROPERTIES_FILE = "etc/service.properties";
private static final Logger operationLog =
LogFactory.getLogger(LogCategory.OPERATION, DatasetDownloadService.class);
public static void main(String[] args) throws Exception
public static void main(final String[] args) throws Exception
{
LogInitializer.init();
ServiceRegistry.setLIMSServiceFactory(RMIBasedLIMSServiceFactory.INSTANCE);
ApplicationContext applicationContext = createApplicationContext();
ConfigParameters configParameters = applicationContext.getConfigParameters();
int port = configParameters.getPort();
Server server = new Server();
SslSocketConnector socketConnector = new SslSocketConnector();
final ApplicationContext applicationContext = createApplicationContext();
final ConfigParameters configParameters = applicationContext.getConfigParameters();
final int port = configParameters.getPort();
final Server server = new Server();
final SslSocketConnector socketConnector = new SslSocketConnector();
socketConnector.setPort(port);
socketConnector.setMaxIdleTime(30000);
socketConnector.setKeystore(configParameters.getKeystorePath());
socketConnector.setPassword(configParameters.getKeystorePassword());
socketConnector.setKeyPassword(configParameters.getKeystoreKeyPassword());
server.addConnector(socketConnector);
Context context = new Context(server, "/", Context.SESSIONS);
final Context context = new Context(server, "/", Context.SESSIONS);
context.setAttribute(APPLICATION_CONTEXT_KEY, applicationContext);
context.addServlet(DatasetDownloadServlet.class, "/"
+ applicationContext.getApplicationName() + "/*");
server.start();
selfTest(applicationContext);
if (operationLog.isInfoEnabled())
{
operationLog.info("Data set download server ready on port " + port);
}
}
private static void selfTest(ApplicationContext applicationContext)
private static void selfTest(final ApplicationContext applicationContext)
{
int version = applicationContext.getDataSetService().getVersion();
final int version = applicationContext.getDataSetService().getVersion();
if (IWebService.VERSION != version)
{
throw new ConfigurationFailureException(
"This client has the wrong service version for the server (client: "
+ IWebService.VERSION + ", server: " + version + ").");
}
}
if (operationLog.isInfoEnabled())
{
operationLog.info("openBIS service (interface version " + version + ") is reachable");
......@@ -99,33 +101,35 @@ public class DatasetDownloadService
private static ApplicationContext createApplicationContext()
{
ConfigParameters configParameters = getConfigParameters();
IDataSetService dataSetService = new DataSetService(configParameters);
ApplicationContext applicationContext =
final ConfigParameters configParameters = getConfigParameters();
final IDataSetService dataSetService = new DataSetService(configParameters);
final ApplicationContext applicationContext =
new ApplicationContext(dataSetService, configParameters, "dataset-download");
return applicationContext;
}
private static ConfigParameters getConfigParameters()
{
Properties properties = loadProperties();
Properties systemProperties = System.getProperties();
Enumeration<?> propertyNames = systemProperties.propertyNames();
final Properties properties = loadProperties();
final Properties systemProperties = System.getProperties();
final Enumeration<?> propertyNames = systemProperties.propertyNames();
while (propertyNames.hasMoreElements())
{
String name = (String) propertyNames.nextElement();
final String name = (String) propertyNames.nextElement();
if (name.startsWith(PREFIX))
{
String value = systemProperties.getProperty(name);
final String value = systemProperties.getProperty(name);
properties.setProperty(name.substring(PREFIX_LENGTH), value);
}
}
return new ConfigParameters(properties);
final ConfigParameters configParameters = new ConfigParameters(properties);
configParameters.log();
return configParameters;
}
private static Properties loadProperties()
{
final Properties properties = new Properties();
try
{
......@@ -139,7 +143,7 @@ public class DatasetDownloadService
{
IOUtils.closeQuietly(is);
}
} catch (Exception ex)
} catch (final Exception ex)
{
final String msg =
"Could not load the service properties from resource '"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment