use of org.apache.openejb.config.WebModule in project tomee by apache.
the class MaxChildTest method app.
@Module
public AppModule app() {
final String jarLocation = "target/" + getClass().getSimpleName();
return new AppModule(Thread.currentThread().getContextClassLoader(), jarLocation, new Application(), true) {
{
getEjbModules().add(new EjbModule(new EjbJar("app"), new OpenejbJar() {
{
getPojoDeployment().add(new PojoDeployment() {
{
setClassName(SimpleContractImpl.class.getName());
getProperties().setProperty("cxf.jaxws.properties", "cxfLargeMsgSize");
}
});
}
}));
getWebModules().add(new WebModule(new WebApp().contextRoot("app").addServlet("ws", SimpleContractImpl.class.getName(), "/ws"), "app", Thread.currentThread().getContextClassLoader(), jarLocation, "app"));
getServices().add(new Service() {
{
setId("cxfLargeMsgSize");
setClassName(Properties.class.getName());
getProperties().setProperty("org.apache.cxf.stax.maxChildElements", "1");
}
});
}
};
}
use of org.apache.openejb.config.WebModule in project tomee by apache.
the class TomcatWebAppBuilder method loadWebModule.
/**
* Creates a new {@link WebModule} instance from given
* tomcat context instance.
*
* @param standardContext tomcat context instance
*/
private void loadWebModule(final AppModule appModule, final StandardContext standardContext) {
final List<WebModule> webModules = appModule.getWebModules();
if (webModules.isEmpty()) {
final File file = appModule.getFile();
logger.error("Failed to find a single module in: " + file);
return;
}
final WebModule webModule = webModules.get(0);
final WebApp webApp = webModule.getWebApp();
// create the web module
final String path = standardContext.getPath();
logger.debug("context path = " + path);
webModule.setHost(Contexts.getHostname(standardContext));
// Add all Tomcat env entries to context so they can be overriden by the env.properties file
final NamingResourcesImpl naming = standardContext.getNamingResources();
for (final ContextEnvironment environment : naming.findEnvironments()) {
EnvEntry envEntry = webApp.getEnvEntryMap().get(environment.getName());
if (envEntry == null) {
envEntry = new EnvEntry();
envEntry.setName(environment.getName());
webApp.getEnvEntry().add(envEntry);
}
envEntry.setEnvEntryValue(environment.getValue());
envEntry.setEnvEntryType(environment.getType());
}
// remove all jndi entries where there is a configured Tomcat resource or resource-link
for (final ContextResource resource : naming.findResources()) {
final String name = resource.getName();
removeRef(webApp, name);
}
for (final ContextResourceLink resourceLink : naming.findResourceLinks()) {
final String name = resourceLink.getName();
removeRef(webApp, name);
}
// remove all env entries from the web xml that are not overridable
for (final ContextEnvironment environment : naming.findEnvironments()) {
if (!environment.getOverride()) {
// overrides are not allowed
webApp.getEnvEntryMap().remove(environment.getName());
}
}
}
use of org.apache.openejb.config.WebModule in project tomee by apache.
the class AddContainerCdiBeansExtension method addCdiExtLib.
public void addCdiExtLib(@Observes final BeforeAppInfoBuilderEvent event) {
for (final EjbModule ejbModule : event.getAppModule().getEjbModules()) {
if (ejbModule.getModuleId().startsWith("ear-scoped-cdi-beans")) {
final Beans beans = ejbModule.getBeans();
if (CompositeBeans.class.isInstance(beans)) {
final CompositeBeans cb = CompositeBeans.class.cast(beans);
cb.getManagedClasses().put(EXT_LIB, new ArrayList<>(BEANS));
}
return;
}
}
// else a war
for (final WebModule webModule : event.getAppModule().getWebModules()) {
for (final EjbModule ejbModule : event.getAppModule().getEjbModules()) {
if (ejbModule.getModuleId().equals(webModule.getModuleId())) {
final Beans beans = ejbModule.getBeans();
if (CompositeBeans.class.isInstance(beans)) {
final CompositeBeans cb = CompositeBeans.class.cast(beans);
cb.getManagedClasses().put(EXT_LIB, new ArrayList<>(BEANS));
}
return;
}
}
}
}
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;
}
use of org.apache.openejb.config.WebModule 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