org.jboss.arquillian.container.spi.client.container.DeploymentException Java Examples

The following examples show how to use org.jboss.arquillian.container.spi.client.container.DeploymentException. 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: KeycloakOnUndertow.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example #2
Source File: StrictModeEnabledByDefaultTest.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Deployment
@AddonDependencies({
         @AddonDependency(name = INCOMPATIBLE, version = INCOMPATIBLE_VERSION, optional = true,
                  shouldThrowException = DeploymentException.class,
                  listener = {
                           TestRepositoryDeploymentListener.class,
                           FurnaceVersion_2_14_0_DeploymentListener.class
                  }, timeout = 5000
         ),
         @AddonDependency(name = COMPATIBLE, version = COMPATIBLE_VERSION, listener = TestRepositoryDeploymentListener.class)
})
public static AddonArchive getDeployment() throws Exception
{
   AddonArchive archive = ShrinkWrap.create(AddonArchive.class);
   archive.addAsLocalServices(StrictModeEnabledByDefaultTest.class);
   return archive;
}
 
Example #3
Source File: ManagedSEDeployableContainer.java    From camel-spring-boot with Apache License 2.0 6 votes vote down vote up
private boolean isJMXTestRunnerMBeanRegistered(final String host, final int port, int waitTime) throws DeploymentException {
    // Taken from org.jboss.arquillian.container.spi.client.protocol.metadata.JMXContext
    final String jmxServiceUrl = "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi";
    try (JMXConnector jmxc = JMXConnectorFactory.connect(new JMXServiceURL(jmxServiceUrl), null)) {
        final MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
        return new Await(waitTime, new Callable<Boolean>() {
            @Override
            public Boolean call() throws Exception {
                mbsc.getObjectInstance(new ObjectName(JMXTestRunnerMBean.OBJECT_NAME));
                LOGGER.fine("JMXTestRunnerMBean registered with the remote MBean server at: " + jmxServiceUrl);
                return true;
            }
        }).start();
    } catch (IOException e) {
        throw new DeploymentException("Could not verify JMXTestRunnerMBean registration", e);
    }
}
 
Example #4
Source File: ManagedSEDeployableContainer.java    From camel-spring-boot with Apache License 2.0 6 votes vote down vote up
private void readJarFilesFromDirectory() throws DeploymentException {
    if (librariesPath == null) {
        return;
    }
    File lib = new File(librariesPath);
    if (!lib.exists() || lib.isFile()) {
        throw new DeploymentException("Cannot read files from " + librariesPath);
    }

    File[] dep = lib.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith(".jar");
        }
    });
    classpathDependencies.addAll(Arrays.asList(dep));

}
 
Example #5
Source File: FileDeploymentUtils.java    From camel-spring-boot with Apache License 2.0 6 votes vote down vote up
public static void materializeSubdirectories(File entryDirectory, Node node) throws DeploymentException, IOException {
    for (Node child : node.getChildren()) {
        if (child.getAsset() == null) {
            materializeSubdirectories(entryDirectory, child);
        } else {
            if (ClassPathDirectory.isMarkerFileArchivePath(child.getPath())) {
                // Do not materialize the marker file
                continue;
            }
            // E.g. META-INF/my-super-descriptor.xml
            File resourceFile = new File(entryDirectory, child.getPath().get().replace(DELIMITER_RESOURCE_PATH, File.separatorChar));
            File resoureDirectory = resourceFile.getParentFile();
            if (!resoureDirectory.exists() && !resoureDirectory.mkdirs()) {
                throw new DeploymentException("Could not create class path directory: " + entryDirectory);
            }
            resourceFile.createNewFile();
            try (InputStream in = child.getAsset().openStream(); OutputStream out = new FileOutputStream(resourceFile)) {
                copy(in, out);
            }
            child.getPath().get();
        }
    }
}
 
Example #6
Source File: PiranhaServerDeployableContainer.java    From piranha with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
    LOGGER.info("Starting Piranha Micro");

    microOuterDeployer = new MicroOuterDeployer(configuration);

    Set<String> servletNames = microOuterDeployer.deploy(archive);

    HTTPContext httpContext = new HTTPContext("localhost", configuration.getPort());
    for (String servletName : servletNames) {
        httpContext.add(new Servlet(servletName, "/"));
    }

    ProtocolMetaData protocolMetaData = new ProtocolMetaData();
    protocolMetaData.addContext(httpContext);

    return protocolMetaData;
}
 
