Search in sources :

Example 1 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class ApplicationPropertiesTest method testOverrideAdd.

public void testOverrideAdd() throws Exception {
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    {
        // setup the system
        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    }
    {
        SystemInstance.get().getProperties().put("fooApp.color", "orange");
        final Map<String, String> map = new HashMap<String, String>();
        map.put("META-INF/ejb-jar.xml", "<ejb-jar id=\"fooModule\"/>");
        final File module = Archives.fileArchive(map, WidgetBean.class);
        final AppModule appModule = config.loadApplication(this.getClass().getClassLoader(), "fooApp", Arrays.asList(module));
        final AppInfo appInfo = config.configureApplication(appModule);
        assembler.createApplication(appInfo);
    }
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    assertContexts(containerSystem);
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) Assembler(org.apache.openejb.assembler.classic.Assembler) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 2 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class AltDDPrefixTest method testMultitplePrefixes.

public void testMultitplePrefixes() throws Exception {
    System.out.println("*** testMultitplePrefixes ***");
    final Assembler assmbler = new Assembler();
    SystemInstance.get().setProperty("openejb.altdd.prefix", "footest, test");
    DeploymentLoader.reloadAltDD();
    final ConfigurationFactory factory = new ConfigurationFactory();
    final URL resource = AltDDPrefixTest.class.getClassLoader().getResource("altddapp2");
    final File file = URLs.toFile(resource);
    final AppInfo appInfo = factory.configureApplication(file);
    assertNotNull(appInfo);
    assertEquals(1, appInfo.ejbJars.size());
    final EjbJarInfo ejbJar = appInfo.ejbJars.get(0);
    // was the footest.ejb-jar.xml picked up
    assertEquals("EjbJar.enterpriseBeans", 1, ejbJar.enterpriseBeans.size());
    assertEquals("EjbJar.interceptors.size()", 1, ejbJar.interceptors.size());
    // was the test.env-entries.properties picked up
    // 4 + ComponentName
    assertEquals("EjbJar.enterpriseBeans.get(0).jndiEnc.envEntries.size()", 5, ejbJar.enterpriseBeans.get(0).jndiEnc.envEntries.size());
}
Also used : Assembler(org.apache.openejb.assembler.classic.Assembler) File(java.io.File) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) URL(java.net.URL) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 3 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class AnnotationDeployerTest method badMainClassFormatTest.

@Test
public /**
     *  For https://issues.apache.org/jira/browse/OPENEJB-1063
     */
void badMainClassFormatTest() throws Exception {
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    final AppModule app = new AppModule(this.getClass().getClassLoader(), "test-app");
    final ClientModule clientModule = new ClientModule(null, app.getClassLoader(), app.getJarLocation(), null, null);
    // change "." --> "/" to check that main class is changed by the AnnotationDeployer
    final String mainClass = MyMainClass.class.getName().replaceAll("\\.", "/");
    clientModule.setMainClass(mainClass);
    app.getClientModules().add(clientModule);
    final AppInfo appInfo = config.configureApplication(app);
    assembler.createApplication(appInfo);
    final ClientInfo clientInfo = appInfo.clients.get(0);
    Assert.assertNotNull(clientInfo);
    Assert.assertEquals(MyMainClass.class.getName(), clientInfo.mainClass);
}
Also used : Assembler(org.apache.openejb.assembler.classic.Assembler) ClientInfo(org.apache.openejb.assembler.classic.ClientInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo) Test(org.junit.Test)

Example 4 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class ApplicationPropertiesTest method testOverrideUnprefixedVsPrefixedOpenEJB.

