public void setHttpServer(HttpServer httpServer) {
Objects.requireNonNull(httpServer);
if (this.httpServer.isDone())
- throw new IllegalStateException("HTTP server is already set");
+ 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) {
}
if (!this.httpServer.isDone())
throw new IllegalStateException("HTTP server is not set");
- HttpContext httpContext = httpServer.resultNow().createContext(contextPath);
+ // 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);
httpContext.setHandler(httpHandler);
httpHandlers.remove(contextPath);
if (!httpServer.isDone())
return;
- httpServer.resultNow().removeContext(contextPath);
+ // TODO use resultNow when switching to Java 21
+ httpServer.join().removeContext(contextPath);
log.debug(() -> "Removed handler " + contextPath + " : " + httpHandler.getClass().getName());
}