Example #7
Source File: ManagedSEDeployableContainer.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
private void materializeDirectory(Archive<?> archive) throws DeploymentException {
    if (archive.getContent().isEmpty()) {
        // Do not materialize an empty directory
        return;
    }
    File entryDirectory = new File(TARGET.concat(File.separator).concat(archive.getName()));
    try {
        if (entryDirectory.exists()) {
            // Always delete previous content
            FileDeploymentUtils.deleteContent(entryDirectory.toPath());
        } else {
            if (!entryDirectory.mkdirs()) {
                throw new DeploymentException("Could not create class path directory: " + entryDirectory);
            }
        }
        for (Node child : archive.get(ClassPath.ROOT_ARCHIVE_PATH).getChildren()) {
            Asset asset = child.getAsset();
            if (asset instanceof ClassAsset) {
                FileDeploymentUtils.materializeClass(entryDirectory, (ClassAsset) asset);
            } else if (asset == null) {
                FileDeploymentUtils.materializeSubdirectories(entryDirectory, child);
            }
        }
    } catch (IOException e) {
        throw new DeploymentException("Could not materialize class path directory: " + archive.getName(), e);
    }
    materializedFiles.add(entryDirectory);
}
 
Example #8
Source File: WildFlySwarmContainer.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
    StartupTimeout startupTimeout = this.testClass.getAnnotation(StartupTimeout.class);
    if (startupTimeout != null) {
        setTimeout(startupTimeout.value());
    }


    if (this.testClass.getAnnotation(InVM.class) != null) {
        this.delegateContainer = new InVMSimpleContainer(this.testClass);
    } else {
        this.delegateContainer = new UberjarSimpleContainer(this.testClass);
    }
    try {
        this.delegateContainer
                .requestedMavenArtifacts(this.requestedMavenArtifacts)
                .start(archive);
        // start wants to connect to the remote container, which isn't up until now, so
        // we override start above and call it here instead
        super.start();

        ProtocolMetaData metaData = new ProtocolMetaData();
        metaData.addContext(createDeploymentContext(archive.getId()));

        return metaData;
    } catch (Exception e) {
        throw new DeploymentException(e.getMessage(), e);
    }
}
 
Example #9
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 #10
Source File: MeecrowaveContainer.java    From openwebbeans-meecrowave with Apache License 2.0 5 votes vote down vote up
@Override
public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentException {
    final File dump = toArchiveDump(archive);
    archive.as(ZipExporter.class).exportTo(dump, true);
    final String context = sanitizeName(archive);
    container.deployWebapp(context, dump);
    final int port = configuration.isSkipHttp() ? configuration.getHttpsPort() : configuration.getHttpPort();
    return new ProtocolMetaData()
            .addContext(new HTTPContext(configuration.getHost(), port)
                    .add(new Servlet("arquillian", context)));
}
 
Example #11
Source File: WildFlySwarmContainer.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
    BootstrapUtil.convertSwarmSystemPropertiesToThorntail();

    StartupTimeout startupTimeout = this.testClass.getAnnotation(StartupTimeout.class);
    if (startupTimeout != null) {
        setTimeout(startupTimeout.value());
    }

    this.delegateContainer = new UberjarSimpleContainer(this.containerContext.get(), this.deploymentContext.get(), this.testClass);

    try {
        this.delegateContainer
                .setJavaVmArguments(this.getJavaVmArguments())
                .requestedMavenArtifacts(this.requestedMavenArtifacts)
                .start(archive);
        // start wants to connect to the remote container, which isn't up until now, so
        // we override start above and call it here instead
        super.start();

        ProtocolMetaData metaData = new ProtocolMetaData();
        metaData.addContext(createDeploymentContext(archive.getId()));

        return metaData;
    } catch (Throwable e) {
        if (e instanceof LifecycleException) {
            e = e.getCause();
        }
        throw new DeploymentException(e.getMessage(), e);
    }
}
 
Example #12
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 #13
Source File: ManagedSEDeployableContainer.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
private void addTestResourcesDirectory(Properties properties) throws DeploymentException {
    String testResources = properties.getProperty("container.test.resources.dir");
    if (testResources != null) {
        File testDir = new File(testResources);
        if (testDir.exists() && testDir.isDirectory()) {
            classpathDependencies.add(testDir);
        }
    }
}
 
