Skip to content

Commit

Permalink
Merge branch 'develop' into feat/#309-read-config-from-arbitrary-dire…
Browse files Browse the repository at this point in the history
…ctories
  • Loading branch information
NicholasAzar committed Feb 13, 2019
2 parents 878fb94 + 405896e commit f2a4f54
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public void registerService(ConsulService service, String token) {
}
} catch (Exception e) {
logger.error("Exception:", e);
throw new RuntimeException(e.getMessage());
}
}

Expand Down
65 changes: 36 additions & 29 deletions server/src/main/java/com/networknt/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,18 @@ static private boolean bind(HttpHandler handler, int port) {

server.start();
System.out.println("HOST IP " + System.getenv(STATUS_HOST_IP));
// application level service registry. only be used without docker container.
if (config.enableRegistry) {
// assuming that registry is defined in service.json, otherwise won't start
// server.
} catch (Exception e) {
System.out.println("Failed to bind to port " + port);
e.printStackTrace(System.out);
if (logger.isInfoEnabled())
logger.info("Failed to bind to port " + port);
throw new RuntimeException(e.getMessage());
}
// application level service registry. only be used without docker container.
if (config.enableRegistry) {
// assuming that registry is defined in service.json, otherwise won't start
// server.
try {
registry = SingletonServiceFactory.getBean(Registry.class);
if (registry == null)
throw new RuntimeException("Could not find registry instance in service map");
Expand All @@ -261,36 +269,35 @@ static private boolean bind(HttpHandler handler, int port) {
SwitcherUtil.setSwitcherValue(Constants.REGISTRY_HEARTBEAT_SWITCHER, true);
if (logger.isInfoEnabled())
logger.info("Registry heart beat switcher is on");

}

if (config.enableHttp) {
System.out.println("Http Server started on ip:" + config.getIp() + " Port:" + port);
if (logger.isInfoEnabled())
logger.info("Http Server started on ip:" + config.getIp() + " Port:" + port);
} else {
System.out.println("Http port disabled.");
if (logger.isInfoEnabled())
logger.info("Http port disabled.");
}
if (config.enableHttps) {
System.out.println("Https Server started on ip:" + config.getIp() + " Port:" + port);
if (logger.isInfoEnabled())
logger.info("Https Server started on ip:" + config.getIp() + " Port:" + port);
} else {
System.out.println("Https port disabled.");
// handle the registration exception separately to eliminate confusion
} catch (Exception e) {
System.out.println("Failed to register service, the server stopped.");
if (logger.isInfoEnabled())
logger.info("Https port disabled.");
logger.info("Failed to register service, the server stopped.");
throw new RuntimeException(e.getMessage());
}
}

return true;
} catch (Exception e) {
System.out.println("Failed to bind to port " + port);
e.printStackTrace(System.out);
if (config.enableHttp) {
System.out.println("Http Server started on ip:" + config.getIp() + " Port:" + port);
if (logger.isInfoEnabled())
logger.info("Failed to bind to port " + port, e);
return false;
logger.info("Http Server started on ip:" + config.getIp() + " Port:" + port);
} else {
System.out.println("Http port disabled.");
if (logger.isInfoEnabled())
logger.info("Http port disabled.");
}
if (config.enableHttps) {
System.out.println("Https Server started on ip:" + config.getIp() + " Port:" + port);
if (logger.isInfoEnabled())
logger.info("Https Server started on ip:" + config.getIp() + " Port:" + port);
} else {
System.out.println("Https port disabled.");
if (logger.isInfoEnabled())
logger.info("Https port disabled.");
}

return true;
}

static public void stop() {
Expand Down

0 comments on commit f2a4f54

Please sign in to comment.