use of org.apache.catalina.Container in project tomee by apache.
the class OpenEJBContextConfig method webConfig.
@Override
protected void webConfig() {
TomcatHelper.configureJarScanner(context);
// read the real config
super.webConfig();
if (IgnoredStandardContext.class.isInstance(context)) {
// no need of jsf
return;
}
if (AppFinder.findAppContextOrWeb(context.getLoader().getClassLoader(), AppFinder.WebBeansContextTransformer.INSTANCE) != null) {
final FilterDef asyncOwbFilter = new FilterDef();
asyncOwbFilter.setAsyncSupported("true");
asyncOwbFilter.setDescription("OpenEJB CDI Filter - to propagate @RequestScoped in async tasks");
asyncOwbFilter.setDisplayName("OpenEJB CDI");
asyncOwbFilter.setFilterClass(EEFilter.class.getName());
asyncOwbFilter.setFilterName(EEFilter.class.getName());
context.addFilterDef(asyncOwbFilter);
final FilterMap asyncOwbMapping = new FilterMap();
asyncOwbMapping.setFilterName(asyncOwbFilter.getFilterName());
asyncOwbMapping.addURLPattern("/*");
context.addFilterMap(asyncOwbMapping);
}
if ("true".equalsIgnoreCase(SystemInstance.get().getProperty("tomee.jsp-development", "false"))) {
for (final Container c : context.findChildren()) {
if (Wrapper.class.isInstance(c)) {
final Wrapper servlet = Wrapper.class.cast(c);
if ("org.apache.jasper.servlet.JspServlet".equals(servlet.getServletClass())) {
servlet.addInitParameter("development", "true");
}
}
}
}
final ClassLoader classLoader = context.getLoader().getClassLoader();
// add myfaces auto-initializer if mojarra is not present
try {
classLoader.loadClass("com.sun.faces.context.SessionMap");
return;
} catch (final Throwable ignored) {
// no-op
}
try {
final Class<?> myfacesInitializer = Class.forName(MYFACES_TOMEEM_CONTAINER_INITIALIZER, true, classLoader);
final ServletContainerInitializer instance = (ServletContainerInitializer) myfacesInitializer.newInstance();
context.addServletContainerInitializer(instance, getJsfClasses(context));
// cleanup listener
context.addApplicationListener(TOMEE_MYFACES_CONTEXT_LISTENER);
} catch (final Exception | NoClassDefFoundError ignored) {
// no-op
}
}
use of org.apache.catalina.Container in project tomee by apache.
the class TomcatLoader method processRunningApplications.
/**
* Process running web applications for ejb deployments.
*
* @param tomcatWebAppBuilder tomcat web app builder instance
* @param standardServer tomcat server instance
*/
private void processRunningApplications(final TomcatWebAppBuilder tomcatWebAppBuilder, final StandardServer standardServer) {
for (final org.apache.catalina.Service service : standardServer.findServices()) {
if (service.getContainer() instanceof Engine) {
final Engine engine = (Engine) service.getContainer();
for (final Container engineChild : engine.findChildren()) {
if (engineChild instanceof Host) {
final Host host = (Host) engineChild;
for (final Container hostChild : host.findChildren()) {
if (hostChild instanceof StandardContext) {
final StandardContext standardContext = (StandardContext) hostChild;
final int state = TomcatHelper.getContextState(standardContext);
if (state == 0) {
// context only initialized
tomcatWebAppBuilder.init(standardContext);
} else if (state == 1) {
// context already started
standardContext.addParameter("openejb.start.late", "true");
final ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(standardContext.getLoader().getClassLoader());
try {
tomcatWebAppBuilder.init(standardContext);
tomcatWebAppBuilder.beforeStart(standardContext);
tomcatWebAppBuilder.start(standardContext);
tomcatWebAppBuilder.afterStart(standardContext);
} finally {
Thread.currentThread().setContextClassLoader(oldCL);
}
standardContext.removeParameter("openejb.start.late");
}
}
}
}
}
}
}
}
use of org.apache.catalina.Container in project tomee by apache.
the class GlobalListenerSupport method serviceRemoved.
/**
* Service removed.
*
* @param service tomcat service
*/
private void serviceRemoved(final Service service) {
final Container container = service.getContainer();
if (container instanceof StandardEngine) {
final StandardEngine engine = (StandardEngine) container;
engineRemoved(engine);
}
}
use of org.apache.catalina.Container in project tomee by apache.
the class GlobalListenerSupport method hostRemoved.
/**
* Host is removed.
*
* @param host tomcat host
*/
private void hostRemoved(final StandardHost host) {
for (final Container child : host.findChildren()) {
if (child instanceof StandardContext) {
final StandardContext context = (StandardContext) child;
contextRemoved(context);
}
}
}
use of org.apache.catalina.Container in project Payara by payara.
the class WebContainer method loadWebModule.
/**
* Creates and configures a web module for each virtual server
* that the web module is hosted under.
* <p/>
* If no virtual servers have been specified, then the web module will
* not be loaded.
* @param wmInfo
* @param j2eeApplication
* @param deploymentProperties
* @return
*/
public List<Result<WebModule>> loadWebModule(WebModuleConfig wmInfo, String j2eeApplication, Properties deploymentProperties) {
List<Result<WebModule>> results = new ArrayList<Result<WebModule>>();
String vsIDs = wmInfo.getVirtualServers();
List<String> vsList = StringUtils.parseStringList(vsIDs, " ,");
if (vsList == null || vsList.isEmpty()) {
if (logger.isLoggable(Level.INFO)) {
logger.log(Level.INFO, LogFacade.WEB_MODULE_NOT_LOADED_NO_VIRTUAL_SERVERS, wmInfo.getName());
}
return results;
}
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, LogFacade.LOADING_WEB_MODULE, vsIDs);
}
List<String> nonProcessedVSList = new ArrayList<String>(vsList);
Container[] vsArray = getEngine().findChildren();
List<VirtualServer> vsToDeploy = new ArrayList<>(vsArray.length);
for (Container aVsArray : vsArray) {
if (aVsArray instanceof VirtualServer) {
VirtualServer vs = (VirtualServer) aVsArray;
boolean eqVS = vsList.contains(vs.getID());
if (eqVS) {
nonProcessedVSList.remove(vs.getID());
}
Set<String> matchedAliases = matchAlias(vsList, vs);
final boolean hasMatchedAlias = (matchedAliases.size() > 0);
if (hasMatchedAlias) {
nonProcessedVSList.removeAll(matchedAliases);
}
if (eqVS || hasMatchedAlias) {
vsToDeploy.add(vs);
}
}
}
final boolean moreThanOneVS = vsToDeploy.size() > 1;
for (VirtualServer vs : vsToDeploy) {
WebModule ctx = null;
ClassLoader appClassLoader = wmInfo.getAppClassLoader();
try {
if (moreThanOneVS) {
WebappClassLoader virtualServerClassLoader = new WebappClassLoader(appClassLoader, wmInfo.getDeploymentContext().getModuleMetaData(Application.class));
virtualServerClassLoader.start();
// for every virtual server, JSF and other extensions expect a separata class loader
wmInfo.setAppClassLoader(virtualServerClassLoader);
}
ctx = loadWebModule(vs, wmInfo, j2eeApplication, deploymentProperties);
results.add(new Result<>(ctx));
} catch (Throwable t) {
if (ctx != null) {
ctx.setAvailable(false);
}
results.add(new Result<>(t));
} finally {
if (moreThanOneVS) {
wmInfo.setAppClassLoader(appClassLoader);
}
}
}
if (nonProcessedVSList.size() > 0) {
StringBuilder sb = new StringBuilder();
boolean follow = false;
for (String alias : nonProcessedVSList) {
if (follow) {
sb.append(",");
}
sb.append(alias);
follow = true;
}
Object[] params = { wmInfo.getName(), sb.toString() };
logger.log(Level.SEVERE, LogFacade.WEB_MODULE_NOT_LOADED_TO_VS, params);
}
return results;
}
Aggregations