Search in sources :

Example 46 with DeploymentManager

use of io.undertow.servlet.api.DeploymentManager in project undertow by undertow-io.

the class JSRWebSocketServer method main.

public static void main(final String[] args) {
    PathHandler path = Handlers.path();
    Undertow server = Undertow.builder().addHttpListener(8080, "localhost").setHandler(path).build();
    server.start();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(JSRWebSocketServer.class.getClassLoader()).setContextPath("/").addWelcomePage("index.html").setResourceManager(new ClassPathResourceManager(JSRWebSocketServer.class.getClassLoader(), JSRWebSocketServer.class.getPackage())).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(new DefaultByteBufferPool(true, 100)).addEndpoint(JsrChatWebSocketEndpoint.class)).setDeploymentName("chat.war");
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    try {
        path.addPrefixPath("/", manager.start());
    } catch (ServletException e) {
        throw new RuntimeException(e);
    }
}
Also used : ServletException(javax.servlet.ServletException) DefaultByteBufferPool(io.undertow.server.DefaultByteBufferPool) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) PathHandler(io.undertow.server.handlers.PathHandler) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) ClassPathResourceManager(io.undertow.server.handlers.resource.ClassPathResourceManager) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) Undertow(io.undertow.Undertow)

Example 47 with DeploymentManager

use of io.undertow.servlet.api.DeploymentManager in project undertow by undertow-io.

the class ServletContainerImpl method getDeploymentByPath.

@Override
public DeploymentManager getDeploymentByPath(final String path) {
    DeploymentManager exact = deploymentsByPath.get(path.isEmpty() ? "/" : path);
    if (exact != null) {
        return exact;
    }
    int length = path.length();
    int pos = length;
    while (pos > 1) {
        --pos;
        if (path.charAt(pos) == '/') {
            String part = path.substring(0, pos);
            DeploymentManager deployment = deploymentsByPath.get(part);
            if (deployment != null) {
                return deployment;
            }
        }
    }
    return deploymentsByPath.get("/");
}
Also used : DeploymentManager(io.undertow.servlet.api.DeploymentManager)

Example 48 with DeploymentManager

use of io.undertow.servlet.api.DeploymentManager in project undertow by undertow-io.

the class ServletContainerImpl method addDeployment.

@Override
public DeploymentManager addDeployment(final DeploymentInfo deployment) {
    final DeploymentInfo dep = deployment.clone();
    DeploymentManager deploymentManager = new DeploymentManagerImpl(dep, this);
    deployments.put(dep.getDeploymentName(), deploymentManager);
    deploymentsByPath.put(dep.getContextPath(), deploymentManager);
    return deploymentManager;
}
Also used : DeploymentManager(io.undertow.servlet.api.DeploymentManager) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo)

Example 49 with DeploymentManager

use of io.undertow.servlet.api.DeploymentManager in project wildfly by wildfly.

the class AbstractRTSService method deployServlet.

protected void deployServlet(final DeploymentInfo deploymentInfo) {
    DeploymentManager manager = ServletContainer.Factory.newInstance().addDeployment(deploymentInfo);
    manager.deploy();
    deployment = manager.getDeployment();
    try {
        injectedHost.getValue().registerDeployment(deployment, manager.start());
    } catch (ServletException e) {
        RTSLogger.ROOT_LOGGER.warn(e.getMessage(), e);
        deployment = null;
    }
}
Also used : ServletException(javax.servlet.ServletException) DeploymentManager(io.undertow.servlet.api.DeploymentManager)

Example 50 with DeploymentManager

use of io.undertow.servlet.api.DeploymentManager 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)

Aggregations

DeploymentManager (io.undertow.servlet.api.DeploymentManager)84 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)75 ServletContainer (io.undertow.servlet.api.ServletContainer)69 PathHandler (io.undertow.server.handlers.PathHandler)58 BeforeClass (org.junit.BeforeClass)53 ServletInfo (io.undertow.servlet.api.ServletInfo)51 TestResourceLoader (io.undertow.servlet.test.util.TestResourceLoader)17 FilterInfo (io.undertow.servlet.api.FilterInfo)16 SimpleServletTestCase (io.undertow.servlet.test.SimpleServletTestCase)16 ServletException (javax.servlet.ServletException)14 WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)13 LoginConfig (io.undertow.servlet.api.LoginConfig)12 ServletIdentityManager (io.undertow.servlet.test.security.constraint.ServletIdentityManager)10 ListenerInfo (io.undertow.servlet.api.ListenerInfo)8 SecurityConstraint (io.undertow.servlet.api.SecurityConstraint)8 WebResourceCollection (io.undertow.servlet.api.WebResourceCollection)8 ServerWebSocketContainer (io.undertow.websockets.jsr.ServerWebSocketContainer)8 Test (org.junit.Test)8 TestHttpClient (io.undertow.testutils.TestHttpClient)7 ServletSecurityInfo (io.undertow.servlet.api.ServletSecurityInfo)5