Search in sources :

Example 71 with ServletContextEvent

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);
}
Also used : DispatcherType(javax.servlet.DispatcherType) Meecrowave(org.apache.meecrowave.Meecrowave) ServletContextEvent(javax.servlet.ServletContextEvent) FilterRegistration(javax.servlet.FilterRegistration)

Example 72 with ServletContextEvent

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;
}
Also used : ServletContextListener(javax.servlet.ServletContextListener) ServletContextEvent(javax.servlet.ServletContextEvent)

Example 73 with ServletContextEvent

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;
}
Also used : ServletContextListener(javax.servlet.ServletContextListener) ServletContextEvent(javax.servlet.ServletContextEvent) SecurityConstraint(org.apache.catalina.deploy.SecurityConstraint)

Example 74 with ServletContextEvent

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();
}
Also used : EasyMockSupport(org.easymock.EasyMockSupport) ELResolver(javax.el.ELResolver) ExpressionFactory(javax.el.ExpressionFactory) JspApplicationContextImpl(org.apache.jasper.runtime.JspApplicationContextImpl) StandardContext(org.apache.catalina.core.StandardContext) BeanManager(javax.enterprise.inject.spi.BeanManager) ServletContextEvent(javax.servlet.ServletContextEvent) Test(org.junit.Test)

Aggregations

ServletContextEvent (javax.servlet.ServletContextEvent)74 Test (org.junit.Test)43 MockServletContext (org.springframework.mock.web.test.MockServletContext)21 ServletContextListener (javax.servlet.ServletContextListener)19 ServletContext (javax.servlet.ServletContext)18 Injector (com.google.inject.Injector)10 ContextLoaderListener (org.springframework.web.context.ContextLoaderListener)10 XmlWebApplicationContext (org.springframework.web.context.support.XmlWebApplicationContext)8 SimpleWebApplicationContext (org.springframework.web.servlet.SimpleWebApplicationContext)8 Test (org.testng.annotations.Test)8 BrokerService (org.apache.activemq.broker.BrokerService)7 IOException (java.io.IOException)6 Properties (java.util.Properties)6 TestBean (org.springframework.tests.sample.beans.TestBean)6 ArrayList (java.util.ArrayList)5 SystemPropertiesHelper.overrideSystemProperties (org.eclipse.che.commons.test.SystemPropertiesHelper.overrideSystemProperties)5 File (java.io.File)4 MalformedURLException (java.net.MalformedURLException)3 HashMap (java.util.HashMap)3 ServletException (javax.servlet.ServletException)3