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:io.lavagna.web.security.login.DemoLoginTest.java

@Before
public void prepare() {
    dl = new DemoLogin(userRepository, errorPage);
    when(req.getMethod()).thenReturn("POST");
    when(req.getServletContext()).thenReturn(context);
    when(context.getContextPath()).thenReturn("");

    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:org.sakaiproject.tool.section.filter.RoleFilter.java

public void init(FilterConfig filterConfig) throws ServletException {
    if (logger.isInfoEnabled())
        logger.info("Initializing sections role filter");

    ac = (ApplicationContext) filterConfig.getServletContext()
            .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);

    authnBeanName = filterConfig.getInitParameter("authnServiceBean");
    authzBeanName = filterConfig.getInitParameter("authzServiceBean");
    contextBeanName = filterConfig.getInitParameter("contextManagementServiceBean");
    authorizationFilterConfigurationBeanName = filterConfig
            .getInitParameter("authorizationFilterConfigurationBean");
    selectSiteRedirect = filterConfig.getInitParameter("selectSiteRedirect");
}

From source file:com.athena.sqs.MessageDispatchListener.java

public void contextInitialized(ServletContextEvent sce) {
    ServletContext servletContext = sce.getServletContext();
    sqsConfigLocation = servletContext.getInitParameter("sqsConfigLocation");

    String realPath = servletContext.getRealPath(sqsConfigLocation);
    if (logger.isDebugEnabled()) {
        logger.debug("****************** SQS Config ******************");
        logger.debug("LOCATION : " + sqsConfigLocation);
        logger.debug("REAL LOCATION : " + realPath);
        logger.debug("************************************************");
    }/*from  ww  w.ja  v  a  2  s.  com*/

    ApplicationContext applicationContext = (ApplicationContext) servletContext
            .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    // TODO : You can load your own application config here
}

From source file:com.clican.pluto.cms.ui.listener.StartupListener.java

public void contextInitialized(ServletContextEvent event) {
    super.contextInitialized(event);
    try {/* w  ww .j  ava2 s  .  com*/
        Velocity.init(
                Thread.currentThread().getContextClassLoader().getResource("velocity.properties").getPath());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    ApplicationContext ctx = null;
    JndiUtils.setJndiFactory(MockContextFactory.class.getName());
    Hashtable<String, String> ht = new Hashtable<String, String>();
    ht.put(Context.INITIAL_CONTEXT_FACTORY, MockContextFactory.class.getName());
    try {
        ctx = (ApplicationContext) JndiUtils.lookupObject(ApplicationContext.class.getName());
        if (ctx == null) {
            log.warn("Cannot get ApplicationContext from JNDI");
        }
    } catch (Exception e) {
        log.warn("Cannot get ApplicationContext from JNDI");
    }
    if (ctx == null) {
        ctx = (new ClassPathXmlApplicationContext(new String[] { "classpath*:META-INF/ui-*.xml", }));
    }
    XmlWebApplicationContext wac = (XmlWebApplicationContext) WebApplicationContextUtils
            .getRequiredWebApplicationContext(event.getServletContext());
    wac.setParent(ctx);
    wac.refresh();
    event.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    Constants.ctx = wac;
}

From source file:io.lavagna.web.security.SecurityFilterTest.java

@Before
public void prepare() {
    WebSecurityConfig webSecurityConfig = new WebSecurityConfig();
    when(webApplicationContext.getBean("configuredAppPathConf", PathConfiguration.class))
            .thenReturn(webSecurityConfig.configuredApp());
    when(webApplicationContext.getBean("unconfiguredAppPathConf", PathConfiguration.class))
            .thenReturn(webSecurityConfig.unconfiguredApp());
    when(webApplicationContext.getBean(ConfigurationRepository.class)).thenReturn(configurationRepository);
    when(filterConfig.getServletContext()).thenReturn(servletContext);
    when(servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE))
            .thenReturn(webApplicationContext);
}

