X-Git-Url: http://git.argeo.org/?p=lgpl%2Fargeo-commons.git;a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Finternal%2Fruntime%2FCmsDeploymentImpl.java;fp=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Finternal%2Fruntime%2FCmsDeploymentImpl.java;h=d3f4b575aa7ff6486f5708a7fbfa93728af4bb8c;hp=e1c420b8287469bb698af791d04b9d87638563d9;hb=b95462873703848193e56fcbe997693630db6121;hpb=55d88fba80cec198a0f11ba7545e19878c51fc5e 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 e1c420b82..d3f4b575a 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 @@ -63,12 +63,21 @@ public class CmsDeploymentImpl implements CmsDeployment { public void setHttpServer(HttpServer httpServer) { Objects.requireNonNull(httpServer); - this.httpServer.complete(httpServer); - // create contexts whose handles had already been published - for (String contextPath : httpHandlers.keySet()) { - HttpHandler httpHandler = httpHandlers.get(contextPath); - CmsAuthenticator authenticator = httpAuthenticators.get(contextPath); - createHttpContext(contextPath, httpHandler, authenticator); + if (this.httpServer.isDone()) + if (httpExpected) + throw new IllegalStateException("HTTP server is already set"); + else + return;// ignore + // create contexts whose handlers had already been published + synchronized (httpHandlers) { + synchronized (httpAuthenticators) { + this.httpServer.complete(httpServer); + for (String contextPath : httpHandlers.keySet()) { + HttpHandler httpHandler = httpHandlers.get(contextPath); + CmsAuthenticator authenticator = httpAuthenticators.get(contextPath); + createHttpContext(contextPath, httpHandler, authenticator); + } + } } } @@ -80,9 +89,13 @@ public class CmsDeploymentImpl implements CmsDeployment { } boolean isPublic = Boolean.parseBoolean(properties.get(CmsConstants.CONTEXT_PUBLIC)); CmsAuthenticator authenticator = isPublic ? new PublicCmsAuthenticator() : new CmsAuthenticator(); - httpHandlers.put(contextPath, httpHandler); - httpAuthenticators.put(contextPath, authenticator); - if (httpServer.join() == null) { + synchronized (httpHandlers) { + synchronized (httpAuthenticators) { + httpHandlers.put(contextPath, httpHandler); + httpAuthenticators.put(contextPath, authenticator); + } + } + if (!httpServer.isDone()) { return; } else { createHttpContext(contextPath, httpHandler, authenticator); @@ -95,6 +108,9 @@ public class CmsDeploymentImpl implements CmsDeployment { log.warn("Ignore HTTP context " + contextPath + " as we don't provide an HTTP server"); return; } + if (!this.httpServer.isDone()) + throw new IllegalStateException("HTTP server is not set"); + // TODO use resultNow when switching to Java 21 HttpContext httpContext = httpServer.join().createContext(contextPath); // we want to set the authenticator BEFORE the handler actually becomes active httpContext.setAuthenticator(authenticator); @@ -107,8 +123,9 @@ public class CmsDeploymentImpl implements CmsDeployment { if (contextPath == null) return; // ignore silently httpHandlers.remove(contextPath); - if (httpServer.join() == null) + if (!httpExpected || !httpServer.isDone()) return; + // TODO use resultNow when switching to Java 21 httpServer.join().removeContext(contextPath); log.debug(() -> "Removed handler " + contextPath + " : " + httpHandler.getClass().getName()); }