Search in sources :

Example 6 with ProtocolMetaData

use of org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData in project tomee by apache.

the class TomEEContainer method deploy.

@Override
public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentException {
    try {
        final Dump dump = dumpFile(archive);
        final File file = dump.getFile();
        final String fileName = file.getName();
        if (dump.isCreated() && (fileName.endsWith(".war") || fileName.endsWith(".ear"))) {
            // extracted folder, TODO: openejb work dir is ignored here
            Files.deleteOnExit(new File(file.getParentFile(), fileName.substring(0, fileName.length() - 4)));
        }
        final AppInfo appInfo;
        final String archiveName = archive.getName();
        try {
            if (dump.isCreated() || !configuration.isSingleDeploymentByArchiveName(archiveName)) {
                appInfo = doDeploy(archive, file);
                if (appInfo != null) {
                    moduleIds.put(archiveName, new DeployedApp(appInfo.path, file));
                    // "i" folder
                    Files.deleteOnExit(file);
                }
            } else {
                final String path = moduleIds.get(archiveName).path;
                AppInfo selected = null;
                for (final AppInfo info : getDeployedApps()) {
                    if (path.equals(info.path)) {
                        selected = info;
                        break;
                    }
                }
                appInfo = selected;
            }
            if (appInfo == null) {
                LOGGER.severe("appInfo was not found for " + file.getPath() + ", available are: " + apps());
                throw new OpenEJBException("can't get appInfo");
            }
        } catch (final OpenEJBException re) {
            // clean up in undeploy needs it
            moduleIds.put(archiveName, new DeployedApp(file.getPath(), file));
            throw re;
        }
        if (options.get("tomee.appinfo.output", false)) {
            Info.marshal(appInfo);
        }
        final HTTPContext httpContext = new HTTPContext(configuration.getHost(), configuration.getHttpPort());
        addArquillianServlet(archive, appInfo, archiveName, httpContext);
        addServlets(httpContext, appInfo);
        return new ProtocolMetaData().addContext(httpContext);
    } catch (final Exception e) {
        throw new DeploymentException("Unable to deploy", e);
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) HTTPContext(org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData) File(java.io.File) NamingException(javax.naming.NamingException) UndeployException(org.apache.openejb.UndeployException) LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) OpenEJBException(org.apache.openejb.OpenEJBException) IOException(java.io.IOException) NoSuchApplicationException(org.apache.openejb.NoSuchApplicationException) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 7 with ProtocolMetaData

use of org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData in project tomee by apache.

the class EmbeddedTomEEContainer method deploy.

@Override
public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentException {
    try {
        /* don't do it since it should be configurable
            final File tempDir = Files.createTempDir();
            final File file = new File(tempDir, name);
            */
        final String name = archive.getName();
        final Dump dump = this.dumpFile(archive);
        final File file = dump.getFile();
        if (dump.isCreated() || !configuration.isSingleDeploymentByArchiveName(name)) {
            ARCHIVES.put(archive, file);
            final Thread current = Thread.currentThread();
            final ClassLoader loader = current.getContextClassLoader();
            // multiple deployments, don't leak a loader
            current.setContextClassLoader(ParentClassLoaderFinder.Helper.get());
            try {
                this.container.deploy(name, file);
            } finally {
                current.setContextClassLoader(loader);
            }
        }
        final AppInfo info = this.container.getInfo(name);
        final String context = this.getArchiveNameWithoutExtension(archive);
        final HTTPContext httpContext = new HTTPContext(this.configuration.getHost(), this.configuration.getHttpPort());
        httpContext.add(new Servlet("ArquillianServletRunner", "/" + context));
        this.addServlets(httpContext, info);
        // ensure tests can use request/session scopes even if we don't have a request
        startCdiContexts(name);
        TestObserver.ClassLoaders classLoaders = this.classLoader.get();
        if (classLoaders == null) {
            classLoaders = new TestObserver.ClassLoaders();
            this.classLoader.set(classLoaders);
        }
        classLoaders.register(archive.getName(), SystemInstance.get().getComponent(ContainerSystem.class).getAppContext(info.appId).getClassLoader());
        return new ProtocolMetaData().addContext(httpContext);
    } catch (final Exception e) {
        throw new DeploymentException("Unable to deploy", e);
    }
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) HTTPContext(org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext) TestObserver(org.apache.openejb.arquillian.common.TestObserver) LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) AppInfo(org.apache.openejb.assembler.classic.AppInfo) Servlet(org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData) File(java.io.File)

Example 8 with ProtocolMetaData

use of org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData in project camel by apache.

the class ManagedSEDeployableContainer method deploy.

