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);
}
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());
}
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);
}
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);
}
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);
}
}
Aggregations