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);
+ }
+ }
}
}
}
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 == null) {
+ synchronized (httpHandlers) {
+ synchronized (httpAuthenticators) {
+ httpHandlers.put(contextPath, httpHandler);
+ httpAuthenticators.put(contextPath, authenticator);
+ }
+ }
+ if (!httpServer.isDone()) {
return;
} else {
createHttpContext(contextPath, httpHandler, authenticator);
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);
if (contextPath == null)
return; // ignore silently
httpHandlers.remove(contextPath);
- if (httpServer == 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());
}
public boolean allExpectedServicesAvailable() {
- if (httpExpected && httpServer == null)
+ if (httpExpected && !httpServer.isDone())
return false;
- if (sshdExpected && cmsSshd == null)
+ if (sshdExpected && !cmsSshd.isDone())
return false;
return true;
}