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:com.socialsite.util.SpringWicketTester.java

/**
 * Create the new ServletContext that will be used with this test session.
 * This method configures the spring web context to be included in your
 * Servlet context. It's the magic that makes everything happy.
 * /*from www .  j a v a  2 s.co  m*/
 * @param path
 *            the root context path for URLs
 * 
 * @return a configured ServletContext
 */
@Override
public ServletContext newServletContext(final String path) {
    final ServletContext context = new MockServletContext(getApplication(), path);
    getSpringContext().setServletContext(context);
    context.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, spring);
    return context;
}

From source file:serendip.struts.plugins.thymeleaf.ThymeleafSpringResult.java

@Override
public void execute(ActionInvocation actionInvocation) throws Exception {
    TemplateEngine templateEngine = templateEngineProvider.get();

    HttpServletRequest request = ServletActionContext.getRequest();
    HttpServletResponse response = ServletActionContext.getResponse();
    ServletContext servletContext = ServletActionContext.getServletContext();

    Object action = actionInvocation.getAction();

    // Action instance put to Thymeleaf context.
    Map<String, Object> variables = bindStrutsContest(action);

    // Locale by Struts2-Action.
    Locale locale = ((LocaleProvider) action).getLocale();

    // Spring-ApplicationContext.
    //ApplicationContext appctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
    ApplicationContext appctx = (ApplicationContext) servletContext
            .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);

    // Use SpringWebContext( by Thymeleaf-spring plugin. )
    SpringWebContext context = new SpringWebContext(request, response, servletContext, locale, variables,
            appctx);/*from w  ww  .  jav a  2 s  . co  m*/

    // response to TemplateEngine.
    response.setContentType("text/html");
    response.setCharacterEncoding(defaultEncoding);
    templateEngine.process(templateName, context, response.getWriter());
}

From source file:org.obiba.jta.web.cfg.JettyServer.java

private void createServletHandler() {
    servletContextHandler = new ServletContextHandler(ServletContextHandler.NO_SECURITY);
    servletContextHandler.setContextPath("/");
    servletContextHandler.addFilter(new FilterHolder(new RequestContextFilter()), "/*", FilterMapping.DEFAULT);
    initApplicationContext();//  w w  w  . j  a v a  2s  .  c  om
    servletContextHandler.getServletContext()
            .setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webApplicationContext);
}

From source file:org.parancoe.web.ContextListener.java

/**
 * load the ApplicationContext mixing the base parancoe files and the application specific
 * configuration// w w w  .ja  va 2 s .c om
 */