Example #14
Source File: DeploymentExceptionObserver.java    From tomee with Apache License 2.0 5 votes vote down vote up
public void observes(@Observes final DeploymentException t) throws Exception {
    EXCEPTIONS.put(t.getClass(), t);

    Throwable current = t.getCause();
    while (current != null) {
        if (Exception.class.isInstance(current)) {
            PARENT_EXCEPTIONS.put(current.getClass(), Exception.class.cast(current));
        }
        if (current.getCause() != current) {
            current = current.getCause();
        }
    }

    throw t; // don't forget it even if it is an observer and not an interceptor
}
 
Example #15
Source File: WildFlySwarmContainer.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void undeploy(Archive<?> archive) throws DeploymentException {
    try {
        this.delegateContainer.stop();
    } catch (Exception e) {
        throw new DeploymentException("Unable to stop process", e);
    }
}
 
Example #16
Source File: UndertowAppServer.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private boolean isJaxrsApp(WebArchive archive) throws DeploymentException {
    try {
        return IOUtils.toString(archive.get("/WEB-INF/web.xml").getAsset().openStream(), Charset.forName("UTF-8"))
                .contains(Application.class.getName());
    } catch (IOException e) {
        throw new DeploymentException("Unable to read archive.", e);
    }
}
 
Example #17
Source File: ManagedSEDeployableContainer.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
private Properties getSystemProperties(final Archive<?> archive) throws DeploymentException {
    Node systemPropertiesNode = archive.get(ClassPath.SYSTEM_PROPERTIES_ARCHIVE_PATH);
    if (systemPropertiesNode != null) {
        try (InputStream in = systemPropertiesNode.getAsset().openStream()) {
            Properties systemProperties = new Properties();
            systemProperties.load(in);
            return systemProperties;
        } catch (IOException e) {
            throw new DeploymentException("Could not load system properties", e);
        }
    }
    return null;
}
 
Example #18
Source File: PiranhaServerDeployableContainer.java    From piranha with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void undeploy(Archive<?> archive) throws DeploymentException {
    if (microOuterDeployer != null) {
        LOGGER.info("Stopping Piranha Micro");
        microOuterDeployer.stop();
    }
}
 
Example #19
Source File: WildFlySwarmContainer.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void undeploy(Archive<?> archive) throws DeploymentException {
    try {
        this.delegateContainer.stop();
    } catch (Exception e) {
        throw new DeploymentException("Unable to stop process", e);
    }
}
 
Example #20
Source File: AuthServerTestEnricher.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public void deployProviders(@Observes(precedence = -1) AfterStart event) throws DeploymentException {
    if (isAuthServerRemote() && currentContainerName.contains("auth-server")) {
        this.testsuiteProvidersArchive = ShrinkWrap.create(ZipImporter.class, "testsuiteProviders.jar")
                .importFrom(Maven.configureResolverViaPlugin()
                    .resolve("org.keycloak.testsuite:integration-arquillian-testsuite-providers")
                    .withoutTransitivity()
                    .asSingleFile()
                ).as(JavaArchive.class)
                .addAsManifestResource("jboss-deployment-structure.xml");
                
        event.getDeployableContainer().deploy(testsuiteProvidersArchive);
    }
}
 
Example #21
Source File: EmbeddedTomEEContainer.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public void undeploy(final Archive<?> archive) throws DeploymentException {
    final String name = archive.getName();
    stopCdiContexts(name);
    if (configuration.isSingleDeploymentByArchiveName(name)) {
        return;
    }

    try {
        this.container.undeploy(name);
    } catch (final Exception e) {
        throw new DeploymentException("Unable to undeploy", e);
    } finally {
        this.classLoader.get().unregister(archive.getName());

        final File file = ARCHIVES.remove(archive);
        if (!configuration.isSingleDumpByArchiveName()) {
            final File folder = new File(file.getParentFile(), file.getName().substring(0, file.getName().length() - 4));
            if (folder.exists()) {
                Files.delete(folder);
            }
            Files.delete(file);
            final File parentFile = file.getParentFile();
            final File[] parentChildren = parentFile.listFiles();
            if (parentChildren == null || parentChildren.length == 0) {
                Files.delete(file.getParentFile());
            }
        }
    }
}
 
