use of org.commonjava.indy.boot.BootStatus 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;
}
use of org.commonjava.indy.boot.BootStatus in project indy by Commonjava.
the class JaxRsBooter method initialize.
@Override
public boolean initialize(final BootOptions bootOptions) {
this.bootOptions = bootOptions;
boolean initialized;
try {
bootOptions.setSystemProperties();
weld = new Weld();
container = weld.initialize();
// injectable version.
final BootOptions cdiOptions = container.instance().select(BootOptions.class).get();
cdiOptions.copyFrom(bootOptions);
final BeanManager bmgr = container.getBeanManager();
logger.info("\n\n\nStarted BeanManager: {}\n\n\n", bmgr);
initialized = true;
} catch (final Throwable e) {
logger.error("Failed to initialize Booter: " + e.getMessage(), e);
exit = ERR_CANT_INIT_BOOTER;
status = new BootStatus(exit, e);
initialized = false;
}
return initialized;
}
Aggregations