Skip to content

Commit

Permalink
Merge pull request #6 from jembi/last-minute-conf-hacks
Browse files Browse the repository at this point in the history
Added support for specifying conf via a parameter
  • Loading branch information
hnnesv committed Feb 13, 2015
2 parents 7e88c7e + a349c6e commit 237b7bd
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/main/java/org/openhim/mediator/XDSMediatorMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import akka.actor.ActorSystem;
import akka.event.Logging;
import akka.event.LoggingAdapter;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.openhim.mediator.denormalization.ATNAAuditingActor;
import org.openhim.mediator.denormalization.EnrichRegistryStoredQueryActor;
import org.openhim.mediator.engine.*;
Expand All @@ -19,8 +21,10 @@
import org.openhim.mediator.orchestration.RegistryActor;
import org.openhim.mediator.orchestration.RepositoryActor;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class XDSMediatorMain {

Expand All @@ -39,10 +43,20 @@ private static StartupActorsConfig buildStartupActorsConfig() {
return startupActors;
}

private static MediatorConfig loadConfig() throws IOException, RoutingTable.RouteAlreadyMappedException {
private static MediatorConfig loadConfig(String configPath) throws IOException, RoutingTable.RouteAlreadyMappedException {
MediatorConfig config = new MediatorConfig();

config.setProperties("mediator.properties");
if (configPath!=null) {
Properties props = new Properties();
File conf = new File(configPath);
InputStream in = FileUtils.openInputStream(conf);
props.load(in);
IOUtils.closeQuietly(in);

config.setProperties(props);
} else {
config.setProperties("mediator.properties");
}

config.setName(config.getProperty("mediator.name"));
config.setServerHost(config.getProperty("mediator.host"));
Expand Down Expand Up @@ -89,7 +103,19 @@ public static void main(String... args) throws Exception {

//setup server
log.info("Initializing mediator server...");
MediatorConfig config = loadConfig();

String configPath = null;
//for now only --conf param is supported... poorly
//TODO support custom config for mediator registration info json
//TODO better parameter handling
if (args.length==2 && args[0].equals("--conf")) {
configPath = args[1];
log.info("Loading mediator configuration from '" + configPath + "'...");
} else {
log.info("No configuration specified. Using default properties...");
}

MediatorConfig config = loadConfig(configPath);
final MediatorServer server = new MediatorServer(system, config);

if (isSecure(config)) {
Expand Down

0 comments on commit 237b7bd

Please sign in to comment.