use of org.apache.openejb.config.WebModule 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.config.WebModule in project tomee by apache.
the class CheckDescriptorLocation method validate.
@Override
public void validate(final AppModule appModule) {
final List<String> validated = new ArrayList<String>();
for (final WebModule webModule : safe(appModule.getWebModules())) {
validated.add(webModule.getModuleId());
validateWebModule(webModule);
}
for (final EjbModule ejbModule : safe(appModule.getEjbModules())) {
// without this check, CheckDescriptorLocationTest#testWarWithDescriptorInRoot() would fail
if (!validated.contains(ejbModule.getModuleId())) {
validateEjbModule(ejbModule);
}
}
}
use of org.apache.openejb.config.WebModule in project tomee by apache.
the class SimplePojoTest method war.
@Module
@Classes(cdi = true, value = { MyFirstRestClass.class })
public WebModule war() {
final WebModule webModule = new WebModule(new WebApp(), "/foo", Thread.currentThread().getContextClassLoader(), "", "foo");
webModule.getRestClasses().add(MyFirstRestClass.class.getName());
return webModule;
}
Aggregations