Example usage for org.springframework.web.context.support WebApplicationContextUtils getRequiredWebApplicationContext

List of usage examples for org.springframework.web.context.support WebApplicationContextUtils getRequiredWebApplicationContext

Introduction

In this page you can find the example usage for org.springframework.web.context.support WebApplicationContextUtils getRequiredWebApplicationContext.

Prototype

public static WebApplicationContext getRequiredWebApplicationContext(ServletContext sc)
        throws IllegalStateException 

Source Link

Document

Find the root WebApplicationContext for this web app, typically loaded via org.springframework.web.context.ContextLoaderListener .

Usage

From source file:org.openxdata.server.servlet.StudyExportServlet.java

@Override
public void init() throws ServletException {
    ServletContext sctx = this.getServletContext();
    WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(sctx);
    dataExportService = (DataExportService) ctx.getBean("dataExportService");
}

From source file:org.jminix.console.servlet.SpringMiniConsoleServlet.java

@Override
public void init() throws ServletException {
    String applicationBeanName = getInitParameter("applicationBean");
    if (applicationBeanName == null) {
        applicationBeanName = "miniConsoleApplication";
    }/*ww  w  .java  2s  .c  o  m*/

    ApplicationContext ac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());

    app = (MiniConsoleApplication) ac.getBean(applicationBeanName);

    super.init();

    getComponent().getClients().add(Protocol.CLAP);
}

From source file:org.intalio.tempo.web.LoginFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    if (request instanceof HttpServletRequest) {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;

        if (req.getRequestURI().endsWith("/login.htm") || req.getRequestURI().endsWith("/login")) {
            // don't protect login page
            chain.doFilter(request, response);
            return;
        }// www  .  ja  v a 2s  . c  om

        String secureSession = LoginController.getSecureRandomSession(req);
        String secureCookie = LoginController.getSecureRandomCookie(req);
        if (secureSession != null) {
            if (secureSession.equals(secureCookie)) {
                // already authenticated
                chain.doFilter(request, response);
                return;
            }
        }

        WebApplicationContext context = WebApplicationContextUtils
                .getRequiredWebApplicationContext(req.getSession().getServletContext());
        LoginController login = (LoginController) context.getBean("loginController");
        if (login == null)
            throw new IllegalStateException("Missing 'loginController' object in Spring webapp context");

        User user = login.getCurrentUser(req);
        if (user == null) {
            // authentication failed or not available
            LOG.info("User not logged in, redirecting to login page: " + login.getLoginPageURL());
            LoginController.setRedirectAfterLoginCookie(resp, req.getRequestURI());
            resp.sendRedirect(login.getLoginPageURL());
        } else {
            // authenticated: synchronize secure random
            if (secureCookie != null) {
                LoginController.setSecureRandomSession(req, secureCookie);
            } else {
                LoginController.generateSecureRandom(req, resp);
            }
            ApplicationState state = login.getApplicationState(req);
            if (state != null) {
                state.setCurrentUser(user);
            }
            chain.doFilter(request, response);
        }
    } else {
        LOG.warn("ServletRequest was not HttpServletRequest; ignoring request.");
    }
}

From source file:com.mqm.frame.infrastructure.startup.ContextInit.java

/**
 * ?DI/*from  w  w  w  .  j  a va  2  s.c  om*/
 * 
 * @param context ServletContextEvent
 */
