Fixed issue where external pages are not set

This commit is contained in:
Ziver Koc 2021-08-29 14:16:42 +02:00
parent 378d00b83e
commit 2d1e6f8f50
3 changed files with 14 additions and 9 deletions

View file

@ -67,6 +67,9 @@ public class HalServer {
logger.info("Working directory: " + FileUtil.find(".").getAbsolutePath()); logger.info("Working directory: " + FileUtil.find(".").getAbsolutePath());
httpExternal = new HalExternalWebDaemon();
registerDaemon(httpExternal);
// ------------------------------------ // ------------------------------------
// Initialize Plugins // Initialize Plugins
// ------------------------------------ // ------------------------------------
@ -107,9 +110,6 @@ public class HalServer {
for (Iterator<HalDaemon> it = pluginManager.getSingletonIterator(HalDaemon.class); it.hasNext(); ) { for (Iterator<HalDaemon> it = pluginManager.getSingletonIterator(HalDaemon.class); it.hasNext(); ) {
HalDaemon daemon = it.next(); HalDaemon daemon = it.next();
registerDaemon(daemon); registerDaemon(daemon);
if (daemon instanceof HalExternalWebDaemon) // Keep a reference of the external web server
httpExternal = (HalExternalWebDaemon) daemon;
} }
// ------------------------------------ // ------------------------------------
@ -198,7 +198,7 @@ public class HalServer {
/** /**
* Registers the given page with the external Hal web server. * Registers the given page with the external Hal web server.
* Note: as this page will most likely be accessible trough the internet it needs to be robust and secure. * Note: as this page will most likely be accessible through the internet it needs to be robust and secure.
* *
* @param url is the web path to the page. * @param url is the web path to the page.
* @param page is the page to register with the server. * @param page is the page to register with the server.
@ -210,7 +210,7 @@ public class HalServer {
/** /**
* Registers the given page with the external Hal web server. * Registers the given page with the external Hal web server.
* Note: as this page will most likely be accessible trough the internet it needs to be robust and secure. * Note: as this page will most likely be accessible through the internet it needs to be robust and secure.
* *
* @param page is the page to register with the server. * @param page is the page to register with the server.
*/ */

View file

@ -14,6 +14,7 @@ import zutil.net.http.HttpServer;
import java.io.IOException; import java.io.IOException;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.util.HashMap;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -24,10 +25,12 @@ import static se.hal.HalContext.CONFIG_HTTP_EXTERNAL_PORT;
public class HalExternalWebDaemon implements HalDaemon { public class HalExternalWebDaemon implements HalDaemon {
private static final Logger logger = LogUtil.getLogger(); private static final Logger logger = LogUtil.getLogger();
private HalAcmeDataStore acmeDataStore = new HalAcmeDataStore();
private HttpServer httpExternal; private HttpServer httpExternal;
private String externalServerUrl; private String externalServerUrl;
private HalAcmeDataStore acmeDataStore = new HalAcmeDataStore();
private X509Certificate certificate; private X509Certificate certificate;
private HashMap<String, HttpPage> pageMap = new HashMap<>();
@Override @Override
public void initiate(ScheduledExecutorService executor) { public void initiate(ScheduledExecutorService executor) {
@ -83,6 +86,10 @@ public class HalExternalWebDaemon implements HalDaemon {
private void startHttpServer() throws GeneralSecurityException, IOException { private void startHttpServer() throws GeneralSecurityException, IOException {
httpExternal = new HttpServer(HalContext.getIntegerProperty(CONFIG_HTTP_EXTERNAL_PORT), acmeDataStore.getDomainKeyPair().getPrivate(), certificate); httpExternal = new HttpServer(HalContext.getIntegerProperty(CONFIG_HTTP_EXTERNAL_PORT), acmeDataStore.getDomainKeyPair().getPrivate(), certificate);
for (String url : pageMap.keySet()) {
httpExternal.setPage(url, pageMap.get(url));
}
httpExternal.start(); httpExternal.start();
logger.info("External https server up and running at: " + externalServerUrl); logger.info("External https server up and running at: " + externalServerUrl);
@ -90,7 +97,6 @@ public class HalExternalWebDaemon implements HalDaemon {
public void setPage(String url, HttpPage page) { public void setPage(String url, HttpPage page) {
if (httpExternal != null) pageMap.put(url, page);
httpExternal.setPage(url, page);
} }
} }

View file

@ -8,7 +8,6 @@
{"se.hal.intf.HalAbstractControllerManager": "se.hal.EventControllerManager"}, {"se.hal.intf.HalAbstractControllerManager": "se.hal.EventControllerManager"},
{"se.hal.intf.HalAbstractControllerManager": "se.hal.SensorControllerManager"}, {"se.hal.intf.HalAbstractControllerManager": "se.hal.SensorControllerManager"},
{"se.hal.intf.HalDaemon": "se.hal.daemon.HalExternalWebDaemon"},
{"se.hal.intf.HalDaemon": "se.hal.daemon.HalMulticastDnsDaemon"}, {"se.hal.intf.HalDaemon": "se.hal.daemon.HalMulticastDnsDaemon"},
{"se.hal.intf.HalDaemon": "se.hal.daemon.SensorDataAggregatorDaemon"}, {"se.hal.intf.HalDaemon": "se.hal.daemon.SensorDataAggregatorDaemon"},
{"se.hal.intf.HalDaemon": "se.hal.daemon.SensorDataCleanupDaemon"}, {"se.hal.intf.HalDaemon": "se.hal.daemon.SensorDataCleanupDaemon"},