Example usage for javax.servlet ServletRequestEvent getServletContext

List of usage examples for javax.servlet ServletRequestEvent getServletContext

Introduction

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

Prototype

public ServletContext getServletContext() 

Source Link

Document

Returns the ServletContext of this web application.

Usage

From source file:ReqListener.java

public void requestInitialized(ServletRequestEvent sre) {

    ServletContext context = sre.getServletContext();
    ServletRequest request = sre.getServletRequest();

    synchronized (context) {
        context.log("Request for "
                + (request instanceof HttpServletRequest ? ((HttpServletRequest) request).getRequestURI()
                        : "Unknown")
                + "; Count=" + ++reqCount);
    }/* w w w  .  j av  a 2 s.c  o  m*/

}

From source file:com.krawler.common.listeners.LocaleResolverListener.java

@Override
public void requestInitialized(ServletRequestEvent sre) {
    ServletRequest request = sre.getServletRequest();
    ServletContext context = sre.getServletContext();

    if (request != null && context != null) {
        request.setAttribute(LocaleUtils.LOCALE_RESOLVER_ATTRIBUTE,
                context.getAttribute(LocaleUtils.LOCALE_RESOLVER_NAME));
    } else {/*from w ww  . jav a2s. c  o m*/
        log.debug("Locale resolver cannot be associated with request [request:" + request + ",context:"
                + context + "]");
    }
}

From source file:com.mtgi.analytics.servlet.BehaviorTrackingListener.java

private synchronized void checkInit(ServletRequestEvent event) {
    if (!initialized) {

        ServletContext context = event.getServletContext();
        boolean hasFilter = BehaviorTrackingFilter.isFiltered(context);
        ArrayList<ServletRequestBehaviorTrackingAdapter> beans = new ArrayList<ServletRequestBehaviorTrackingAdapter>();

        //find registered request adapters in all mvc servlet contexts.
        for (Enumeration<?> atts = context.getAttributeNames(); atts.hasMoreElements();) {
            String name = (String) atts.nextElement();
            if (name.startsWith(FrameworkServlet.SERVLET_CONTEXT_PREFIX)) {
                Object value = context.getAttribute(name);
                if (value instanceof ListableBeanFactory)
                    addRequestAdapters(beans, (ListableBeanFactory) value, hasFilter);
            }//from w  w  w.ja  v a 2 s.c om
        }

        //look for shared application context, loaded by ContextLoaderListener.
        ListableBeanFactory parent = WebApplicationContextUtils.getWebApplicationContext(context);
        if (parent != null)
            addRequestAdapters(beans, parent, hasFilter);

        if (!beans.isEmpty()) {
            adapters = beans.toArray(new ServletRequestBehaviorTrackingAdapter[beans.size()]);
            log.info("BehaviorTracking for HTTP servlet requests started");
        }

        initialized = true;
    }
}