Example usage for org.springframework.web.context WebApplicationContext ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE

List of usage examples for org.springframework.web.context WebApplicationContext ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE

Introduction

In this page you can find the example usage for org.springframework.web.context WebApplicationContext ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE.

Prototype

String ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE

To view the source code for org.springframework.web.context WebApplicationContext ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE.

Click Source Link

Document

Context attribute to bind root WebApplicationContext to on successful startup.

Usage

From source file:test.pl.chilldev.facelets.taglib.spring.social.ConnectedTagTest.java

@Test
public void apply() throws IOException, FacesException {
    String provider = "facebook";

    Map<String, Object> config = new HashMap<>();
    config.put(ConnectedTag.ATTRIBUTE_PROVIDER, provider);

    ConnectedTag tag = new ConnectedTag(MockTagConfig.factory(config, this.nextHandler));

    // set up context
    FaceletContext context = new MockFaceletContext();
    context.getFacesContext().getExternalContext().getApplicationMap()
            .put(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.applicationContext);

    List<Connection<?>> connections = new ArrayList<>();
    connections.add(this.connection);

    when(this.applicationContext.getBean(ConnectionRepository.class)).thenReturn(this.connectionRepository);
    when(this.connectionRepository.findConnections(provider)).thenReturn(connections);

    // run the tag
    tag.apply(context, this.parent);

    verify(this.nextHandler).apply(context, this.parent);
}

From source file:org.sakaiproject.tool.section.jsf.JsfTool.java

/**
 * @inheritDoc/*ww w  .  j a  v a 2  s  .co m*/
 */
protected String computeDefaultTarget() {
    if (log.isDebugEnabled())
        log.debug("Entering sections tool... determining role appropriate view");

    ApplicationContext ac = (ApplicationContext) getServletContext()
            .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    Authn authnService = (Authn) ac.getBean("org.sakaiproject.section.api.facade.manager.Authn");
    Authz authzService = (Authz) ac.getBean("org.sakaiproject.section.api.facade.manager.Authz");
    Context contextService = (Context) ac.getBean("org.sakaiproject.section.api.facade.manager.Context");

    String userUid = authnService.getUserUid(null);
    String siteContext = contextService.getContext(null);

    boolean viewAllSections = authzService.isViewAllSectionsAllowed(userUid, siteContext);
    boolean viewOwnSections = authzService.isViewOwnSectionsAllowed(userUid, siteContext);

    String target;
    if (viewAllSections) {
        if (log.isDebugEnabled())
            log.debug("Sending user to the overview page");
        target = "/overview";
    } else if (viewOwnSections) {
        if (log.isDebugEnabled())
            log.debug("Sending user to the student view page");
        target = "/studentView";
    } else {
        // The role filter has not been invoked yet, so this could happen here
        throw new RuntimeException("User " + userUid + " attempted to access sections in site " + siteContext
                + " without any role");
    }
    return target;
}

From source file:org.parancoe.plugin.configuration.TestContextListener.java

@Override
protected void loadApplicationContext() {
    List<String> config = new ArrayList<String>();
    // generici/*w  w  w  .ja va  2  s .co m*/
    config.add("classpath:org/lambico/spring/dao/hibernate/genericDao.xml");
    config.add("classpath:org/lambico/spring/dao/hibernate/applicationContextBase.xml");
    config.add("classpath:org/parancoe/web/parancoeBase.xml");
    config.add("classpath:database-test-server.xml");
    config.add("classpath:applicationContext-test.xml");
    config.add("classpath*:parancoe-plugin.xml");
    config.add("classpath*:applicationContext-plugin.xml");
    config.add("classpath:org/parancoe/plugin/configuration/restful-services.xml");
    XmlWebApplicationContext ctx = new XmlWebApplicationContext();
    ctx.setServletContext(servletContext);
    ctx.setConfigLocations(config.toArray(new String[config.size()]));
    ctx.refresh();

    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx);
    applicationContext = ctx;

    populateDaoMap(ctx);
}

From source file:test.pl.chilldev.facelets.taglib.spring.web.MessageTagTest.java

@Test
public void apply() throws FacesException {
    String message = "Foo";
    String var = "bar";
    Locale locale = Locale.UK;

    String translated = "Baz";

    Map<String, Object> config = new HashMap<>();
    config.put(MessageTag.ATTRIBUTE_MESSAGE, message);
    config.put(MessageTag.ATTRIBUTE_VAR, var);

    MessageTag tag = new MessageTag(MockTagConfig.factory(config));

    // set up context
    FaceletContext context = new MockFaceletContext();
    context.getFacesContext().getExternalContext().getApplicationMap()
            .put(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.applicationContext);

    context.setLocale(locale);/*from  w w  w.  ja v a2  s. co  m*/
    when(this.applicationContext.getBean(MessageSource.class)).thenReturn(this.messageSource);
    when(this.messageSource.getMessage(message, null, locale)).thenReturn(translated);

    // run the tag
    tag.apply(context, this.parent);

    assertEquals("MessageTag.apply() should translate message using current locale by default.", translated,
            context.getAttribute(var));
}

From source file:org.red5.server.tomcat.TomcatApplicationContext.java

