Search in sources :

Example 61 with DeploymentInfo

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

the class UndertowHostTestCase method getContexts.

@Test
public void getContexts() {
    Deployment deployment = mock(Deployment.class);
    DeploymentInfo info = new DeploymentInfo();
    String expectedPath = "";
    info.setContextPath(expectedPath);
    HttpHandler handler = mock(HttpHandler.class);
    when(deployment.getDeploymentInfo()).thenReturn(info);
    this.undertowHost.registerDeployment(deployment, handler);
    Iterator<Context> result = this.host.getContexts().iterator();
    assertTrue(result.hasNext());
    Context context = result.next();
    assertSame(this.host, context.getHost());
    assertSame(expectedPath, context.getPath());
    assertFalse(result.hasNext());
}
Also used : Context(org.jboss.modcluster.container.Context) HttpHandler(io.undertow.server.HttpHandler) Deployment(io.undertow.servlet.api.Deployment) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) Test(org.junit.Test)

Example 62 with DeploymentInfo

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

the class VolatileParticipantService method deployParticipant.

private void deployParticipant() {
    undeployServlet();
    final Map<String, String> initialParameters = new HashMap<String, String>();
    initialParameters.put("javax.ws.rs.Application", VolatileParticipantApplication.class.getName());
    final DeploymentInfo participantDeploymentInfo = getDeploymentInfo(DEPLOYMENT_NAME, CONTEXT_PATH, initialParameters);
    deployServlet(participantDeploymentInfo);
}
Also used : HashMap(java.util.HashMap) VolatileParticipantApplication(org.wildfly.extension.rts.jaxrs.VolatileParticipantApplication) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo)

Example 63 with DeploymentInfo

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

the class AbstractRTSService method getDeploymentInfo.

protected DeploymentInfo getDeploymentInfo(final String name, final String contextPath, final Map<String, String> initialParameters) {
    final DeploymentInfo deploymentInfo = new DeploymentInfo();
    deploymentInfo.setClassLoader(ParticipantService.class.getClassLoader());
    deploymentInfo.setContextPath(contextPath);
    deploymentInfo.setDeploymentName(name);
    deploymentInfo.addServlets(getResteasyServlet());
    deploymentInfo.addListener(getResteasyListener());
    deploymentInfo.addListener(getRestATListener());
    for (Entry<String, String> entry : initialParameters.entrySet()) {
        deploymentInfo.addInitParameter(entry.getKey(), entry.getValue());
    }
    return deploymentInfo;
}
Also used : DeploymentInfo(io.undertow.servlet.api.DeploymentInfo)

Example 64 with DeploymentInfo

use of io.undertow.servlet.api.DeploymentInfo 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 65 with DeploymentInfo

use of io.undertow.servlet.api.DeploymentInfo in project indy by Commonjava.

the class IndyDeployment method getDeployment.

public DeploymentInfo getDeployment(final String contextRoot) {
    final ResteasyDeployment deployment = new ResteasyDeployment();
    deployment.setApplication(this);
    deployment.setInjectorFactoryClass(CdiInjectorFactoryImpl.class.getName());
    final ServletInfo resteasyServlet = Servlets.servlet("REST", HttpServlet30Dispatcher.class).setAsyncSupported(true).setLoadOnStartup(1).addMapping("/api*").addMapping("/api/*").addMapping("/api-docs*").addMapping("/api-docs/*").addMapping("/swagger.json").addMapping("/swagger.yaml");
    final BeanConfig beanConfig = new BeanConfig();
    beanConfig.setResourcePackage("org.commonjava.indy");
    beanConfig.setBasePath("/");
    beanConfig.setLicense("ASLv2");
    beanConfig.setLicenseUrl("http://www.apache.org/licenses/LICENSE-2.0");
    beanConfig.setScan(true);
    beanConfig.setVersion(versioning.getApiVersion());
    final FilterInfo resourceManagementFilter = Servlets.filter("Naming and Resource Management", ResourceManagementFilter.class, new ImmediateInstanceFactory<ResourceManagementFilter>(this.resourceManagementFilter));
    final DeploymentInfo di = new DeploymentInfo().addListener(Servlets.listener(RequestScopeListener.class)).setContextPath(contextRoot).addServletContextAttribute(ResteasyDeployment.class.getName(), deployment).addServlet(resteasyServlet).addFilter(resourceManagementFilter).addFilterUrlMapping(resourceManagementFilter.getName(), "/api/*", DispatcherType.REQUEST).setDeploymentName("Indy").setClassLoader(ClassLoader.getSystemClassLoader()).addOuterHandlerChainWrapper(new HeaderDebugger.Wrapper());
    if (deploymentProviders != null) {
        DeploymentInfoUtils.mergeFromProviders(di, deploymentProviders);
    }
    // Add UI servlet at the end so its mappings don't obscure any from add-ons.
    final ServletInfo uiServlet = Servlets.servlet("UI", UIServlet.class).setAsyncSupported(true).setLoadOnStartup(99).addMappings(UIServlet.PATHS);
    uiServlet.setInstanceFactory(new ImmediateInstanceFactory<Servlet>(ui));
    di.addServlet(uiServlet);
    return di;
}
Also used : BeanConfig(io.swagger.jaxrs.config.BeanConfig) ServletInfo(io.undertow.servlet.api.ServletInfo) ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) Servlet(javax.servlet.Servlet) UIServlet(org.commonjava.indy.bind.jaxrs.ui.UIServlet) RequestScopeListener(org.commonjava.indy.bind.jaxrs.util.RequestScopeListener) UIServlet(org.commonjava.indy.bind.jaxrs.ui.UIServlet) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) FilterInfo(io.undertow.servlet.api.FilterInfo) CdiInjectorFactoryImpl(org.commonjava.indy.bind.jaxrs.util.CdiInjectorFactoryImpl)

Aggregations

DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)113 DeploymentManager (io.undertow.servlet.api.DeploymentManager)75 ServletContainer (io.undertow.servlet.api.ServletContainer)69 ServletInfo (io.undertow.servlet.api.ServletInfo)63 PathHandler (io.undertow.server.handlers.PathHandler)59 BeforeClass (org.junit.BeforeClass)55 FilterInfo (io.undertow.servlet.api.FilterInfo)20 SimpleServletTestCase (io.undertow.servlet.test.SimpleServletTestCase)17 TestResourceLoader (io.undertow.servlet.test.util.TestResourceLoader)17 WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)16 LoginConfig (io.undertow.servlet.api.LoginConfig)15 ServletException (javax.servlet.ServletException)15 HttpHandler (io.undertow.server.HttpHandler)12 SecurityConstraint (io.undertow.servlet.api.SecurityConstraint)11 WebResourceCollection (io.undertow.servlet.api.WebResourceCollection)11 Test (org.junit.Test)11 ListenerInfo (io.undertow.servlet.api.ListenerInfo)10 ServletIdentityManager (io.undertow.servlet.test.security.constraint.ServletIdentityManager)10 ServerWebSocketContainer (io.undertow.websockets.jsr.ServerWebSocketContainer)8 HashMap (java.util.HashMap)8