Search in sources :

Example 1 with BootStatus

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;
}
Also used : IndyDeployment(org.commonjava.indy.bind.jaxrs.IndyDeployment) UncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler) ServletException(javax.servlet.ServletException) PortFinder(org.commonjava.indy.boot.PortFinder) LoggerFactory(org.slf4j.LoggerFactory) IndyLifecycleException(org.commonjava.indy.action.IndyLifecycleException) WeldBootInterface(org.commonjava.indy.boot.WeldBootInterface) Undertow(io.undertow.Undertow) IndyConfigFactory(org.commonjava.indy.conf.IndyConfigFactory) Servlets(io.undertow.servlet.Servlets) IndyLifecycleManager(org.commonjava.indy.action.IndyLifecycleManager) BootInterface(org.commonjava.indy.boot.BootInterface) ConfigurationException(org.commonjava.web.config.ConfigurationException) Service(org.commonjava.atservice.annotation.Service) Weld(org.jboss.weld.environment.se.Weld) Logger(org.slf4j.Logger) BootStatus(org.commonjava.indy.boot.BootStatus) BootOptions(org.commonjava.indy.boot.BootOptions) WeldContainer(org.jboss.weld.environment.se.WeldContainer) DeploymentManager(io.undertow.servlet.api.DeploymentManager) InvocationTargetException(java.lang.reflect.InvocationTargetException) IndyBootException(org.commonjava.indy.boot.IndyBootException) Holder(javax.xml.ws.Holder) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) BeanManager(javax.enterprise.inject.spi.BeanManager) DeploymentManager(io.undertow.servlet.api.DeploymentManager) BootStatus(org.commonjava.indy.boot.BootStatus) IndyDeployment(org.commonjava.indy.bind.jaxrs.IndyDeployment) ServletException(javax.servlet.ServletException) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) Undertow(io.undertow.Undertow)

Example 2 with BootStatus

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;
}
Also used : BootStatus(org.commonjava.indy.boot.BootStatus) BootOptions(org.commonjava.indy.boot.BootOptions) BeanManager(javax.enterprise.inject.spi.BeanManager) Weld(org.jboss.weld.environment.se.Weld)

Aggregations

BeanManager (javax.enterprise.inject.spi.BeanManager)2 BootOptions (org.commonjava.indy.boot.BootOptions)2 BootStatus (org.commonjava.indy.boot.BootStatus)2 Weld (org.jboss.weld.environment.se.Weld)2 Undertow (io.undertow.Undertow)1 Servlets (io.undertow.servlet.Servlets)1 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 DeploymentManager (io.undertow.servlet.api.DeploymentManager)1 UncaughtExceptionHandler (java.lang.Thread.UncaughtExceptionHandler)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ServletException (javax.servlet.ServletException)1 Holder (javax.xml.ws.Holder)1 Service (org.commonjava.atservice.annotation.Service)1 IndyLifecycleException (org.commonjava.indy.action.IndyLifecycleException)1 IndyLifecycleManager (org.commonjava.indy.action.IndyLifecycleManager)1 IndyDeployment (org.commonjava.indy.bind.jaxrs.IndyDeployment)1 BootInterface (org.commonjava.indy.boot.BootInterface)1 IndyBootException (org.commonjava.indy.boot.IndyBootException)1 PortFinder (org.commonjava.indy.boot.PortFinder)1 WeldBootInterface (org.commonjava.indy.boot.WeldBootInterface)1