Merge pull request #1695 from stianst/fix-undertow-start
KEYCLOAK-1935 Stop KeycloakServer if Undertow fails to start
This commit is contained in:
commit
3ab7edbbcd
1 changed files with 29 additions and 22 deletions
|
@ -46,6 +46,7 @@ import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.BindException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -289,37 +290,43 @@ public class KeycloakServer {
|
||||||
.setWorkerThreads(config.getWorkerThreads())
|
.setWorkerThreads(config.getWorkerThreads())
|
||||||
.setIoThreads(config.getWorkerThreads() / 8);
|
.setIoThreads(config.getWorkerThreads() / 8);
|
||||||
|
|
||||||
server = new UndertowJaxrsServer().start(builder);
|
server = new UndertowJaxrsServer();
|
||||||
|
try {
|
||||||
|
server.start(builder);
|
||||||
|
|
||||||
DeploymentInfo di = server.undertowDeployment(deployment, "");
|
DeploymentInfo di = server.undertowDeployment(deployment, "");
|
||||||
di.setClassLoader(getClass().getClassLoader());
|
di.setClassLoader(getClass().getClassLoader());
|
||||||
di.setContextPath("/auth");
|
di.setContextPath("/auth");
|
||||||
di.setDeploymentName("Keycloak");
|
di.setDeploymentName("Keycloak");
|
||||||
di.setDefaultEncoding("UTF-8");
|
di.setDefaultEncoding("UTF-8");
|
||||||
|
|
||||||
di.setDefaultServletConfig(new DefaultServletConfig(true));
|
di.setDefaultServletConfig(new DefaultServletConfig(true));
|
||||||
di.addWelcomePage("theme/keycloak/welcome/resources/index.html");
|
di.addWelcomePage("theme/keycloak/welcome/resources/index.html");
|
||||||
|
|
||||||
FilterInfo filter = Servlets.filter("SessionFilter", KeycloakSessionServletFilter.class);
|
FilterInfo filter = Servlets.filter("SessionFilter", KeycloakSessionServletFilter.class);
|
||||||
di.addFilter(filter);
|
di.addFilter(filter);
|
||||||
di.addFilterUrlMapping("SessionFilter", "/*", DispatcherType.REQUEST);
|
di.addFilterUrlMapping("SessionFilter", "/*", DispatcherType.REQUEST);
|
||||||
|
|
||||||
FilterInfo connectionFilter = Servlets.filter("ClientConnectionFilter", ClientConnectionFilter.class);
|
FilterInfo connectionFilter = Servlets.filter("ClientConnectionFilter", ClientConnectionFilter.class);
|
||||||
di.addFilter(connectionFilter);
|
di.addFilter(connectionFilter);
|
||||||
di.addFilterUrlMapping("ClientConnectionFilter", "/*", DispatcherType.REQUEST);
|
di.addFilterUrlMapping("ClientConnectionFilter", "/*", DispatcherType.REQUEST);
|
||||||
|
|
||||||
server.deploy(di);
|
server.deploy(di);
|
||||||
|
|
||||||
sessionFactory = ((KeycloakApplication) deployment.getApplication()).getSessionFactory();
|
sessionFactory = ((KeycloakApplication) deployment.getApplication()).getSessionFactory();
|
||||||
|
|
||||||
setupDevConfig();
|
setupDevConfig();
|
||||||
|
|
||||||
if (config.getResourcesHome() != null) {
|
if (config.getResourcesHome() != null) {
|
||||||
info("Loading resources from " + config.getResourcesHome());
|
info("Loading resources from " + config.getResourcesHome());
|
||||||
|
}
|
||||||
|
|
||||||
|
info("Started Keycloak (http://" + config.getHost() + ":" + config.getPort() + "/auth) in "
|
||||||
|
+ (System.currentTimeMillis() - start) + " ms\n");
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
server.stop();
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
info("Started Keycloak (http://" + config.getHost() + ":" + config.getPort() + "/auth) in "
|
|
||||||
+ (System.currentTimeMillis() - start) + " ms\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void info(String message) {
|
private void info(String message) {
|
||||||
|
|
Loading…
Reference in a new issue