protected void loadApplicationContext() {
    List<String> config = new ArrayList<String>();
    // generici
    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/core/applicationContextBase.xml");
    config.add("WEB-INF/database.xml");
    // load all plugin configurations at once
    config.add("classpath*:applicationContext-plugin.xml");
    config.add("WEB-INF/applicationContext.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:com.dianping.lion.web.tag.StrutsTagSupport.java

private void injectWithSpringContainer() {
    if (!springContextInitialized) {
        ApplicationContext applicationContext = (ApplicationContext) ActionContext.getContext().getApplication()
                .get(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
        if (applicationContext == null) {
            logger.warn(/* www. ja  v a 2s.co m*/
                    "ApplicationContext could not be found.  Customized strutsTag classes will not be autowired.");
        } else {
            factory = new SpringObjectFactory();
            factory.setApplicationContext(applicationContext);
            factory.setAutowireStrategy(AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE);
        }
        springContextInitialized = true;
    }
    if (factory != null) {
        factory.autoWireBean(this);
    }
}

From source file:com.github.carlomicieli.nerdmovies.MockWebApplicationContextLoader.java

@Override
public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception {
    final MockServletContext servletContext = new MockServletContext(configuration.webapp(),
            new FileSystemResourceLoader());
    final MockServletConfig servletConfig = new MockServletConfig(servletContext, configuration.name());

    final AnnotationConfigWebApplicationContext webContext = new AnnotationConfigWebApplicationContext();
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webContext);
    webContext.getEnvironment().setActiveProfiles(mergedConfig.getActiveProfiles());
    webContext.setServletConfig(servletConfig);
    webContext.setConfigLocations(mergedConfig.getLocations());
    webContext.register(mergedConfig.getClasses());

    // Create a DispatcherServlet that uses the previously established
    // WebApplicationContext.
    @SuppressWarnings("serial")
    final DispatcherServlet dispatcherServlet = new DispatcherServlet() {
        @Override//from w ww .jav  a2s .  c  o m
        protected WebApplicationContext createWebApplicationContext(ApplicationContext parent) {
            return webContext;
        }
    };

    // Add the DispatcherServlet (and anything else you want) to the
    // context.
    // Note: this doesn't happen until refresh is called below.
    webContext.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {
        @Override
        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
            beanFactory.registerResolvableDependency(DispatcherServlet.class, dispatcherServlet);
            // Register any other beans here, including a ViewResolver if
            // you are using JSPs.
        }
    });

    // Have the context notify the servlet every time it is refreshed.
    webContext.addApplicationListener(
            new SourceFilteringListener(webContext, new ApplicationListener<ContextRefreshedEvent>() {
                @Override
                public void onApplicationEvent(ContextRefreshedEvent event) {
                    dispatcherServlet.onApplicationEvent(event);
                }
            }));

    // Prepare the context.
    webContext.refresh();
    webContext.registerShutdownHook();

    // Initialize the servlet.
    dispatcherServlet.setContextConfigLocation("");
    dispatcherServlet.init(servletConfig);

    return webContext;
}

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

@Test
public void applyNoConnectionRepository() 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);

    when(this.applicationContext.getBean(ConnectionRepository.class)).thenReturn(null);

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

    verifyZeroInteractions(this.nextHandler);
}

From source file:io.lavagna.web.security.login.oauth.HandlersTest.java

@Before
public void prepare() {

    when(sBuilder.provider(any(Api.class))).thenReturn(sBuilder);
    when(sBuilder.apiKey(any(String.class))).thenReturn(sBuilder);
    when(sBuilder.apiSecret(any(String.class))).thenReturn(sBuilder);
    when(sBuilder.callback(any(String.class))).thenReturn(sBuilder);
    when(sBuilder.scope(any(String.class))).thenReturn(sBuilder);
    when(sBuilder.build()).thenReturn(oauthService);

    session = new MockHttpSession();
    session2 = new MockHttpSession();

    when(req2.getParameter("code")).thenReturn("code");
    when(req2.getParameter("oauth_verifier")).thenReturn("code");

    when(req.getSession()).thenReturn(session);

    when(req2.getSession()).thenReturn(session);
    when(req2.getSession(true)).thenReturn(session2);

    when(req2.getServletContext()).thenReturn(servletContext);
    when(servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE))
            .thenReturn(webappContext);// w w w . j a  v  a 2  s. c om
    when(webappContext.getBean(ConfigurationRepository.class)).thenReturn(configurationRepository);
    when(configurationRepository.getValue(Key.BASE_APPLICATION_URL)).thenReturn(BASE_APPLICATION_URL);

    when(reqBuilder.req(any(Verb.class), any(String.class))).thenReturn(oauthReq);
    when(oauthReq.send()).thenReturn(oauthRes);
    when(usersRep.findUserByName(any(String.class), any(String.class))).thenReturn(user);

    bitbucketHandler = new BitbucketHandler(sBuilder, reqBuilder, key, secret, callback, usersRep, errPage);
    githubHandler = new GithubHandler(sBuilder, reqBuilder, key, secret, callback, usersRep, errPage);
    googleHandler = new GoogleHandler(sBuilder, reqBuilder, key, secret, callback, usersRep, errPage);
}