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:com.edgenius.wiki.util.WikiUtil.java

/**
 * @return//from www .ja v a2  s.  c om
 */
public static User getUser() {
    ServletContext servletCtx = WebUtil.getServletContext();
    User user = null;
    if (servletCtx != null) {
        ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletCtx);
        UserReadingService userReadingService = (UserReadingService) ctx
                .getBean(UserReadingService.SERVICE_NAME);
        user = userReadingService.getUserByName(getUserName());
    }
    if (user == null) {
        user = ProxyLoginUtil.getRequester();
    }
    return user;
}

From source file:com.glaf.core.context.StartupListener.java

public void setupContext(ServletContext context) {
    ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
    if (ctx != null) {
        logger.info("......");
        ContextFactory.setContext(ctx);// ww  w.ja v  a  2s  . c o  m
        if (conf.getBoolean("scheduler.enabled", true) && ContextFactory.hasBean("scheduler")) {
            SchedulerRunner runner = new SchedulerRunner();
            runner.start();
        }
    }
}

From source file:com.j2trp.test.util.jersey.spi.spring.container.servlet.SpringServlet.java

private ConfigurableApplicationContext getDefaultContext() {
    final WebApplicationContext springWebContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(getServletContext());
    final ConfigurableApplicationContext springContext = (ConfigurableApplicationContext) springWebContext;
    return springContext;
}

From source file:org.lamsfoundation.lams.admin.service.AdminServiceProxy.java

private static Object getDomainService(ServletContext servletContext, String serviceName) {
    WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
    return wac.getBean(serviceName);
}

From source file:com.edgenius.wiki.webapp.servlet.StatusServlet.java

private JmsTemplate getJmsTemplate() {
    ApplicationContext ctx = WebApplicationContextUtils
            .getRequiredWebApplicationContext(this.getServletContext());
    return (JmsTemplate) ctx.getBean("jmsTemplate");
}

From source file:it.scoppelletti.programmerpower.web.spring.ApplicationContextListener.java

/**
 * Inizializzazione di una’applicazione Web.
 * //www  .  j a v  a  2 s . c  om
 * @param event Evento.
 */
public void contextInitialized(ServletContextEvent event) {
    UUID applInstanceId;
    ApplicationContext applCtx;
    ServletContext servletCtx = event.getServletContext();
    AttributeMap servletCtxMap;
    EventContext eventCtx = null;

    try {
        applInstanceId = UUIDGenerator.getInstance().newUUID();
    } catch (Exception ex) {
        myLogger.error("Failed to extract UUID.", ex);
        applInstanceId = UUIDGenerator.NIL;
    }

    try {
        servletCtxMap = WebUtils.getSynchronizedAttributeMap(servletCtx);
        servletCtxMap.setAttribute(WebUtils.ATTR_APPLICATIONINSTANCEID, applInstanceId);

        eventCtx = new EventContext(ApplicationContextListener.THREAD_SERVLETCONTEXT_INIT, servletCtx);

        mySpringSvc.contextInitialized(event);
        applCtx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletCtx);
        myApplListeners = applCtx.getBeansOfType(ServletContextListener.class, false, true);
        mySessionListeners = applCtx.getBeansOfType(HttpSessionListener.class, false, true);

        for (Map.Entry<String, ServletContextListener> entry : myApplListeners.entrySet()) {
            myLogger.trace("Calling method contextInitialized of " + "ServletContextListener {}.",
                    entry.getKey());
            try {
                entry.getValue().contextInitialized(event);
            } catch (Exception ex) {
                myLogger.error(entry.getKey(), ex);
            }
        }
    } finally {
        if (eventCtx != null) {
            eventCtx.dispose();
            eventCtx = null;
        }
    }
}

From source file:com.atolcd.alfresco.AuditFilter.java

private ApplicationContext getApplicationContext() {
    return WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
}

From source file:com.edgenius.wiki.webapp.servlet.StatusServlet.java

private SpaceService getSpaceService() {

    ApplicationContext ctx = WebApplicationContextUtils
            .getRequiredWebApplicationContext(this.getServletContext());
    return (SpaceService) ctx.getBean(SpaceService.SERVICE_NAME);
}

From source file:com.qut.middleware.esoe.sso.servlet.SSOServlet.java

@Override
public void init() throws ServletException {
    try {//w  ww . ja v a2s  .  c o m
        /* Spring integration to make our servlet aware of IoC */
        WebApplicationContext webAppContext = WebApplicationContextUtils
                .getRequiredWebApplicationContext(this.getServletContext());

        this.ssoProcessor = (SSOProcessor) webAppContext.getBean(ConfigurationConstants.SSO_PROCESSOR,
                com.qut.middleware.esoe.sso.SSOProcessor.class);

        if (this.ssoProcessor == null)
            throw new IllegalArgumentException(
                    "Unable to acquire SSO Processor bean from web application context. Missing bean for name: "
                            + ConfigurationConstants.SSO_PROCESSOR);
    } catch (BeansException e) {
        this.logger.error(
                "Unable to acquire SSO Processor bean from web application context. Error retrieving bean for name: "
                        + e.getLocalizedMessage());
        throw new ServletException(
                "Unable to acquire SSO Processor bean from web application context. Error retrieving bean for name: "
                        + ConfigurationConstants.SSO_PROCESSOR,
                e);
    } catch (IllegalStateException e) {
        this.logger.error(
                "Unable to acquire SSO Processor bean from web application context. Currently in an illegal state for retrieving beans.",
                e);
        throw new ServletException(
                "Unable to acquire SSO Processor bean from web application context. Currently in an illegal state for retrieving beans.",
                e);
    }
}