use of org.apache.tomcat.InstanceManager in project tomcat by apache.
the class OpenWebBeansContextLifecycleListener method lifecycleEvent.
@Override
public void lifecycleEvent(LifecycleEvent event) {
if (event.getSource() instanceof Context) {
Context context = (Context) event.getSource();
if (event.getType().equals(Lifecycle.CONFIGURE_START_EVENT)) {
if (getStartWithoutBeansXml() || context.getResources().getResource("/WEB-INF/beans.xml").exists() || context.getResources().getResource("/WEB-INF/classes/META-INF/beans.xml").exists()) {
// Registering ELResolver with JSP container
System.setProperty("org.apache.webbeans.application.jsp", "true");
// Add Listeners
String[] oldListeners = context.findApplicationListeners();
LinkedList<String> listeners = new LinkedList<>();
listeners.addFirst(WebBeansConfigurationListener.class.getName());
for (String listener : oldListeners) {
listeners.add(listener);
context.removeApplicationListener(listener);
}
for (String listener : listeners) {
context.addApplicationListener(listener);
}
Pipeline pipeline = context.getPipeline();
// Add to the corresponding pipeline to get a notification once configure is done
if (pipeline instanceof Lifecycle) {
boolean contextLifecycleListenerFound = false;
for (LifecycleListener listener : ((Lifecycle) pipeline).findLifecycleListeners()) {
if (listener instanceof OpenWebBeansContextLifecycleListener) {
contextLifecycleListenerFound = true;
}
}
if (!contextLifecycleListenerFound) {
((Lifecycle) pipeline).addLifecycleListener(this);
}
}
if (getAddSecurityValve()) {
// Add security valve
boolean securityValveFound = false;
for (Valve valve : pipeline.getValves()) {
if (valve instanceof OpenWebBeansSecurityValve) {
securityValveFound = true;
}
}
if (!securityValveFound) {
pipeline.addValve(new OpenWebBeansSecurityValve());
}
}
}
}
} else if (event.getSource() instanceof Pipeline && event.getType().equals(Lifecycle.START_EVENT)) {
// This notification occurs once the configuration is fully done, including naming resources setup
// Otherwise, the instance manager is not ready for creation
Pipeline pipeline = (Pipeline) event.getSource();
if (pipeline.getContainer() instanceof Context) {
Context context = (Context) pipeline.getContainer();
if (!(context.getInstanceManager() instanceof OpenWebBeansInstanceManager)) {
InstanceManager processor = context.getInstanceManager();
if (processor == null) {
processor = context.createInstanceManager();
}
InstanceManager custom = new OpenWebBeansInstanceManager(context.getLoader().getClassLoader(), processor);
context.setInstanceManager(custom);
}
}
}
}
Aggregations