public void contextInitialized(ServletContextEvent context) {

    final ServletContext servletContext = context.getServletContext();

    ContextInit.servletContext = servletContext;

    super.contextInitialized(context);

    // FBRP
    setContext(WebApplicationContextUtils.getRequiredWebApplicationContext(context.getServletContext()));
    ContextUtil.setApplicationContext(ContextInit.context);

    // ?FBRP?
    ContextUtil.setApplicationPath(context.getServletContext().getRealPath("/"));

    /*log.info("?Portlet...");
    log.debug("DriverConfiguration");
    DriverConfiguration driverConfiguration = (DriverConfiguration) ContextInit.context
    .getBean("fbrp_admin_driverConfiguration");
    log.debug("DriverConfiguration");
    servletContext.setAttribute(AttributeKeys.DRIVER_CONFIG, driverConfiguration);
            
    log.debug("?AdminConfiguration");
    AdminConfiguration adminConfiguration = (AdminConfiguration) ContextInit.context
    .getBean("fbrp_admin_adminConfiguration");
            
    if (adminConfiguration != null) {
       log.debug("?AdminConfiguration");
       servletContext.setAttribute(AttributeKeys.DRIVER_ADMIN_CONFIG, adminConfiguration);
    }
            
    log.debug("Portlet");
    PortletContainer container = (PortletContainer) ContextInit.context
    .getBean("fbrp_admin_portletContainer");
            
    log.debug("Portlet");
    servletContext.setAttribute(AttributeKeys.PORTLET_CONTAINER, container);
    log.info("Portlet????");
    */

    //TODO luxiaocheng  ?? 
    /*try {
       // 
       Scheduler scheduler = (Scheduler) ContextInit.getContext().getBean(
       "fbrp_scheduler");
       if (scheduler != null) {
    scheduler.start();
       }
    } catch (Exception e) {
       log.warn("??", e);
    }*/

    LicenseColl licenseList = null;
    try {
        licenseList = (LicenseColl) ContextInit.getContext().getBean("fbrp_licenseColl");
    } catch (Exception exe) {
        log.warn("License?");
    }
    if (licenseList != null) {
        boolean licenseIsValid = ValidateLicense.validateLicense(licenseList, ContextUtil.getApplicationPath());
        ContextUtil.put("licenseIsValid", licenseIsValid, ContextUtil.SCOPE_APPLICATION);
    } else {
        ContextUtil.put("licenseIsValid", true, ContextUtil.SCOPE_APPLICATION);
    }
}

From source file:fiftyfive.wicket.spring.FoundationSpringApplication.java

/**
 * Override this method to change how the Spring context is located,
 * for example during unit tests. The default implementation simply
 * locates the Spring context by calling
 * {@link WebApplicationContextUtils#getRequiredWebApplicationContext}.
 *///  w  w  w  . j  av a  2s.  com
protected ApplicationContext getApplicationContext() {
    return WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
}

From source file:nl.tue.gale.ae.JSONServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    ApplicationContext applicationContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(getServletContext());

    UMCache um = (UMCache) applicationContext.getBean("umCache");
    CacheSession<EntityValue> session = um.openSession();
    try {/*w  ww .  ja  v a 2s . co  m*/
        JSONParser parser = new JSONParser(req.getInputStream());
        JSONArray array = (JSONArray) parser.nextValue();
        for (JSONValue value : array.getValue())
            addToUM((JSONObject) value, session);
        session.commit();
    } catch (Exception e) {
        e.printStackTrace();
        error(e, resp);
    } finally {
        if (session.isOpen())
            session.rollback();
    }
    reply("succes", resp);
}

From source file:com.jredrain.session.HttpSessionFilter.java

protected SessionStore lookSessionStore() {
    WebApplicationContext wac = WebApplicationContextUtils
            .getRequiredWebApplicationContext(getServletContext());
    SessionStore store = wac.getBean("sessionStore", SessionStore.class);
    if (logger.isInfoEnabled()) {
        logger.info("Using '" + store.getClass().getSimpleName() + "' SessionStore for HttpSessionFilter");
    }/*  ww w.  j a  v  a  2  s.  c o m*/
    return store;
}

From source file:es.urjc.mctwp.bbeans.AbstractBean.java

public AbstractBean() {
    //Get Environment
    fc = FacesContext.getCurrentInstance();
    ec = fc.getExternalContext();// w w  w.j av  a  2s . c  o m
    sc = (ServletContext) ec.getContext();
    wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
}

From source file:nl.tue.gale.ae.impl.SAMLServlet.java

private GaleContext getGaleContext(HttpServletRequest req, HttpServletResponse resp) {
    ApplicationContext applicationContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(getServletContext());
    ProcessorManager pm = (ProcessorManager) applicationContext.getBean("processorManager");
    Resource resource = pm.createResource(req, resp);
    return GaleContext.of(resource);
}

From source file:com.opensymphony.able.filter.SimpleTransactionServletFilter.java

public void init(FilterConfig config) throws ServletException {
    context = WebApplicationContextUtils.getRequiredWebApplicationContext(config.getServletContext());
}