From source file:org.red5.stream.http.servlet.TransportSegmentFeeder.java

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
 *      response)//from w  w  w  . j  a  va 2  s  .  c  o  m
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    log.debug("Segment feed requested");
    // get red5 context and segmenter
    if (service == null) {
        ApplicationContext appCtx = (ApplicationContext) getServletContext()
                .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
        service = (SegmenterService) appCtx.getBean("segmenter.service");
    }
    // get the requested stream / segment
    String servletPath = request.getServletPath();
    String streamName = servletPath.split("\\.")[0];
    log.debug("Stream name: {}", streamName);
    if (service.isAvailable(streamName)) {
        response.setContentType("video/MP2T");
        // data segment
        Segment segment = null;
        // setup buffers and output stream
        byte[] buf = new byte[188];
        ByteBuffer buffer = ByteBuffer.allocate(188);
        ServletOutputStream sos = response.getOutputStream();
        // loop segments
        while ((segment = service.getSegment(streamName)) != null) {
            do {
                buffer = segment.read(buffer);
                // log.trace("Limit - position: {}", (buffer.limit() - buffer.position()));
                if ((buffer.limit() - buffer.position()) == 188) {
                    buffer.get(buf);
                    // write down the output stream
                    sos.write(buf);
                } else {
                    log.info("Segment result has indicated a problem");
                    // verifies the currently requested stream segment
                    // number against the currently active segment
                    if (service.getSegment(streamName) == null) {
                        log.debug("Requested segment is no longer available");
                        break;
                    }
                }
                buffer.clear();
            } while (segment.hasMoreData());
            log.trace("Segment {} had no more data", segment.getIndex());
            // flush
            sos.flush();
            // segment had no more data
            segment.cleanupThreadLocal();
        }
        buffer.clear();
        buffer = null;
    } else {
        // let requester know that stream segment is not available
        response.sendError(404, "Requested segmented stream not found");
    }
}

From source file:ltistarter.controllers.AppControllersTest.java

@Before
public void setup() {
    assertNotNull(context);/*  ww  w  . j  a  v a 2  s.  c  om*/
    assertNotNull(springSecurityFilter);
    // Process mock annotations
    MockitoAnnotations.initMocks(this);
    // Setup Spring test in webapp-mode (same config as spring-boot)
    this.mockMvc = MockMvcBuilders.webAppContextSetup(context).addFilters(springSecurityFilter).build();
    context.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
            context);
}

From source file:com.trenako.web.test.AbstractSpringTagsTest.java

@Before
public void setup() throws Exception {
    mockServletContext = new MockServletContext();

    // mocking the spring web application context
    mockWebApplicationContext = mock(WebApplicationContext.class);
    when(mockWebApplicationContext.getServletContext()).thenReturn(mockServletContext);
    when(mockWebApplicationContext.getAutowireCapableBeanFactory())
            .thenReturn(mock(AutowireCapableBeanFactory.class));

    mockServletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
            mockWebApplicationContext);/*from   w w w.j  a va2s.  c  om*/

    // mocking the servlet request
    mockRequest = new MockHttpServletRequest();
    mockRequest.setContextPath("/trenako-web");
    mockRequest.setAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE, "/trenako-web");
    mockPageContext = new MockPageContext(mockServletContext, mockRequest);

    // mocking the message source to always return the default value
    mockMessageSource = mock(MessageSource.class);
    when(mockMessageSource.getMessage(anyString(), any(Object[].class), anyString(), any(Locale.class)))
            .thenAnswer(new Answer<String>() {
                @Override
                public String answer(InvocationOnMock invocation) throws Throwable {
                    Object[] args = invocation.getArguments();
                    return (String) args[2];
                }
            });

    // give the tag under test the chance to setup itself
    setupTag(mockPageContext, mockMessageSource);
}

From source file:grgr.test.cxf.UndertowCxfTest.java

@Test
public void testUndertowServlet() throws Exception {

    ServletContainer servletContainer = Servlets.newContainer();

    // parent, webcontext-wide Spring context
    ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext("/UndertowCxfTest-context.xml");

    // represents a servlet deployment - representing everything we can find in web.xml
    DeploymentInfo di = Servlets.deployment().setClassLoader(UndertowCxfTest.class.getClassLoader())
            .setContextPath("/").setDeploymentName("ROOT.war").setDisplayName("Default Application")
            .setUrlEncoding("UTF-8").addServlets(
                    Servlets.servlet("cxf", CXFServlet.class, new ImmediateInstanceFactory<>(new CXFServlet()))
                            .addMapping("/*"));

    DeploymentManager dm = servletContainer.addDeployment(di);
    dm.deploy();//from  ww  w.  j  a  v a 2s  .c o m
    HttpHandler handler = dm.start();

    // parent, webcontext-wide Spring web context
    GenericWebApplicationContext wac = new GenericWebApplicationContext();
    wac.setParent(parent);
    wac.setServletContext(dm.getDeployment().getServletContext());

    wac.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    wac.refresh();

    PathHandler path = Handlers.path().addPrefixPath(di.getContextPath(), Handlers.requestDump(handler));

    createAndStartServlet(8000, path);
}