Skip to content

Commit

Permalink
- SSL options added
Browse files Browse the repository at this point in the history
  • Loading branch information
Areeb-Gillani committed Aug 18, 2024
1 parent f54c732 commit c5648cc
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions src/main/java/io/github/areebgillani/boost/BoostApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Launcher;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpServer;
import io.vertx.core.impl.logging.Logger;
import io.vertx.core.impl.logging.LoggerFactory;
import io.vertx.core.json.JsonObject;
import io.vertx.core.net.SSLOptions;
import io.vertx.ext.web.Router;

import java.util.LinkedHashSet;
Expand All @@ -21,7 +23,8 @@ public class BoostApplication extends AbstractVerticle {
private JsonObject config;
private Router router;
protected static BoostApplication instance;
public static BoostApplication getInstance(){

public static BoostApplication getInstance() {
return instance;
}

Expand All @@ -39,12 +42,14 @@ public void init(Vertx vertx, Router router, String configPath) throws Interrupt
loadConfig(configPath);
deploy();
}

public void init(Vertx vertx, Router router, JsonObject config) {
this.vertx = vertx;
this.router = router;
this.config = config;
deploy();
}

private void loadConfig(String folderPath) throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
ConfigRetriever.create(vertx, initRetrieverConfig(folderPath)).getConfig().onComplete(ar -> {
Expand All @@ -62,22 +67,24 @@ private void loadConfig(String folderPath) throws InterruptedException {

public void deployApplication(String folderPath) throws InterruptedException {
init(vertx, router, folderPath);
if(config.containsKey("server")
&& config.containsKey("http")
&& config.getJsonObject("server")
.getJsonObject("http").getBoolean("enable", true)) {
logger.info("Initializing Vertx Application Server...");
vertx.createHttpServer()
.requestHandler(router)
.listen(config
.getJsonObject("server")
.getJsonObject("http")
.getInteger("port", 8080))
.onSuccess(server -> logger.info(("Server started at port [" + server.actualPort() + "]. ")))
.onFailure(failed -> logger.info(failed.getMessage()));
if (config.containsKey("server")) {
JsonObject serverConfig = config.getJsonObject("server");
if (serverConfig.containsKey("http")) {
JsonObject httpConfig = serverConfig.getJsonObject("http");
if(httpConfig.getBoolean("enable", true)) {
logger.info("Initializing Vertx Application Server...");
HttpServer httpServer = vertx.createHttpServer().requestHandler(router);
if(httpConfig.containsKey("SSL"))
httpServer.updateSSLOptions(new SSLOptions(httpConfig.getJsonObject("SSL")));
httpServer.listen(httpConfig.getInteger("port", 8080))
.onSuccess(server -> logger.info(("Server started at port [" + server.actualPort() + "]. ")))
.onFailure(failed -> logger.info(failed.getMessage()));
}
}
}

}

public static void run(Class<? extends BoostApplication> clazz, String[] args) {
LinkedHashSet<String> params = new LinkedHashSet<>(List.of(new String[]{"run", clazz.getCanonicalName(), "--launcher-class=" + clazz.getCanonicalName()}));
params.addAll(List.of(args));
Expand All @@ -101,7 +108,7 @@ public ConfigRetrieverOptions initRetrieverConfig(String folderPath) {
.addStore(new ConfigStoreOptions()
.setType("file")
.setOptional(true)
.setConfig(new JsonObject().put("path", folderPath==null||folderPath.isEmpty()?"config.json":folderPath)))
.setConfig(new JsonObject().put("path", folderPath == null || folderPath.isEmpty() ? "config.json" : folderPath)))
.addStore(new ConfigStoreOptions().setType("sys"));
}

Expand Down

0 comments on commit c5648cc

Please sign in to comment.