use of org.apache.openejb.config.DeploymentModule in project tomee by apache.
the class DeployerEjb method deploy.
@Override
public AppInfo deploy(final String inLocation, Properties properties) throws OpenEJBException {
String rawLocation = inLocation;
if (rawLocation == null && properties == null) {
throw new NullPointerException("location and properties are null");
}
if (rawLocation == null) {
rawLocation = properties.getProperty(FILENAME);
}
if (properties == null) {
properties = new Properties();
}
AppModule appModule = null;
final File file;
if ("true".equalsIgnoreCase(properties.getProperty(OPENEJB_USE_BINARIES, "false"))) {
file = copyBinaries(properties);
} else {
file = new File(realLocation(rawLocation).iterator().next());
}
final boolean autoDeploy = Boolean.parseBoolean(properties.getProperty(OPENEJB_APP_AUTODEPLOY, "false"));
final String host = properties.getProperty(OPENEJB_DEPLOYER_HOST, null);
if (WebAppDeployer.Helper.isWebApp(file) && !oldWarDeployer) {
AUTO_DEPLOY.set(autoDeploy);
try {
final AppInfo appInfo = SystemInstance.get().getComponent(WebAppDeployer.class).deploy(host, contextRoot(properties, file.getAbsolutePath()), file);
if (appInfo != null) {
saveIfNeeded(properties, file, appInfo);
return appInfo;
}
throw new OpenEJBException("can't deploy " + file.getAbsolutePath());
} finally {
AUTO_DEPLOY.remove();
}
}
AppInfo appInfo = null;
try {
appModule = deploymentLoader.load(file, null);
// Add any alternate deployment descriptors to the modules
final Map<String, DeploymentModule> modules = new TreeMap<>();
for (final DeploymentModule module : appModule.getEjbModules()) {
modules.put(module.getModuleId(), module);
}
for (final DeploymentModule module : appModule.getClientModules()) {
modules.put(module.getModuleId(), module);
}
for (final WebModule module : appModule.getWebModules()) {
final String contextRoot = contextRoot(properties, module.getJarLocation());
if (contextRoot != null) {
module.setContextRoot(contextRoot);
module.setHost(host);
}
modules.put(module.getModuleId(), module);
}
for (final DeploymentModule module : appModule.getConnectorModules()) {
modules.put(module.getModuleId(), module);
}
for (final Map.Entry<Object, Object> entry : properties.entrySet()) {
String name = (String) entry.getKey();
if (name.startsWith(ALT_DD + "/")) {
name = name.substring(ALT_DD.length() + 1);
final DeploymentModule module;
final int slash = name.indexOf('/');
if (slash > 0) {
final String moduleId = name.substring(0, slash);
name = name.substring(slash + 1);
module = modules.get(moduleId);
} else {
module = appModule;
}
if (module != null) {
final String value = (String) entry.getValue();
final File dd = new File(value);
if (dd.canRead()) {
module.getAltDDs().put(name, dd.toURI().toURL());
} else {
module.getAltDDs().put(name, value);
}
}
}
}
appInfo = configurationFactory.configureApplication(appModule);
appInfo.autoDeploy = autoDeploy;
if (properties != null && properties.containsKey(OPENEJB_DEPLOYER_FORCED_APP_ID_PROP)) {
appInfo.appId = properties.getProperty(OPENEJB_DEPLOYER_FORCED_APP_ID_PROP);
}
if (!appInfo.webApps.isEmpty()) {
appInfo.properties.setProperty("tomcat.unpackWar", "false");
}
assembler.createApplication(appInfo);
saveIfNeeded(properties, file, appInfo);
return appInfo;
} catch (final Throwable e) {
// destroy the class loader for the failed application
if (appModule != null) {
ClassLoaderUtil.destroyClassLoader(appModule.getJarLocation());
}
if (null != appInfo) {
ClassLoaderUtil.destroyClassLoader(appInfo.appId, appInfo.path);
}
LOGGER.error("Can't deploy " + inLocation, e);
if (e instanceof ValidationException) {
throw (ValidationException) e;
}
final Throwable ex;
final DeploymentExceptionManager dem = SystemInstance.get().getComponent(DeploymentExceptionManager.class);
if (dem != null) {
if (dem.hasDeploymentFailed()) {
ex = dem.getLastException();
} else {
ex = e;
}
if (appInfo != null) {
dem.clearLastException(appInfo);
}
} else {
ex = e;
}
if (ex instanceof OpenEJBException) {
if (ex.getCause() instanceof ValidationException) {
throw (ValidationException) ex.getCause();
}
throw (OpenEJBException) ex;
}
throw new OpenEJBException(ex);
}
}
Aggregations