Search in sources :

Example 21 with ServletRequestEvent

use of javax.servlet.ServletRequestEvent in project Payara by payara.

the class StandardContext method fireRequestInitializedEvent.

@Override
public void fireRequestInitializedEvent(ServletRequest request) {
    List<EventListener> listeners = getApplicationEventListeners();
    ServletRequestEvent event = null;
    if (!listeners.isEmpty()) {
        event = new ServletRequestEvent(getServletContext(), request);
        // create pre-service event
        Iterator<EventListener> iter = listeners.iterator();
        while (iter.hasNext()) {
            EventListener eventListener = iter.next();
            if (!(eventListener instanceof ServletRequestListener)) {
                continue;
            }
            ServletRequestListener listener = (ServletRequestListener) eventListener;
            // START SJSAS 6329662
            fireContainerEvent(ContainerEvent.BEFORE_REQUEST_INITIALIZED, listener);
            // END SJSAS 6329662
            try {
                listener.requestInitialized(event);
            } catch (Throwable t) {
                String msg = MessageFormat.format(rb.getString(LogFacade.REQUEST_INIT_EXCEPTION), listener.getClass().getName());
                log.log(Level.WARNING, msg, t);
                request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, t);
            // START SJSAS 6329662
            } finally {
                fireContainerEvent(ContainerEvent.AFTER_REQUEST_INITIALIZED, listener);
            // END SJSAS 6329662
            }
        }
    }
}
Also used : ServletRequestListener(javax.servlet.ServletRequestListener) ServletRequestEvent(javax.servlet.ServletRequestEvent) EventListener(java.util.EventListener)

Example 22 with ServletRequestEvent

use of javax.servlet.ServletRequestEvent in project Payara by payara.

the class StandardContext method fireRequestDestroyedEvent.

@Override
public void fireRequestDestroyedEvent(ServletRequest request) {
    List<EventListener> listeners = getApplicationEventListeners();
    if (!listeners.isEmpty()) {
        // create post-service event
        ServletRequestEvent event = new ServletRequestEvent(getServletContext(), request);
        int len = listeners.size();
        for (int i = 0; i < len; i++) {
            EventListener eventListener = listeners.get((len - 1) - i);
            if (!(eventListener instanceof ServletRequestListener)) {
                continue;
            }
            ServletRequestListener listener = (ServletRequestListener) eventListener;
            // START SJSAS 6329662
            fireContainerEvent(ContainerEvent.BEFORE_REQUEST_DESTROYED, listener);
            // END SJSAS 6329662
            try {
                listener.requestDestroyed(event);
            } catch (Throwable t) {
                String msg = MessageFormat.format(rb.getString(LogFacade.REQUEST_DESTROY_EXCEPTION), listener.getClass().getName());
                log.log(Level.WARNING, msg, t);
                request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, t);
            // START SJSAS 6329662
            } finally {
                fireContainerEvent(ContainerEvent.AFTER_REQUEST_DESTROYED, listener);
            // END SJSAS 6329662
            }
        }
    }
}
Also used : ServletRequestListener(javax.servlet.ServletRequestListener) ServletRequestEvent(javax.servlet.ServletRequestEvent) EventListener(java.util.EventListener) SecurityConstraint(org.apache.catalina.deploy.SecurityConstraint)

Aggregations

ServletRequestEvent (javax.servlet.ServletRequestEvent)22 ServletRequestListener (javax.servlet.ServletRequestListener)11 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 Test (org.junit.Test)7 ServletException (javax.servlet.ServletException)5 IOException (java.io.IOException)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 HttpSession (javax.servlet.http.HttpSession)3 EventListener (java.util.EventListener)2 ServletRequest (javax.servlet.ServletRequest)2 HttpSessionBindingEvent (javax.servlet.http.HttpSessionBindingEvent)2 ServletsMockitoUtil.createHttpSessionBindingEvent (jodd.petite.ServletsMockitoUtil.createHttpSessionBindingEvent)2 ServletsMockitoUtil.createServletRequestEvent (jodd.petite.ServletsMockitoUtil.createServletRequestEvent)2 Ses (jodd.petite.tst.Ses)2 RequestContextListener (jodd.servlet.RequestContextListener)2 SecurityConstraint (org.apache.catalina.deploy.SecurityConstraint)2 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)2 MultiPartInputStreamParser (org.eclipse.jetty.util.MultiPartInputStreamParser)2