use of org.commonjava.indy.bind.jaxrs.IndyDeployment in project indy by Commonjava.
the class JaxRsBooter method deploy.
@Override
public boolean deploy() {
boolean started;
final IndyDeployment indyDeployment = container.instance().select(IndyDeployment.class).get();
final DeploymentInfo di = indyDeployment.getDeployment(bootOptions.getContextPath()).setContextPath("/");
final DeploymentManager dm = Servlets.defaultContainer().addDeployment(di);
dm.deploy();
status = new BootStatus();
try {
Integer port = bootOptions.getPort();
if (port < 1) {
System.out.println("Looking for open port...");
final ThreadLocal<ServletException> errorHolder = new ThreadLocal<>();
ThreadLocal<Integer> usingPort = new ThreadLocal<>();
server = PortFinder.findPortFor(16, (foundPort) -> {
Undertow undertow = null;
try {
undertow = Undertow.builder().setHandler(dm.start()).addHttpListener(foundPort, bootOptions.getBind()).build();
undertow.start();
usingPort.set(foundPort);
} catch (ServletException e) {
errorHolder.set(e);
}
return undertow;
});
ServletException e = errorHolder.get();
if (e != null) {
throw e;
}
bootOptions.setPort(usingPort.get());
} else {
server = Undertow.builder().setHandler(dm.start()).addHttpListener(port, bootOptions.getBind()).build();
server.start();
}
System.out.println("Using: " + bootOptions.getPort());
status.markSuccess();
started = true;
System.out.printf("Indy listening on %s:%s\n\n", bootOptions.getBind(), bootOptions.getPort());
} catch (ServletException | RuntimeException e) {
status.markFailed(ERR_CANT_LISTEN, e);
started = false;
}
return started;
}
Aggregations