Example #22
Source File: ExceptionInjectionTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Deployment(testable = false)
@ShouldThrowException(javax.enterprise.inject.spi.DeploymentException.class)
public static WebArchive war() {
    return ShrinkWrap.create(WebArchive.class)
            .addAsWebInfResource(new StringAsset(Descriptors.create(BeansDescriptor.class)
                    .getOrCreateInterceptors()
                        .clazz("i.dont.exist.so.i.ll.make.the.deployment.fail")
                    .up()
                    .exportAsString()), ArchivePaths.create("beans.xml"));
}
 
Example #23
Source File: TargetController.java    From arquillian-container-chameleon with Apache License 2.0 5 votes vote down vote up
public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentException {
    return deployment(new Callable<ProtocolMetaData>() {
        @SuppressWarnings("unchecked")
        @Override
        public ProtocolMetaData call() throws Exception {
            return delegate.deploy(archive);
        }
    });
}
 
Example #24
Source File: TargetController.java    From arquillian-container-chameleon with Apache License 2.0 5 votes vote down vote up
public void undeploy(final Archive<?> archive) throws DeploymentException {
    deployment(new Callable<Void>() {
        @SuppressWarnings("unchecked")
        @Override
        public Void call() throws Exception {
            delegate.undeploy(archive);
            return null;
        }
    });
}
 
Example #25
Source File: TargetController.java    From arquillian-container-chameleon with Apache License 2.0 5 votes vote down vote up
public void deploy(final Descriptor descriptor) throws DeploymentException {
    deployment(new Callable<Void>() {
        @Override
        public Void call() throws Exception {
            delegate.deploy(descriptor);
            return null;
        }
    });
}
 
Example #26
Source File: TargetController.java    From arquillian-container-chameleon with Apache License 2.0 5 votes vote down vote up
public void undeploy(final Descriptor descriptor) throws DeploymentException {
    deployment(new Callable<Void>() {
        @Override
        public Void call() throws Exception {
            delegate.undeploy(descriptor);
            return null;
        }
    });
}
 
Example #27
Source File: ArquillianUtil.java    From tomee with Apache License 2.0 5 votes vote down vote up
public static void undeploy(final DeployableContainer<?> container, final Collection<Archive<?>> containerArchives) {
    if (containerArchives != null) {
        for (final Archive<?> a  : containerArchives) {
            try {
                container.undeploy(a);
            } catch (final DeploymentException e) {
                Logger.getLogger(container.getClass().getName()).log(Level.SEVERE, e.getMessage(), e);
            }
        }
    }
}
 
Example #28
Source File: TomEEContainer.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public void undeploy(final Archive<?> archive) throws DeploymentException {
    final String archiveName = archive.getName();
    if (configuration.isSingleDeploymentByArchiveName(archiveName)) {
        return;
    }

    final DeployedApp deployed = moduleIds.remove(archiveName);
    try {
        if (deployed == null) {
            LOGGER.warning(archiveName + " was not deployed");
            return;
        }
        doUndeploy(deployed);
    } catch (final Exception e) {
        throw new DeploymentException("Unable to undeploy " + archiveName, e);
    } finally {
        if (deployed != null && !configuration.isSingleDumpByArchiveName()) {
            LOGGER.info("cleaning " + deployed.file.getAbsolutePath());
            Files.delete(deployed.file); // "i" folder

            final File pathFile = new File(deployed.path);
            if (!deployed.path.equals(deployed.file.getAbsolutePath()) && pathFile.exists()) {
                LOGGER.info("cleaning " + pathFile);
                Files.delete(pathFile);
            }
            final File parentFile = deployed.file.getParentFile();
            final File[] parentChildren = parentFile.listFiles();
            if (parentChildren == null || parentChildren.length == 0) {
                Files.delete(deployed.file.getParentFile());
            }
        }
    }
}
 
Example #29
Source File: MeecrowaveContainer.java    From openwebbeans-meecrowave with Apache License 2.0 5 votes vote down vote up
@Override
public void undeploy(final Archive<?> archive) throws DeploymentException {
    this.container.undeploy(sanitizeName(archive));
    final File dump = toArchiveDump(archive);
    if (dump.isFile()) {
        IO.delete(dump);
    }
    final File unpacked = new File(dump.getParentFile(), dump.getName().replace(".war", ""));
    if (unpacked.isDirectory()) {
        IO.delete(unpacked);
    }
}
 
Example #30
Source File: OpenEJBDeployableContainer.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
public void deploy(final Descriptor descriptor) throws DeploymentException {
    throw new UnsupportedOperationException();
}