use of org.apache.openejb.assembler.classic.AppInfo 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);
}
}
use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.
the class TomEEContainer method doDeploy.
protected AppInfo doDeploy(final Archive<?> archive, final File file) throws OpenEJBException, NamingException, IOException {
AppInfo appInfo;
final Properties deployerProperties = getDeployerProperties();
if (deployerProperties == null) {
appInfo = deployer().deploy(file.getAbsolutePath());
} else {
final Properties props = new Properties();
props.putAll(deployerProperties);
if ("true".equalsIgnoreCase(deployerProperties.getProperty(DeployerEjb.OPENEJB_USE_BINARIES, "false"))) {
final byte[] slurpBinaries = IO.slurpBytes(file);
props.put(DeployerEjb.OPENEJB_VALUE_BINARIES, slurpBinaries);
props.put(DeployerEjb.OPENEJB_PATH_BINARIES, archive.getName());
}
appInfo = deployer().deploy(file.getAbsolutePath(), props);
}
return appInfo;
}
use of org.apache.openejb.assembler.classic.AppInfo 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);
}
}
use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.
the class TomcatWebAppBuilder method checkHost.
/**
* {@inheritDoc}
*/
@Override
public synchronized void checkHost(final StandardHost standardHost) {
if (noHostCheck) {
return;
}
if (standardHost.getAutoDeploy()) {
// Undeploy any modified application
for (final Iterator<Map.Entry<String, DeployedApplication>> iterator = deployedApps.entrySet().iterator(); iterator.hasNext(); ) {
final Map.Entry<String, DeployedApplication> entry = iterator.next();
final DeployedApplication deployedApplication = entry.getValue();
if (deployedApplication.isModified()) {
// TODO: for war use StandardContext.redeploy()
if (deployedApplication.appInfo != null) {
// can happen with badly formed config
try {
getAssembler().destroyApplication(deployedApplication.appInfo.path);
} catch (final Exception e) {
logger.error("Unable to application " + deployedApplication.appInfo.path, e);
}
} else {
logger.error("appinfo is null for " + deployedApplication);
}
iterator.remove();
}
}
// Deploy new applications
final File appBase = appBase(standardHost);
final File[] files = appBase.listFiles();
if (null != files) {
for (File file : files) {
if (file.getName().endsWith(".tmp")) {
// tomcat is uploading, see org.apache.catalina.manager.ManagerServlet.deploy(java.io.PrintWriter, org.apache.catalina.util.ContextName, java.lang.String, boolean, javax.servlet.http.HttpServletRequest, org.apache.tomcat.util.res.StringManager)
continue;
}
final String name = file.getName();
// ignore war files
if (name.toLowerCase().endsWith(".war") || isRoot(name) || name.equalsIgnoreCase("META-INF") || name.equalsIgnoreCase("WEB-INF")) {
continue;
}
// Simple fix for TOMEE-23
if (name.toLowerCase().equals(".ds_store")) {
continue;
}
// ignore unpacked web apps
if (file.isDirectory() && new File(file, "WEB-INF").exists()) {
continue;
}
// ignore unpacked apps where packed version is present (packed version is owner)
if (file.isDirectory() && (new File(file.getParent(), file.getName() + ".ear").exists() || new File(file.getParent(), file.getName() + ".war").exists() || new File(file.getParent(), file.getName() + ".rar").exists())) {
continue;
}
// ignore already deployed apps
if (isDeployed(file, standardHost)) {
continue;
}
final AppInfo appInfo;
try {
file = file.getCanonicalFile().getAbsoluteFile();
final AppModule appModule = deploymentLoader.load(file, null);
// Ignore any standalone web modules - this happens when the app is unpaked and doesn't have a WEB-INF dir
if (appModule.getDeploymentModule().size() == 1 && appModule.getWebModules().size() == 1) {
final WebModule webModule = appModule.getWebModules().iterator().next();
if (file.getAbsolutePath().equals(webModule.getJarLocation())) {
continue;
}
}
// tell web modules to deploy using this host
for (final WebModule webModule : appModule.getWebModules()) {
webModule.setHost(standardHost.getName());
}
appInfo = configurationFactory.configureApplication(appModule);
if (file.isFile() && file.getName().toLowerCase().endsWith(".ear")) {
// this is to prevent any WARs inside the EARs being unpacked in a directory where they'll then be deployed again
appInfo.properties.setProperty("tomcat.unpackWar", "false");
}
// if this is an unpacked dir, tomcat will pick it up as a webapp so undeploy it first
if (file.isDirectory()) {
final ContainerBase context = (ContainerBase) standardHost.findChild("/" + name);
if (context != null) {
try {
standardHost.removeChild(context);
} catch (final Throwable t) {
logger.warning("Error undeploying wep application from Tomcat " + name, t);
}
try {
context.destroy();
} catch (final Throwable t) {
logger.warning("Error destroying Tomcat web context " + name, t);
}
}
}
getAssembler().createApplication(appInfo);
deployedApps.put(file.getAbsolutePath(), new DeployedApplication(file, appInfo));
} catch (final Throwable e) {
logger.warning("Error deploying application " + file.getAbsolutePath(), e);
}
}
}
}
}
use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.
the class AsynchInRoleTest method testClassScopeAsynch.
@Test
public void testClassScopeAsynch() throws Exception {
// Build the application
final AppModule app = new AppModule(this.getClass().getClassLoader(), "testclassasynch");
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new SingletonBean(TestBeanA.class));
app.getEjbModules().add(new EjbModule(ejbJar));
final AppInfo appInfo = config.configureApplication(app);
assembler.createApplication(appInfo);
final Properties env = new Properties();
env.put(javax.naming.Context.SECURITY_PRINCIPAL, "jonathan");
env.put(javax.naming.Context.SECURITY_CREDENTIALS, "secret");
final InitialContext context = new InitialContext(env);
final TestBean test = (TestBean) context.lookup("TestBeanALocal");
test.testA(Thread.currentThread().getId());
Thread.sleep(1000L);
Assert.assertEquals("testA was never executed", "testA", test.getLastInvokeMethod());
final Future<String> future = test.testB(Thread.currentThread().getId());
Thread.sleep(1000L);
Assert.assertTrue("The task should be done", future.isDone());
Assert.assertEquals("testB was never executed", "testB", test.getLastInvokeMethod());
test.testC(Thread.currentThread().getId());
Assert.assertEquals("testC was never executed", "testC", test.getLastInvokeMethod());
test.testD(Thread.currentThread().getId());
Assert.assertEquals("testD was never executed", "testD", test.getLastInvokeMethod());
context.close();
}
Aggregations