Search in sources :

Example 6 with Deployer

use of org.apache.openejb.assembler.Deployer in project tomee by apache.

the class TomEEContainer method lookupDeployerWithRetry.

protected Deployer lookupDeployerWithRetry(final int retry) throws NamingException {
    try {
        final Properties properties = new Properties();
        properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");
        properties.setProperty(Context.PROVIDER_URL, providerUrl());
        return (Deployer) new InitialContext(properties).lookup("openejb/DeployerBusinessRemote");
    } catch (final RuntimeException ne) {
        // surely "org.apache.openejb.client.ClientRuntimeException: Invalid response from server: -1"
        if (retry > 1) {
            try {
                // wait a bit before retrying
                Thread.sleep(200);
            } catch (final InterruptedException ignored) {
            // no-op
            }
            return lookupDeployerWithRetry(retry - 1);
        }
        if (Boolean.getBoolean("openejb.arquillian.debug") && retry >= 0) {
            try {
                // wait a lot to be sure that's not a timing issue
                Thread.sleep(10000);
            } catch (final InterruptedException ignored) {
            // no-op
            }
            return lookupDeployerWithRetry(-1);
        }
        throw ne;
    }
}
Also used : Properties(java.util.Properties) Deployer(org.apache.openejb.assembler.Deployer) InitialContext(javax.naming.InitialContext)

Example 7 with Deployer

use of org.apache.openejb.assembler.Deployer in project tomee by apache.

the class JMXDeployer method deployer.

private static Deployer deployer() throws NamingException {
    final Properties p = new Properties();
    p.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
    final ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(DeployerEjb.class.getClassLoader());
    try {
        return (Deployer) new InitialContext(p).lookup("openejb/DeployerBusinessRemote");
    } finally {
        Thread.currentThread().setContextClassLoader(oldCl);
    }
}
Also used : DeployerEjb(org.apache.openejb.assembler.DeployerEjb) Properties(java.util.Properties) LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) Deployer(org.apache.openejb.assembler.Deployer) InitialContext(javax.naming.InitialContext)

Example 8 with Deployer

use of org.apache.openejb.assembler.Deployer in project tomee by apache.

the class DeployMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    final Deployer deployer = (Deployer) lookup("openejb/DeployerBusinessRemote");
    if ((!"localhost".equals(tomeeHost) && !tomeeHost.startsWith("127.")) || useBinaries) {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final byte[] archive;
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(path);
            IO.copy(fis, baos);
            archive = baos.toByteArray();
        } catch (final Exception e) {
            throw new TomEEException(e.getMessage(), e);
        } finally {
            IO.close(fis);
            IO.close(baos);
        }
        try {
            final Properties prop = new Properties();
            prop.putAll(systemVariables);
            prop.put(DeployerEjb.OPENEJB_USE_BINARIES, "true");
            prop.put(DeployerEjb.OPENEJB_PATH_BINARIES, new File(path).getName());
            prop.put(DeployerEjb.OPENEJB_VALUE_BINARIES, archive);
            deployer.deploy(path, prop);
        } catch (final OpenEJBException e) {
            throw new TomEEException(e.getMessage(), e);
        }
    } else {
        try {
            if (systemVariables.isEmpty()) {
                deployer.deploy(path);
            } else {
                final Properties prop = new Properties();
                prop.putAll(systemVariables);
                deployer.deploy(path, prop);
            }
        } catch (final OpenEJBException e) {
            throw new TomEEException(e.getMessage(), e);
        }
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Properties(java.util.Properties) File(java.io.File) Deployer(org.apache.openejb.assembler.Deployer) FileInputStream(java.io.FileInputStream) OpenEJBException(org.apache.openejb.OpenEJBException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 9 with Deployer

use of org.apache.openejb.assembler.Deployer in project tomee by apache.

the class ListEjbMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    final Deployer deployer = (Deployer) lookup("openejb/DeployerBusinessRemote");
    final Collection<AppInfo> infos = deployer.getDeployedApps();
    final Lines lines = new Lines();
    lines.add(new Line("Name", "Class", "Interface Type", "Bean Type"));
    for (final AppInfo info : infos) {
        for (final EjbJarInfo ejbJar : info.ejbJars) {
            for (final EnterpriseBeanInfo bean : ejbJar.enterpriseBeans) {
                lines.add(new Line(bean.ejbDeploymentId, bean.ejbClass, getType(bean), componentType(bean)));
            }
        }
    }
    lines.print(new LogPrinterStream(getLog()));
}
Also used : Line(org.apache.openejb.table.Line) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) Deployer(org.apache.openejb.assembler.Deployer) AppInfo(org.apache.openejb.assembler.classic.AppInfo) Lines(org.apache.openejb.table.Lines)

Example 10 with Deployer

use of org.apache.openejb.assembler.Deployer in project tomee by apache.

the class UnDeployMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    final Deployer deployer = (Deployer) lookup("openejb/DeployerBusinessRemote");
    try {
        final Collection<AppInfo> apps = deployer.getDeployedApps();
        final Collection<String> paths = new ArrayList<String>(apps.size());
        for (final AppInfo info : apps) {
            paths.add(info.path);
        }
        if (paths.contains(path)) {
            // exact matching
            deployer.undeploy(path);
        } else {
            for (final String proposed : paths) {
                // exact matching + extension
                if (path.equals(proposed + ".war") || path.equals(proposed + ".ear") || path.equals(proposed + ".jar")) {
                    deployer.undeploy(proposed);
                    return;
                }
            }
            for (final String proposed : paths) {
                // just the app/folder name
                if (proposed.endsWith("/" + path) || proposed.endsWith("\\" + path)) {
                    deployer.undeploy(proposed);
                    return;
                }
            }
        }
    } catch (final OpenEJBException e) {
        throw new TomEEException(e.getMessage(), e);
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) ArrayList(java.util.ArrayList) Deployer(org.apache.openejb.assembler.Deployer) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Aggregations

Deployer (org.apache.openejb.assembler.Deployer)11 Properties (java.util.Properties)8 InitialContext (javax.naming.InitialContext)7 File (java.io.File)4 NamingException (javax.naming.NamingException)4 OpenEJBException (org.apache.openejb.OpenEJBException)3 AppInfo (org.apache.openejb.assembler.classic.AppInfo)3 IOException (java.io.IOException)2 ServiceUnavailableException (javax.naming.ServiceUnavailableException)2 CommandLine (org.apache.commons.cli.CommandLine)2 CommandLineParser (org.apache.commons.cli.CommandLineParser)2 Options (org.apache.commons.cli.Options)2 ParseException (org.apache.commons.cli.ParseException)2 PosixParser (org.apache.commons.cli.PosixParser)2 UndeployException (org.apache.openejb.UndeployException)2 SystemExitException (org.apache.openejb.cli.SystemExitException)2 RemoteInitialContextFactory (org.apache.openejb.client.RemoteInitialContextFactory)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1