Search in sources :

Example 1 with UndertowWarClassLoader

use of org.keycloak.testsuite.utils.undertow.UndertowWarClassLoader in project keycloak by keycloak.

the class KeycloakOnUndertow method deploy.

@Override
public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
    if (isRemoteMode()) {
        log.infof("Skipped deployment of '%s' as we are in remote mode!", archive.getName());
        return new ProtocolMetaData();
    }
    DeploymentInfo di = getDeplotymentInfoFromArchive(archive);
    ClassLoader parentCl = Thread.currentThread().getContextClassLoader();
    UndertowWarClassLoader classLoader = new UndertowWarClassLoader(parentCl, archive);
    Thread.currentThread().setContextClassLoader(classLoader);
    try {
        undertow.deploy(di);
    } finally {
        Thread.currentThread().setContextClassLoader(parentCl);
    }
    deployedArchivesToContextPath.put(archive.getName(), di.getContextPath());
    return new ProtocolMetaData().addContext(createHttpContextForDeploymentInfo(di));
}
Also used : UndertowWarClassLoader(org.keycloak.testsuite.utils.undertow.UndertowWarClassLoader) UndertowWarClassLoader(org.keycloak.testsuite.utils.undertow.UndertowWarClassLoader) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo)

Example 2 with UndertowWarClassLoader

use of org.keycloak.testsuite.utils.undertow.UndertowWarClassLoader in project keycloak by keycloak.

the class UndertowAppServer method deploy.

@Override
public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
    log.info("Deploying archive " + archive.getName());
    // Remove jsps
    // My Intellij and Terminal stores tmp directory in this property
    String ioTMPDir = System.getProperty("java.io.tmpdir", "");
    if (!ioTMPDir.isEmpty()) {
        ioTMPDir = ioTMPDir.endsWith("/") ? ioTMPDir : ioTMPDir + "/";
        File tmpUndertowJSPDirectory = new File(ioTMPDir + "org/apache/jsp");
        if (tmpUndertowJSPDirectory.exists()) {
            try {
                FileUtils.deleteDirectory(tmpUndertowJSPDirectory);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    DeploymentInfo di;
    if (archive instanceof UndertowWebArchive) {
        di = ((UndertowWebArchive) archive).getDeploymentInfo();
    } else if (archive instanceof WebArchive) {
        WebArchive webArchive = (WebArchive) archive;
        Optional<Node> applicationClassNode = archive.getContent(archivePath -> archivePath.get().startsWith("/WEB-INF/classes/") && archivePath.get().endsWith("Application.class")).values().stream().findFirst();
        if (isJaxrsApp(webArchive)) {
            di = new UndertowDeployerHelper().getDeploymentInfo(configuration, webArchive, undertow.undertowDeployment(discoverPathAnnotatedClasses(webArchive)));
        } else if (applicationClassNode.isPresent()) {
            String applicationPath = applicationClassNode.get().getPath().get();
            ResteasyDeployment deployment = new ResteasyDeployment();
            deployment.setApplicationClass(extractClassName(applicationPath));
            di = new UndertowDeployerHelper().getDeploymentInfo(configuration, (WebArchive) archive, undertow.undertowDeployment(deployment));
        } else {
            di = new UndertowDeployerHelper().getDeploymentInfo(configuration, webArchive);
        }
    } else {
        throw new IllegalArgumentException("UndertowContainer only supports UndertowWebArchive or WebArchive.");
    }
    if ("ROOT.war".equals(archive.getName())) {
        di.setContextPath("/");
    }
    ClassLoader parentCl = Thread.currentThread().getContextClassLoader();
    UndertowWarClassLoader classLoader = new UndertowWarClassLoader(parentCl, archive);
    Thread.currentThread().setContextClassLoader(classLoader);
    try {
        undertow.deploy(di);
    } finally {
        Thread.currentThread().setContextClassLoader(parentCl);
    }
    deployedArchivesToContextPath.put(archive.getName(), di.getContextPath());
    return new ProtocolMetaData().addContext(createHttpContextForDeploymentInfo(di));
}
Also used : Optional(java.util.Optional) UndertowWebArchive(org.jboss.shrinkwrap.undertow.api.UndertowWebArchive) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) UndertowWebArchive(org.jboss.shrinkwrap.undertow.api.UndertowWebArchive) IOException(java.io.IOException) ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) UndertowWarClassLoader(org.keycloak.testsuite.utils.undertow.UndertowWarClassLoader) UndertowWarClassLoader(org.keycloak.testsuite.utils.undertow.UndertowWarClassLoader) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) File(java.io.File) UndertowDeployerHelper(org.keycloak.testsuite.utils.undertow.UndertowDeployerHelper)

Aggregations

DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)2 ProtocolMetaData (org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData)2 UndertowWarClassLoader (org.keycloak.testsuite.utils.undertow.UndertowWarClassLoader)2 File (java.io.File)1 IOException (java.io.IOException)1 Optional (java.util.Optional)1 ResteasyDeployment (org.jboss.resteasy.spi.ResteasyDeployment)1 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)1 UndertowWebArchive (org.jboss.shrinkwrap.undertow.api.UndertowWebArchive)1 UndertowDeployerHelper (org.keycloak.testsuite.utils.undertow.UndertowDeployerHelper)1