public void testOverrideUnprefixedVsPrefixedOpenEJB() throws Exception {
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    {
        // setup the system
        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    }
    {
        SystemInstance.get().getProperties().put("openejb.fooApp.color", "orange");
        SystemInstance.get().getProperties().put("fooApp.color", "green");
        final Map<String, String> map = new HashMap<String, String>();
        map.put("META-INF/ejb-jar.xml", "<ejb-jar id=\"fooModule\"/>");
        final File module = Archives.fileArchive(map, WidgetBean.class);
        final AppModule appModule = config.loadApplication(this.getClass().getClassLoader(), "fooApp", Arrays.asList(module));
        final AppInfo appInfo = config.configureApplication(appModule);
        assembler.createApplication(appInfo);
    }
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    assertContexts(containerSystem);
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) Assembler(org.apache.openejb.assembler.classic.Assembler) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 5 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class Deploy method main.

public static void main(final String... args) throws SystemExitException {
    final CommandLineParser parser = new PosixParser();
    // create the Options
    final Options options = new Options();
    options.addOption(option("v", "version", "cmd.deploy.opt.version"));
    options.addOption(option("h", "help", "cmd.deploy.opt.help"));
    options.addOption(option("o", "offline", "cmd.deploy.opt.offline"));
    options.addOption(option("s", "server-url", "url", "cmd.deploy.opt.server"));
    options.addOption(option("d", "debug", "cmd.deploy.opt.debug"));
    options.addOption(option("q", "quiet", "cmd.deploy.opt.quiet"));
    options.addOption(option("u", "undeploy", "cmd.deploy.opt.undeploy"));
    options.addOption(option(null, "dir", "cmd.deploy.opt.dir"));
    final CommandLine line;
    try {
        // parse the command line arguments
        line = parser.parse(options, args);
    } catch (final ParseException exp) {
        help(options);
        throw new SystemExitException(-1);
    }
    if (line.hasOption("help")) {
        help(options);
        return;
    } else if (line.hasOption("version")) {
        OpenEjbVersion.get().print(System.out);
        return;
    }
    if (line.getArgList().size() == 0) {
        System.out.println("Must specify an archive to deploy.");
        help(options);
        return;
    }
    // make sure that the modules given on the command line are accessible
    final List<?> modules = line.getArgList();
    for (final Object module : modules) {
        final String path = (String) module;
        final File file = new File(path);
        try {
            checkSource(file);
        } catch (final DeploymentTerminatedException e) {
            System.out.println(e.getMessage());
            // TODO: What is it for?
            throw new SystemExitException(-100);
        }
    }
    final boolean offline = line.hasOption("offline");
    final File apps;
    try {
        final String dir = line.getOptionValue("dir", "apps");
        apps = SystemInstance.get().getBase().getDirectory(dir);
    } catch (final IOException e) {
        throw new SystemExitException(-1);
    }
    if (!apps.exists()) {
        System.out.println("Directory does not exist: " + apps.getAbsolutePath());
    }
    Deployer deployer = null;
    if (!offline) {
        final Properties p = new Properties();
        p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");
        String serverUrl = line.getOptionValue("server-url", defaultServerUrl);
        if ("auto".equalsIgnoreCase(serverUrl.trim())) {
            try {
                final File sXml = new File(JavaSecurityManagers.getSystemProperty("openejb.base", "conf/server.xml"));
                if (sXml.exists()) {
                    final QuickServerXmlParser result = QuickServerXmlParser.parse(sXml);
                    serverUrl = "http://" + result.host() + ":" + result.http() + "/tomee/ejb";
                }
            } catch (final Throwable e) {
            // no-op
            }
        }
        p.put(Context.PROVIDER_URL, serverUrl);
        try {
            final InitialContext ctx = new InitialContext(p);
            deployer = (Deployer) ctx.lookup("openejb/DeployerBusinessRemote");
        } catch (final ServiceUnavailableException e) {
            System.out.println(e.getCause().getMessage());
            System.out.println(messages.format("cmd.deploy.serverOffline"));
            throw new SystemExitException(-1);
        } catch (final NamingException e) {
            System.out.println("openejb/DeployerBusinessRemote does not exist in server '" + serverUrl + "', check the server logs to ensure it exists and has not been removed.");
            throw new SystemExitException(-2);
        }
    }
    final boolean undeploy = line.hasOption("undeploy");
    // We increment the exit code once for every failed deploy
    int exitCode = 0;
    for (final Object obj : line.getArgList()) {
        final String path = (String) obj;
        final File file = new File(path);
        File destFile = new File(apps, file.getName());
        try {
            if (shouldUnpack(file)) {
                final File unpacked = unpackedLocation(file, apps);
                if (undeploy) {
                    undeploy(offline, unpacked, path, deployer);
                }
                destFile = unpack(file, unpacked);
            } else {
                if (undeploy) {
                    undeploy(offline, destFile, path, deployer);
                }
                checkDest(destFile, file);
                copyFile(file, destFile);
            }
            if (offline) {
                System.out.println(messages.format("cmd.deploy.offline", path, apps.getAbsolutePath()));
                continue;
            }
            final String location;
            try {
                location = destFile.getCanonicalPath();
            } catch (final IOException e) {
                throw new OpenEJBException(messages.format("cmd.deploy.fileNotFound", path));
            }
            final AppInfo appInfo = deployer.deploy(location);
            System.out.println(messages.format("cmd.deploy.successful", path, appInfo.path));
            if (line.hasOption("quiet")) {
                continue;
            }
            print(appInfo);
        } catch (final UndeployException e) {
            System.out.println(messages.format("cmd.undeploy.failed", path));
            e.printStackTrace(System.out);
            exitCode++;
        } catch (final DeploymentTerminatedException e) {
            System.out.println(e.getMessage());
            exitCode++;
        } catch (final ValidationFailedException e) {
            System.out.println(messages.format("cmd.deploy.validationFailed", path));
            int level = 2;
            if (line.hasOption("debug")) {
                level = 3;
            }
            final AppValidator appValidator = new AppValidator(level, false, true, false);
            appValidator.printResults(e);
            exitCode++;
            if (!delete(destFile)) {
                System.out.println(messages.format("cmd.deploy.cantDelete.deploy", destFile.getAbsolutePath()));
            }
        } catch (final Throwable e) {
            System.out.println(messages.format("cmd.deploy.failed", path));
            e.printStackTrace(System.out);
            exitCode++;
            if (!delete(destFile)) {
                System.out.println(messages.format("cmd.deploy.cantDelete.deploy", destFile.getAbsolutePath()));
            }
        }
    }
    if (exitCode != 0) {
        throw new SystemExitException(exitCode);
    }
}
Also used : Options(org.apache.commons.cli.Options) OpenEJBException(org.apache.openejb.OpenEJBException) PosixParser(org.apache.commons.cli.PosixParser) SystemExitException(org.apache.openejb.cli.SystemExitException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) Properties(java.util.Properties) NamingException(javax.naming.NamingException) CommandLineParser(org.apache.commons.cli.CommandLineParser) Deployer(org.apache.openejb.assembler.Deployer) IOException(java.io.IOException) InitialContext(javax.naming.InitialContext) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo) CommandLine(org.apache.commons.cli.CommandLine) ParseException(org.apache.commons.cli.ParseException) JarFile(java.util.jar.JarFile) File(java.io.File) UndeployException(org.apache.openejb.UndeployException)

Aggregations

AppInfo (org.apache.openejb.assembler.classic.AppInfo)106 File (java.io.File)50 Assembler (org.apache.openejb.assembler.classic.Assembler)46 Test (org.junit.Test)31 HashMap (java.util.HashMap)29 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)25 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)16 OpenEJBException (org.apache.openejb.OpenEJBException)15 AppModule (org.apache.openejb.config.AppModule)14 Map (java.util.Map)13 EjbJar (org.apache.openejb.jee.EjbJar)13 ContainerSystem (org.apache.openejb.spi.ContainerSystem)13 Properties (java.util.Properties)10 EjbModule (org.apache.openejb.config.EjbModule)10 Persistence (org.apache.openejb.jee.jpa.unit.Persistence)10 ArrayList (java.util.ArrayList)9 PersistenceUnit (org.apache.openejb.jee.jpa.unit.PersistenceUnit)9 IOException (java.io.IOException)8 URL (java.net.URL)8 InitialContext (javax.naming.InitialContext)8