Search in sources :

Example 1 with DeployException

use of org.commonjava.propulsor.deploy.DeployException in project indy by Commonjava.

the class IndyDeployer method deploy.

@Override
public void deploy(BootOptions bootOptions) throws DeployException {
    final DeploymentInfo di = indyDeployment.getDeployment(bootOptions.getContextPath()).setContextPath("/");
    final DeploymentManager dm = Servlets.defaultContainer().addDeployment(di);
    Collection<String> list = Servlets.defaultContainer().listDeployments();
    logger.info("List deployments: {}", list);
    dm.deploy();
    try {
        Integer port = bootOptions.getPort();
        if (port < 1) {
            logger.info("Looking for open Undertow port...");
            final AtomicReference<Exception> errorHolder = new AtomicReference<>();
            final AtomicReference<Integer> usingPort = new AtomicReference<>();
            server = PortFinder.findPortFor(16, (foundPort) -> {
                usingPort.set(foundPort);
                try {
                    return buildAndStartUndertow(dm, foundPort, bootOptions.getBind(), restConfig);
                } catch (Exception e) {
                    errorHolder.set(e);
                }
                return null;
            });
            Exception e = errorHolder.get();
            if (e != null) {
                throw e;
            }
            bootOptions.setPort(usingPort.get());
        } else {
            logger.info("Start Undertow server, bind: {}, port: {}", bootOptions.getBind(), port);
            server = buildAndStartUndertow(dm, port, bootOptions.getBind(), restConfig);
        }
        logger.info("Indy listening on {}:{}\n\n", bootOptions.getBind(), bootOptions.getPort());
    } catch (Exception e) {
        logger.error("Deploy failed", e);
        throw new DeployException("Deploy failed", e);
    }
}
Also used : Predicates(io.undertow.predicate.Predicates) IndyDeployment(org.commonjava.indy.bind.jaxrs.IndyDeployment) ServletException(javax.servlet.ServletException) HttpServerExchange(io.undertow.server.HttpServerExchange) LoggerFactory(org.slf4j.LoggerFactory) ContentEncodingRepository(io.undertow.server.handlers.encoding.ContentEncodingRepository) AtomicReference(java.util.concurrent.atomic.AtomicReference) Undertow(io.undertow.Undertow) DeployException(org.commonjava.propulsor.deploy.DeployException) Servlets(io.undertow.servlet.Servlets) Inject(javax.inject.Inject) HashSet(java.util.HashSet) BootOptions(org.commonjava.propulsor.boot.BootOptions) DeflateEncodingProvider(io.undertow.server.handlers.encoding.DeflateEncodingProvider) GzipEncodingProvider(io.undertow.server.handlers.encoding.GzipEncodingProvider) Deployer(org.commonjava.propulsor.deploy.Deployer) UndertowOptions(io.undertow.UndertowOptions) Logger(org.slf4j.Logger) Collection(java.util.Collection) PortFinder(org.commonjava.propulsor.boot.PortFinder) Set(java.util.Set) MimeTyper(org.commonjava.indy.util.MimeTyper) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ApplicationContent(org.commonjava.indy.util.ApplicationContent) EncodingHandler(io.undertow.server.handlers.encoding.EncodingHandler) Predicate(io.undertow.predicate.Predicate) ApplicationScoped(javax.enterprise.context.ApplicationScoped) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) DeploymentManager(io.undertow.servlet.api.DeploymentManager) DeployException(org.commonjava.propulsor.deploy.DeployException) AtomicReference(java.util.concurrent.atomic.AtomicReference) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) ServletException(javax.servlet.ServletException) DeployException(org.commonjava.propulsor.deploy.DeployException)

Aggregations

Undertow (io.undertow.Undertow)1 UndertowOptions (io.undertow.UndertowOptions)1 Predicate (io.undertow.predicate.Predicate)1 Predicates (io.undertow.predicate.Predicates)1 HttpServerExchange (io.undertow.server.HttpServerExchange)1 ContentEncodingRepository (io.undertow.server.handlers.encoding.ContentEncodingRepository)1 DeflateEncodingProvider (io.undertow.server.handlers.encoding.DeflateEncodingProvider)1 EncodingHandler (io.undertow.server.handlers.encoding.EncodingHandler)1 GzipEncodingProvider (io.undertow.server.handlers.encoding.GzipEncodingProvider)1 Servlets (io.undertow.servlet.Servlets)1 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 DeploymentManager (io.undertow.servlet.api.DeploymentManager)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Inject (javax.inject.Inject)1 ServletException (javax.servlet.ServletException)1 IndyDeployment (org.commonjava.indy.bind.jaxrs.IndyDeployment)1