X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Finternal%2Fruntime%2FCmsDeploymentImpl.java;h=497ed923fa5f9ee2ae9bd46890f27ce39eae7754;hb=bfb5eb067a6796c0ee2a575b1e2431220352513a;hp=44a2866f8df50613cbeede05262e66c660272428;hpb=c615307d7b87bcb260d8a9f402c6e0a880862f38;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/internal/runtime/CmsDeploymentImpl.java b/org.argeo.cms/src/org/argeo/cms/internal/runtime/CmsDeploymentImpl.java index 44a2866f8..497ed923f 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/runtime/CmsDeploymentImpl.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/runtime/CmsDeploymentImpl.java @@ -1,76 +1,122 @@ package org.argeo.cms.internal.runtime; -import java.io.IOException; -import java.net.URL; -import java.util.Dictionary; +import static org.argeo.api.cms.CmsConstants.CONTEXT_PATH; +import java.util.Map; +import java.util.TreeMap; + +import org.argeo.api.cms.CmsConstants; import org.argeo.api.cms.CmsDeployment; import org.argeo.api.cms.CmsLog; import org.argeo.api.cms.CmsState; -import org.argeo.cms.internal.osgi.DeployConfig; -import org.osgi.service.http.HttpService; +import org.argeo.cms.CmsDeployProperty; + +import com.sun.net.httpserver.HttpHandler; +import com.sun.net.httpserver.HttpServer; /** Implementation of a CMS deployment. */ public class CmsDeploymentImpl implements CmsDeployment { private final CmsLog log = CmsLog.getLog(getClass()); // Readiness - private boolean httpExpected = false; - private HttpService httpService; +// private HttpService httpService; private CmsState cmsState; - private DeployConfig deployConfig; +// private DeployConfig deployConfig; + + private boolean httpExpected = false; + private HttpServer httpServer; + private Map httpHandlers = new TreeMap<>(); public void start() { - httpExpected = deployConfig.getProps(KernelConstants.JETTY_FACTORY_PID, "default") != null; - if (deployConfig.hasDomain()) { - loadIpaJaasConfiguration(); - } - } +// httpExpected = deployConfig.getProps(KernelConstants.JETTY_FACTORY_PID, "default") != null; +// if (deployConfig.hasDomain()) { +// loadIpaJaasConfiguration(); +// } - public void addFactoryDeployConfig(String factoryPid, Dictionary props) { - deployConfig.putFactoryDeployConfig(factoryPid, props); - deployConfig.save(); - try { - deployConfig.loadConfigs(); - } catch (IOException e) { - throw new IllegalStateException(e); - } + log.debug(() -> "CMS deployment available"); } - public Dictionary getProps(String factoryPid, String cn) { - return deployConfig.getProps(factoryPid, cn); - } +// public void addFactoryDeployConfig(String factoryPid, Dictionary props) { +// deployConfig.putFactoryDeployConfig(factoryPid, props); +// deployConfig.save(); +// try { +// deployConfig.loadConfigs(); +// } catch (IOException e) { +// throw new IllegalStateException(e); +// } +// } +// +// public Dictionary getProps(String factoryPid, String cn) { +// return deployConfig.getProps(factoryPid, cn); +// } - public boolean isHttpAvailableOrNotExpected() { - return (httpExpected ? httpService != null : true); - } +// public boolean isHttpAvailableOrNotExpected() { +// return (httpExpected ? httpService != null : true); +// } - private void loadIpaJaasConfiguration() { - if (System.getProperty(KernelConstants.JAAS_CONFIG_PROP) == null) { - String jaasConfig = KernelConstants.JAAS_CONFIG_IPA; - URL url = getClass().getClassLoader().getResource(jaasConfig); - KernelUtils.setJaasConfiguration(url); - log.debug("Set IPA JAAS configuration."); - } - } +// private void loadIpaJaasConfiguration() { +// if (System.getProperty(KernelConstants.JAAS_CONFIG_PROP) == null) { +// String jaasConfig = KernelConstants.JAAS_CONFIG_IPA; +// URL url = getClass().getClassLoader().getResource(jaasConfig); +// KernelUtils.setJaasConfiguration(url); +// log.debug("Set IPA JAAS configuration."); +// } +// } public void stop() { - if (deployConfig != null) { - deployConfig.save(); - } +// if (deployConfig != null) { +// deployConfig.save(); +// } } - public void setDeployConfig(DeployConfig deployConfig) { - this.deployConfig = deployConfig; - } +// public void setDeployConfig(DeployConfig deployConfig) { +// this.deployConfig = deployConfig; +// } public void setCmsState(CmsState cmsState) { this.cmsState = cmsState; + String httpPort = this.cmsState.getDeployProperty(CmsDeployProperty.HTTP_PORT.getProperty()); + String httpsPort = this.cmsState.getDeployProperty(CmsDeployProperty.HTTPS_PORT.getProperty()); + httpExpected = httpPort != null || httpsPort != null; + } + + public void setHttpServer(HttpServer httpServer) { + this.httpServer = httpServer; + // create contexts whose handles had already been published + for (String contextPath : httpHandlers.keySet()) { + HttpHandler httpHandler = httpHandlers.get(contextPath); + httpServer.createContext(contextPath, httpHandler); + log.debug(() -> "Added handler " + contextPath + " : " + httpHandler.getClass().getName()); + } + } + + public void addHttpHandler(HttpHandler httpHandler, Map properties) { + final String contextPath = properties.get(CONTEXT_PATH); + if (contextPath == null) { + log.warn("Property " + CONTEXT_PATH + " not set on HTTP handler " + properties + ". Ignoring it."); + return; + } + httpHandlers.put(contextPath, httpHandler); + if (httpServer == null) + return; + httpServer.createContext(contextPath, httpHandler); + log.debug(() -> "Added handler " + contextPath + " : " + httpHandler.getClass().getName()); + } - public void setHttpService(HttpService httpService) { - this.httpService = httpService; + public void removeHttpHandler(HttpHandler httpHandler, Map properties) { + final String contextPath = properties.get(CmsConstants.CONTEXT_PATH); + if (contextPath == null) + return; // ignore silently + httpHandlers.remove(contextPath); + if (httpServer == null) + return; + httpServer.removeContext(contextPath); + log.debug(() -> "Removed handler " + contextPath + " : " + httpHandler.getClass().getName()); } +// public void setHttpService(HttpService httpService) { +// this.httpService = httpService; +// } }