Example usage for javax.servlet ServletRequestEvent ServletRequestEvent

List of usage examples for javax.servlet ServletRequestEvent ServletRequestEvent

Introduction

In this page you can find the example usage for javax.servlet ServletRequestEvent ServletRequestEvent.

Prototype

public ServletRequestEvent(ServletContext sc, ServletRequest request) 

Source Link

Document

Construct a ServletRequestEvent for the given ServletContext and ServletRequest.

Usage

From source file:de.itsvs.cwtrpc.controller.RemoteServiceControllerServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {/*from ww  w. j av a2s  . com*/
        final PreparedRemoteServiceConfig serviceConfig;
        final RemoteServiceContext serviceContext;
        final ServletRequestEvent servletRequestEvent;

        serviceConfig = getServiceConfig(request);
        if (serviceConfig == null) {
            if (log.isDebugEnabled()) {
                log.debug("No service has been configured for requested URI: " + request.getRequestURI());
            }
            if (CwtRpcUtils.getRpcSessionInvalidationPolicy(request).isInvalidateOnUnexpectedException()) {
                invalidateSession(request);
            }
            response.sendError(HttpServletResponse.SC_NOT_FOUND,
                    "No service has been configured for requested URI");
            return;
        }

        serviceContext = new DefaultRemoteServiceContext(request, response);
        RemoteServiceContextHolder.setContext(serviceContext);

        if (isSpringRequestContextEnabled()) {
            servletRequestEvent = new ServletRequestEvent(getServletContext(), request);
        } else {
            servletRequestEvent = null;
        }
        try {
            if (servletRequestEvent != null) {
                requestContextListener.requestInitialized(servletRequestEvent);
            }
            processRpcCall(request, response, serviceConfig);
        } finally {
            if (servletRequestEvent != null) {
                requestContextListener.requestDestroyed(servletRequestEvent);
            }
        }
    } catch (IOException e) {
        throw e;
    } catch (RuntimeException e) {
        if (isUncaughtException(e)) {
            if (CwtRpcUtils.getRpcSessionInvalidationPolicy(request).isInvalidateOnUnexpectedException()) {
                invalidateSession(request);
            }
            throw e;
        }
        processUnexpectedFailure(request, response, e);
    } catch (Throwable e) {
        processUnexpectedFailure(request, response, e);
    } finally {
        RemoteServiceContextHolder.resetContext();
    }
}

From source file:org.hdiv.AbstractHDIVTestCase.java

protected final void setUp() throws Exception {

    String[] files = { "/org/hdiv/config/hdiv-core-applicationContext.xml", "/org/hdiv/config/hdiv-config.xml",
            "/org/hdiv/config/hdiv-validations.xml", "/org/hdiv/config/applicationContext-test.xml",
            "/org/hdiv/config/applicationContext-extra.xml" };

    if (this.applicationContext == null) {
        this.applicationContext = new ClassPathXmlApplicationContext(files);
    }/*w  w w. ja  v  a  2  s  . c o m*/

    // Servlet API mock
    HttpServletRequest request = (MockHttpServletRequest) this.applicationContext.getBean("mockRequest");
    HttpSession httpSession = request.getSession();
    ServletContext servletContext = httpSession.getServletContext();
    HDIVUtil.setHttpServletRequest(request);

    // Put Spring context on ServletContext
    StaticWebApplicationContext webApplicationContext = new StaticWebApplicationContext();
    webApplicationContext.setServletContext(servletContext);
    webApplicationContext.setParent(this.applicationContext);
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
            webApplicationContext);

    // Initialize config
    this.config = (HDIVConfig) this.applicationContext.getBean("config");

    InitListener initListener = new InitListener();
    // Initialize ServletContext
    ServletContextEvent servletContextEvent = new ServletContextEvent(servletContext);
    initListener.contextInitialized(servletContextEvent);
    // Initialize HttpSession
    HttpSessionEvent httpSessionEvent = new HttpSessionEvent(httpSession);
    initListener.sessionCreated(httpSessionEvent);
    // Initialize request
    ServletRequestEvent requestEvent = new ServletRequestEvent(servletContext, request);
    initListener.requestInitialized(requestEvent);

    if (log.isDebugEnabled()) {
        log.debug("Hdiv test context initialized");
    }

    onSetUp();
}

From source file:org.hdiv.hateoas.jackson.AbstractHDIVTestCase.java

protected void setUp() throws Exception {

    String[] files = { "/org/hdiv/config/hdiv-core-applicationContext.xml", "/org/hdiv/config/hdiv-config.xml",
            "/org/hdiv/config/hdiv-validations.xml", "/org/hdiv/config/applicationContext-test.xml",
            "/org/hdiv/config/applicationContext-extra.xml" };

    if (this.applicationContext == null) {
        this.applicationContext = new ClassPathXmlApplicationContext(files);
    }//from   w  ww  .  java2s .co  m

    // Servlet API mock
    HttpServletRequest request = (MockHttpServletRequest) this.applicationContext.getBean("mockRequest");
    HttpSession httpSession = request.getSession();
    ServletContext servletContext = httpSession.getServletContext();
    HDIVUtil.setHttpServletRequest(request);

    // Put Spring context on ServletContext
    StaticWebApplicationContext webApplicationContext = new StaticWebApplicationContext();
    webApplicationContext.setServletContext(servletContext);
    webApplicationContext.setParent(this.applicationContext);
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
            webApplicationContext);

    // Initialize config
    this.config = (HDIVConfig) this.applicationContext.getBean("config");

    InitListener initListener = new InitListener();
    // Initialize ServletContext
    ServletContextEvent servletContextEvent = new ServletContextEvent(servletContext);
    initListener.contextInitialized(servletContextEvent);
    // Initialize HttpSession
    HttpSessionEvent httpSessionEvent = new HttpSessionEvent(httpSession);
    initListener.sessionCreated(httpSessionEvent);
    // Initialize request
    ServletRequestEvent requestEvent = new ServletRequestEvent(servletContext, request);
    initListener.requestInitialized(requestEvent);

    if (log.isDebugEnabled()) {
        log.debug("Hdiv test context initialized");
    }

    onSetUp();
}

From source file:org.ireland.jnetty.dispatch.filterchain.ServletRequestListenerFilterChain.java

/**
 * Invokes the next filter in the chain or the final servlet at the end of the chain.
 * /*from w  ww. ja  v  a2s .  c  o m*/
 * @param request
 *            the servlet request
 * @param response
 *            the servlet response
 * @since Servlet 2.3
 */
@Override
public void doFilter(ServletRequest request, ServletResponse response) throws ServletException, IOException {
    try {
        //?ServletRequestListener#requestInitialized
        for (ServletRequestListener listener : _requestListeners) {
            ServletRequestEvent event = new ServletRequestEvent(_webApp, request);

            listener.requestInitialized(event);
        }

        _next.doFilter(request, response);
    } finally {
        //?ServletRequestListener#requestDestroyed
        for (int i = _requestListeners.size() - 1; i >= 0; i--) {
            try {
                ServletRequestEvent event = new ServletRequestEvent(_webApp, request);

                _requestListeners.get(i).requestDestroyed(event);
            } catch (Throwable e) {
                log.warn(e.toString(), e);
            }
        }
    }
}