use of javax.servlet.ServletContextEvent in project meecrowave by apache.
the class OWBAutoSetup method onStartup.
@Override
public void onStartup(final Set<Class<?>> c, final ServletContext ctx) throws ServletException {
final Meecrowave.Builder builder = Meecrowave.Builder.class.cast(ctx.getAttribute("meecrowave.configuration"));
final Meecrowave instance = Meecrowave.class.cast(ctx.getAttribute("meecrowave.instance"));
if (builder.isCdiConversation()) {
final FilterRegistration.Dynamic filter = ctx.addFilter("owb-conversation", WebConversationFilter.class);
filter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*");
}
// eager boot to let injections work in listeners
final EagerBootListener bootListener = new EagerBootListener(instance);
bootListener.doContextInitialized(new ServletContextEvent(ctx));
ctx.addListener(bootListener);
}
use of javax.servlet.ServletContextEvent in project Payara by payara.
the class StandardContext method contextListenerStart.
/**
* Notifies all ServletContextListeners at their contextInitialized
* method.
*/
protected void contextListenerStart() {
ServletContextEvent event = new ServletContextEvent(getServletContext());
for (ServletContextListener listener : contextListeners) {
if (listener instanceof RestrictedServletContextListener) {
listener = ((RestrictedServletContextListener) listener).getNestedListener();
context.setRestricted(true);
}
try {
fireContainerEvent(ContainerEvent.BEFORE_CONTEXT_INITIALIZED, listener);
listener.contextInitialized(event);
} finally {
context.setRestricted(false);
fireContainerEvent(ContainerEvent.AFTER_CONTEXT_INITIALIZED, listener);
}
}
/*
* Make sure there are no preliminary servlet or filter
* registrations left after all listeners have been notified
*/
Collection<ServletRegistrationImpl> servletRegistrations = servletRegisMap.values();
for (ServletRegistrationImpl regis : servletRegistrations) {
if (null == regis.getClassName() && null == regis.getJspFile()) {
String msg = MessageFormat.format(rb.getString(LogFacade.SERVLET_WITHOUT_ANY_CLASS_OR_JSP), regis.getName());
throw new IllegalStateException(msg);
}
}
Collection<FilterRegistrationImpl> filterRegistrations = filterRegisMap.values();
for (FilterRegistrationImpl regis : filterRegistrations) {
if (null == regis.getClassName()) {
String msg = MessageFormat.format(rb.getString(LogFacade.FILTER_WITHOUT_ANY_CLASS), regis.getName());
throw new IllegalStateException(msg);
}
}
isContextInitializedCalled = true;
}
use of javax.servlet.ServletContextEvent in project Payara by payara.
the class StandardContext method contextListenerStop.
/**
* Notifies all ServletContextListeners at their contextDestroyed
* method.
*
* @return <code>true</code> if the event was processed successfully,
* <code>false</code> otherwise.
*/
private boolean contextListenerStop() {
boolean ok = true;
if (contextListeners.isEmpty()) {
return ok;
}
ServletContextEvent event = new ServletContextEvent(getServletContext());
int len = contextListeners.size();
for (int i = 0; i < len; i++) {
// Invoke in reverse order of declaration
ServletContextListener listener = contextListeners.get((len - 1) - i);
if (listener instanceof RestrictedServletContextListener) {
listener = ((RestrictedServletContextListener) listener).getNestedListener();
context.setRestricted(true);
}
try {
fireContainerEvent(ContainerEvent.BEFORE_CONTEXT_DESTROYED, listener);
listener.contextDestroyed(event);
fireContainerEvent(ContainerEvent.AFTER_CONTEXT_DESTROYED, listener);
} catch (Throwable t) {
context.setRestricted(false);
fireContainerEvent(ContainerEvent.AFTER_CONTEXT_DESTROYED, listener);
String msg = MessageFormat.format(rb.getString(LogFacade.LISTENER_STOP_EXCEPTION), listener.getClass().getName());
getServletContext().log(msg, t);
ok = false;
}
}
contextListeners.clear();
return ok;
}
use of javax.servlet.ServletContextEvent in project Payara by payara.
the class WeldContextListenerTest method testcontextInitialized.
@Test
public void testcontextInitialized() throws Exception {
EasyMockSupport mockSupport = new EasyMockSupport();
ELResolver elResolver = mockSupport.createMock(ELResolver.class);
ExpressionFactory expressionFactory = mockSupport.createMock(ExpressionFactory.class);
StandardContext servletContext = new StandardContext();
servletContext.getServletContext();
ServletContextEvent servletContextEvent = mockSupport.createMock(ServletContextEvent.class);
BeanManager beanManager = mockSupport.createMock(BeanManager.class);
JspApplicationContextImpl jspApplicationContext = new JspApplicationContextImpl(servletContext);
expect(beanManager.getELResolver()).andReturn(elResolver);
expect(beanManager.wrapExpressionFactory(isA(ExpressionFactory.class))).andReturn(expressionFactory);
mockSupport.replayAll();
WeldContextListener weldContextListener = getWeldContextListener(beanManager, jspApplicationContext);
weldContextListener.contextInitialized(servletContextEvent);
assertSame(expressionFactory, jspApplicationContext.getExpressionFactory());
validateJspApplicationContext(jspApplicationContext, elResolver);
mockSupport.verifyAll();
mockSupport.resetAll();
}
Aggregations