@Override
public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentException {
    LOGGER.info("Deploying " + archive.getName());
    // First of all clear the list of previously materialized deployments - otherwise the class path would grow indefinitely
    materializedFiles.clear();
    // Create a new classpath
    classpathDependencies.clear();
    if (ClassPath.isRepresentedBy(archive)) {
        for (Node child : archive.get(ClassPath.ROOT_ARCHIVE_PATH).getChildren()) {
            Asset asset = child.getAsset();
            if (asset instanceof ArchiveAsset) {
                Archive<?> assetArchive = ((ArchiveAsset) asset).getArchive();
                if (ClassPathDirectory.isRepresentedBy(assetArchive)) {
                    materializeDirectory(assetArchive);
                } else {
                    materializeArchive(assetArchive);
                }
            }
        }
    } else {
        materializeArchive(archive);
    }
    Properties systemProperties = getSystemProperties(archive);
    readJarFilesFromDirectory();
    addTestResourcesDirectory(systemProperties);
    List<String> processCommand = buildProcessCommand(systemProperties);
    logExecutedCommand(processCommand);
    // Launch the process
    final ProcessBuilder processBuilder = new ProcessBuilder(processCommand);
    String path = systemProperties.getProperty("container.user.dir");
    if (path != null) {
        processBuilder.directory(new File(path));
    }
    processBuilder.environment().put("JAVA_HOME", new File(System.getProperty(SYSPROP_KEY_JAVA_HOME)).getAbsolutePath());
    processBuilder.redirectErrorStream(true);
    processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
    processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
    try {
        process = processBuilder.start();
    } catch (final IOException e) {
        throw new DeploymentException("Could not start process", e);
    }
    int finalWaitTime = debugModeEnabled ? (3 * waitTime) : waitTime;
    // Wait for socket connection
    if (!isServerStarted(host, port, finalWaitTime)) {
        throw new DeploymentException("Child JVM process failed to start within " + finalWaitTime + " seconds.");
    }
    if (!isJMXTestRunnerMBeanRegistered(host, port, finalWaitTime)) {
        throw new DeploymentException("JMXTestRunnerMBean not registered within " + finalWaitTime + " seconds.");
    }
    ProtocolMetaData protocolMetaData = new ProtocolMetaData();
    protocolMetaData.addContext(new JMXContext(host, port));
    return protocolMetaData;
}
Also used : Node(org.jboss.shrinkwrap.api.Node) ArchiveAsset(org.jboss.shrinkwrap.api.asset.ArchiveAsset) IOException(java.io.IOException) Properties(java.util.Properties) ClassAsset(org.jboss.shrinkwrap.api.asset.ClassAsset) Asset(org.jboss.shrinkwrap.api.asset.Asset) ArchiveAsset(org.jboss.shrinkwrap.api.asset.ArchiveAsset) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData) File(java.io.File) JMXContext(org.jboss.arquillian.container.spi.client.protocol.metadata.JMXContext)

Example 9 with ProtocolMetaData

use of org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData in project meecrowave by apache.

the class MeecrowaveContainer method deploy.

@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)));
}
Also used : ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) Servlet(org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet) HTTPContext(org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData) File(java.io.File)

Example 10 with ProtocolMetaData

use of org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData in project Payara by payara.

the class CommonPayaraManager method deploy.

public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
    if (archive == null) {
        throw new IllegalArgumentException("archive must not be null");
    }
    final String archiveName = archive.getName();
    final ProtocolMetaData protocolMetaData = new ProtocolMetaData();
    try {
        InputStream deployment = archive.as(ZipExporter.class).exportAsInputStream();
        // Build up the POST form to send to Payara
        final FormDataMultiPart form = new FormDataMultiPart();
        form.bodyPart(new StreamDataBodyPart("id", deployment, archiveName));
        deploymentName = createDeploymentName(archiveName);
        addDeployFormFields(deploymentName, form);
        // Do Deploy the application on the remote Payara
        HTTPContext httpContext = payaraClient.doDeploy(deploymentName, form);
        protocolMetaData.addContext(httpContext);
    } catch (PayaraClientException e) {
        throw new DeploymentException("Could not deploy " + archiveName, e);
    }
    return protocolMetaData;
}
Also used : StreamDataBodyPart(org.glassfish.jersey.media.multipart.file.StreamDataBodyPart) InputStream(java.io.InputStream) ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) HTTPContext(org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData) PayaraClientException(fish.payara.arquillian.container.payara.clientutils.PayaraClientException)

Aggregations

ProtocolMetaData (org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData)10 HTTPContext (org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext)9 DeploymentException (org.jboss.arquillian.container.spi.client.container.DeploymentException)7 File (java.io.File)5 IOException (java.io.IOException)4 NamingException (javax.naming.NamingException)4 LifecycleException (org.jboss.arquillian.container.spi.client.container.LifecycleException)4 Servlet (org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet)4 ZipExporter (org.jboss.shrinkwrap.api.exporter.ZipExporter)3 Properties (java.util.Properties)2 TestObserver (org.apache.openejb.arquillian.common.TestObserver)2 AppInfo (org.apache.openejb.assembler.classic.AppInfo)2 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)2 PayaraVersion (fish.payara.arquillian.container.payara.PayaraVersion)1 PayaraClientException (fish.payara.arquillian.container.payara.clientutils.PayaraClientException)1 BufferingConsumer (fish.payara.arquillian.container.payara.process.BufferingConsumer)1 ConsoleReader (fish.payara.arquillian.container.payara.process.ConsoleReader)1 InputStream (java.io.InputStream)1 Path (java.nio.file.Path)1 SecureRandom (java.security.SecureRandom)1