Java Code Examples for io.undertow.servlet.api.DeploymentManager#stop()

The following examples show how to use io.undertow.servlet.api.DeploymentManager#stop() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CamelEndpointDeployerService.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
private void undeploy(DeploymentManager deploymentManager) {
    final Deployment deployment = deploymentManager.getDeployment();
    CamelLogger.LOGGER.debug("Undeploying endpoint {}", deployment.getDeploymentInfo().getDeploymentName());

    final ClassLoader old = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(deployment.getDeploymentInfo().getClassLoader());
    try {
        try {
            hostSupplier.getValue().unregisterDeployment(deployment);
            deploymentManager.stop();
        } catch (ServletException e) {
            throw new RuntimeException(e);
        }
        deploymentManager.undeploy();
        servletContainerServiceSupplier.getValue().getServletContainer().removeDeployment(deployment.getDeploymentInfo());
    } finally {
        Thread.currentThread().setContextClassLoader(old);
    }

}
 
Example 2
Source File: KeycloakOnUndertow.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public void undeploy(Archive<?> archive) throws DeploymentException {
    if (isRemoteMode()) {
        log.infof("Skipped undeployment of '%s' as we are in remote mode!", archive.getName());
        return;
    }

    Field containerField = Reflections.findDeclaredField(UndertowJaxrsServer.class, "container");
    Reflections.setAccessible(containerField);
    ServletContainer container = (ServletContainer) Reflections.getFieldValue(containerField, undertow);

    DeploymentManager deploymentMgr = container.getDeployment(archive.getName());
    if (deploymentMgr != null) {
        DeploymentInfo deployment = deploymentMgr.getDeployment().getDeploymentInfo();

        try {
            deploymentMgr.stop();
        } catch (ServletException se) {
            throw new DeploymentException(se.getMessage(), se);
        }

        deploymentMgr.undeploy();

        Field rootField = Reflections.findDeclaredField(UndertowJaxrsServer.class, "root");
        Reflections.setAccessible(rootField);
        PathHandler root = (PathHandler) Reflections.getFieldValue(rootField, undertow);

        String path = deployedArchivesToContextPath.get(archive.getName());
        root.removePrefixPath(path);

        container.removeDeployment(deployment);
    } else {
        log.warnf("Deployment '%s' not found", archive.getName());
    }
}
 
Example 3
Source File: UndertowAppServer.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public void undeploy(Archive<?> archive) throws DeploymentException {
    log.info("Undeploying archive " + archive.getName());
    Field containerField = Reflections.findDeclaredField(UndertowJaxrsServer.class, "container");
    Reflections.setAccessible(containerField);
    ServletContainer container = (ServletContainer) Reflections.getFieldValue(containerField, undertow);

    DeploymentManager deploymentMgr = container.getDeployment(archive.getName());
    if (deploymentMgr != null) {
        DeploymentInfo deployment = deploymentMgr.getDeployment().getDeploymentInfo();

        try {
            deploymentMgr.stop();
        } catch (ServletException se) {
            throw new DeploymentException(se.getMessage(), se);
        }

        deploymentMgr.undeploy();

        Field rootField = Reflections.findDeclaredField(UndertowJaxrsServer.class, "root");
        Reflections.setAccessible(rootField);
        PathHandler root = (PathHandler) Reflections.getFieldValue(rootField, undertow);

        String path = deployedArchivesToContextPath.get(archive.getName());
        root.removePrefixPath(path);

        container.removeDeployment(deployment);
    } else {
        log.warnf("Deployment '%s' not found", archive.getName());
    }
}
 
Example 4
Source File: ServletLifecycleTestCase.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
@Test
public void testServletLifecycle() throws Exception {


    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    ServletInfo s = new ServletInfo("servlet", LifeCycleServlet.class)
            .addMapping("/aa");
    FilterInfo f = new FilterInfo("filter", LifecycleFilter.class);

    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(ServletLifecycleTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .addServlet(s)
            .addFilter(f)
            .addFilterUrlMapping("filter", "/aa", DispatcherType.REQUEST);

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(root);

    TestHttpClient client = new TestHttpClient();
    try {
        HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/aa");
        HttpResponse result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        final String response = HttpClientUtils.readResponse(result);

        manager.stop();
        manager.undeploy();

        Assert.assertTrue(LifeCycleServlet.initCalled);
        Assert.assertTrue(LifeCycleServlet.destroyCalled);
        Assert.assertTrue(LifecycleFilter.initCalled);
        Assert.assertTrue(LifecycleFilter.destroyCalled);

    } finally {
        client.getConnectionManager().shutdown();
    }
}
 
Example 5
Source File: ServletSessionPersistenceTestCase.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
@Test
public void testSimpleSessionUsage() throws IOException, ServletException {
    final PathHandler pathHandler = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(SimpleServletTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .setSessionPersistenceManager(new InMemorySessionPersistence())
            .setServletSessionConfig(new ServletSessionConfig().setPath("/servletContext/aa"))
            .addServlets(new ServletInfo("servlet", SessionServlet.class)
                    .addMapping("/aa/b"));
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    try {
        pathHandler.addPrefixPath(builder.getContextPath(), manager.start());
    } catch (ServletException e) {
        throw new RuntimeException(e);
    }
    DefaultServer.setRootHandler(pathHandler);
    TestHttpClient client = new TestHttpClient();
    try {
        HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/aa/b");
        HttpResponse result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        String response = HttpClientUtils.readResponse(result);
        Assert.assertEquals("1", response);

        String cookieValue = result.getHeaders("Set-Cookie")[0].getValue();
        Assert.assertTrue(cookieValue, cookieValue.contains("JSESSIONID"));
        Assert.assertTrue(cookieValue, cookieValue.contains("/servletContext/aa"));

        result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        response = HttpClientUtils.readResponse(result);
        Assert.assertEquals("2", response);

        manager.stop();
        manager.undeploy();
        manager.deploy();
        pathHandler.addPrefixPath(builder.getContextPath(), manager.start());

        result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        response = HttpClientUtils.readResponse(result);
        Assert.assertEquals("3", response);


    } finally {
        client.getConnectionManager().shutdown();
    }
}