public void stop() {
    log.debug("stop");
    try {/*from  w w  w. j  a v a 2s  .  c  om*/
        ServletContext servlet = context.getServletContext();
        Object o = servlet.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
        if (o != null) {
            log.debug("Spring context for {} was found", context.getName());
            ConfigurableWebApplicationContext appCtx = (ConfigurableWebApplicationContext) o;
            //close the red5 app
            if (appCtx.isRunning()) {
                log.debug("Context was running, attempting to stop");
                appCtx.stop();
            }
            if (appCtx.isActive()) {
                log.debug("Context is active, attempting to close");
                appCtx.close();
            }
        } else {
            log.warn("Spring context for {} was not found", context.getName());
        }
    } catch (Exception e) {
        log.error("Could not stop spring context", e);
    }
    context.getParent().removeChild(context);
    if (context instanceof StandardContext) {
        StandardContext ctx = (StandardContext) context;
        try {
            //stop the tomcat context
            ctx.stop();
        } catch (Exception e) {
            log.error("Could not stop context", e);
        } finally {
            try {
                ctx.destroy();
            } catch (Exception e) {
                log.error("Could not destroy context", e);
            }
        }
    }
}

From source file:org.excalibur.service.deployment.server.context.handler.AbstractApplicationInitializedHandler.java

@Override
public final void handlerApplicationInitialized(ServletContextEvent sce) {
    ApplicationContext context = (ApplicationContext) sce.getServletContext()
            .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);

    String hostName = System.getProperty("org.excalibur.instance.hostname");
    checkState(!isNullOrEmpty(hostName));

    String regionName = System.getProperty("org.excalibur.provider.region.name");
    checkState(!isNullOrEmpty(regionName));

    String zoneName = System.getProperty("org.excalibur.provider.region.zone.name");
    checkState(!isNullOrEmpty(zoneName));

    String username = System.getProperty("org.excalibur.user.name");
    checkState(!isNullOrEmpty(username));

    String keyname = System.getProperty("org.excalibur.user.keyname");
    checkState(!isNullOrEmpty(keyname));

    Configuration configuration = new Configuration()
            .setProvider((ProviderSupport) context.getBean(Provider.class))
            .setRegion(context.getBean(RegionRepository.class).findByName(regionName))
            .setZone(context.getBean(RegionRepository.class).findZoneByName(zoneName))
            .setUser(context.getBean(UserRepository.class).findUserByUsername(username)).setHostName(hostName);

    UserProviderCredentials credentials = context.getBean(UserRepository.class)
            .findLoginCredentialsOfUserForProvider(configuration.getUser().getId(),
                    configuration.getProvider().getName());

    checkNotNull(credentials).setRegion(configuration.getRegion());

    credentials/* w ww  .  java  2s  .c om*/
            .setLoginCredentials(credentials.getLoginCredentials().toBuilder().credentialName(keyname).build());

    configuration.setCredentials(credentials);

    handlerApplicationInitializedEvent(configuration, context, sce);

    if (this.next_ != null) {
        this.next_.handlerApplicationInitialized(sce);
    }
}

From source file:com.wbss.mycoffee.in.helper.spring.WebContextLoader.java

@Override
public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception {

    final GenericWebApplicationContext webContext = new GenericWebApplicationContext();
    SERVLET_CONTEXT.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webContext);
    webContext.setServletContext(SERVLET_CONTEXT);
    createBeanDefinitionReader(webContext).loadBeanDefinitions(mergedConfig.getLocations());
    AnnotationConfigUtils.registerAnnotationConfigProcessors(webContext);
    webContext.refresh();//from  ww  w  .  jav  a2s .  c o  m
    webContext.registerShutdownHook();
    return webContext;
}

From source file:org.red5.server.net.servlet.StatisticsServlet.java

/** {@inheritDoc} */
@Override/*from w  w  w .ja  v a 2s  .c om*/
public void init() throws ServletException {
    webAppCtx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
    if (webAppCtx == null) {
        webAppCtx = (WebApplicationContext) getServletContext()
                .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    }
    if (webAppCtx == null) {
        throw new ServletException("No web application context found.");
    }

    webContext = (IContext) webAppCtx.getBean("web.context");

    // Register handlers in XML-RPC server
    server.addHandler("scopes", new XmlRpcScopeStatistics(webContext.getGlobalScope()));
}

From source file:io.lavagna.web.security.login.LdapLoginTest.java

@Before
public void prepare() {
    ldapLogin = new LdapLogin(userRepository, ldap, "errorPage");

    when(context.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE))
            .thenReturn(webApplicationContext);
    when(webApplicationContext.getBean(ConfigurationRepository.class)).thenReturn(configurationRepository);
    when(configurationRepository.getValue(Key.BASE_APPLICATION_URL)).thenReturn(baseUrl);
}

From source file:test.pl.chilldev.web.spring.context.SpringBeansFacesPageMetaModelResolverTest.java

@Test(expected = PageMetaModelContextException.class)
public void getPageMetaModelWithoutBean() throws PageMetaModelContextException {
    GenericWebApplicationContext appContext = new GenericWebApplicationContext();
    appContext.refresh();//from ww  w.j  ava 2  s.  c  o m
    FaceletContext faceletContext = new MockFaceletContext();
    faceletContext.getFacesContext().getExternalContext().getApplicationMap()
            .put(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appContext);

    PageMetaModelResolver resolver = new SpringBeansFacesPageMetaModelResolver();
    resolver.getPageMetaModel(faceletContext);
}