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.agiso.core.i18n.support.spring.MessageSourceAccessorMessageProvider.java

public MessageSourceAccessorMessageProvider(ServletContext servletContext) {
    messageSource = new MessageSourceAccessor(
            WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext));
}

From source file:com.huateng.startup.listener.ContextLoaderListener.java

public void contextInitialized(ServletContextEvent event) {
    ServletContext context = event.getServletContext();
    WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
    ContextUtil.setContext(ctx);//from  w  w  w.ja v  a2 s  . co  m
}

From source file:com.indeed.boxcar.server.servlet.AbstractBoxcarContextListener.java

@Override
public void contextInitialized(final ServletContextEvent event) {
    final ServletContext servletContext = event.getServletContext();
    final WebApplicationContext applicationContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletContext);

    try {/*from w  w w.j a  v  a  2 s .  c  o m*/
        final int maximumRequestsPerConnection = getIntInitParameter(servletContext,
                "maximumRequestsPerConnection", 1000);
        final int servicePort = getRequiredIntInitParameter(servletContext, "servicePort");
        final int localReservedPoolSize = getIntInitParameter(servletContext, "localReservedPoolSize", 0);
        if (localReservedPoolSize < 0) {
            throw new IllegalArgumentException(
                    "localReservedPoolSize must be >= 0, but was " + localReservedPoolSize);
        }

        server = createServer(servletContext, applicationContext, servicePort, maximumRequestsPerConnection,
                localReservedPoolSize);

        final Thread isdThread = new Thread(server);
        isdThread.setDaemon(true);
        isdThread.start();
    } catch (final Exception e) {
        logger.fatal("Error initializing webapp", e);
        throw new RuntimeException("Error in JobSearchContextListener init", e);
    }
}

From source file:jrouter.servlet.filter.SpringBeanJRouterFilter.java

/**
 * ActionFactoryspringbean//w  w w  .j  av  a  2s .c  o  m
 *
 * @param filterConfig ?
 *
 * @return ActionFactory bean.
 */
@Override
protected ActionFactory createActionFactory(FilterConfig filterConfig) {
    //set ActionFactory with spring bean
    return beanName == null
            ? WebApplicationContextUtils.getRequiredWebApplicationContext(filterConfig.getServletContext())
                    .getBean(ActionFactory.class)
            : WebApplicationContextUtils.getRequiredWebApplicationContext(filterConfig.getServletContext())
                    .getBean(beanName, ActionFactory.class);
}

From source file:org.araneaframework.ioc.spring.SimpleAraneaSpringDispatcherServlet.java

public void init() throws ServletException {
    beanFactory = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());

    rootConf = new XmlBeanFactory(
            new ClassPathResource("spring-property-conf/property-custom-webapp-aranea-conf.xml"), beanFactory);
    PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
    cfg.setLocation(new ClassPathResource("spring-property-conf/default-aranea-conf.properties"));

    Properties localConf = new Properties();
    try {//from   w w w. j  av a 2s.  c  o  m
        if (getServletContext().getResource("/WEB-INF/aranea-conf.properties") != null)
            localConf.load(getServletContext().getResourceAsStream("/WEB-INF/aranea-conf.properties"));
    } catch (IOException e) {
        throw new ServletException(e);
    }
    cfg.setProperties(localConf);
    cfg.setLocalOverride(true);

    cfg.postProcessBeanFactory(rootConf);

    super.init();
}

From source file:team.curise.filter.LoginFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain fc)
        throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) resp;
    String reqUri = request.getRequestURI();
    HttpSession session = request.getSession();
    String account = (String) session.getAttribute("account");
    if (reqUri.contains("ogin")) {
        System.out.println(reqUri + "...............");
    }//from  w  ww .  ja v  a2  s  . c o m
    ApplicationContext ac = WebApplicationContextUtils
            .getRequiredWebApplicationContext(request.getSession().getServletContext());
    CuriseInfoService c = (CuriseInfoService) ac.getBean("curiseInfoService");
    String url = request.getContextPath();

    //manageLogin??manageLogin
    if (reqUri.contains("login")) {
        List r = c.find("from CuriseInfo");
        List<CuriseInfo> list = (List<CuriseInfo>) r;
        List<String> curiseNames = new ArrayList<>();
        for (CuriseInfo ci : list) {
            curiseNames.add(ci.getName());
        }
        session.setAttribute("curiseNames", curiseNames);
        fc.doFilter(req, resp);
    }

    if (reqUri.contains("ogin") || reqUri.contains("js") || reqUri.contains("css") || reqUri.contains("icon")
            || reqUri.contains("font") || reqUri.contains("icon")) {
        fc.doFilter(req, resp);
        return;
    }

    if (account == null || "".equals(account)) {
        List r = c.find("from CuriseInfo");
        List<CuriseInfo> list = (List<CuriseInfo>) r;
        List<String> curiseNames = new ArrayList<>();
        for (CuriseInfo ci : list) {
            curiseNames.add(ci.getName());
        }
        session.setAttribute("curiseNames", curiseNames);
        response.sendRedirect("login");
    } else {
        fc.doFilter(req, resp);
    }
}

From source file:demo.order.MsgDelivererImpl.java

/**
 * Instead of @Autowired/ extends SpringBeanAutowiringSupport which doesn't work.
 *//* w  ww.  j  a va 2 s.  c o  m*/
private void wireBeans() {

    ServletContext servletContext;
    servletContext = (ServletContext) context.getMessageContext().get("javax.xml.ws.servlet.context");
    WebApplicationContext webApplicationContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletContext);
    consumer = (Consumer) webApplicationContext.getAutowireCapableBeanFactory().getBean("consumer");

    //        executorService = (ExecutorService) webApplicationContext.getAutowireCapableBeanFactory().getBean("executorService");

}

From source file:org.xaloon.wicket.component.inject.spring.CdiComponentInjector.java

/**
 * Construct.//ww w.  j a v a  2s.  co  m
 * 
 * @param webapp
 * @param beanNameResolver
 */
public CdiComponentInjector(WebApplication webapp, SpringAnnotationResolver... beanNameResolver) {
    // locate application context through spring's default location
    // mechanism and pass it on to the proper constructor
    this(webapp, WebApplicationContextUtils.getRequiredWebApplicationContext(webapp.getServletContext()),
            beanNameResolver);
}

From source file:com.application.model.dao.AuthenticationService.java

public void handleAuthentication(String login, String password, HttpServletRequest httpRequest) {

    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(login, password);

    token.setDetails(new WebAuthenticationDetails(httpRequest));

    ServletContext servletContext = httpRequest.getSession().getServletContext();

    WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);

    AuthenticationManager authManager = wac.getBean(AuthenticationManager.class);

    Authentication authentication = authManager.authenticate(token);

    SecurityContextHolder.getContext().setAuthentication(authentication);

}

From source file:com.rockagen.gnext.service.spring.security.extension.BasicRefreshMetadataSource.java

/**
 * Refresh./*from  w w w.  j  av  a 2s.c  om*/
 */
public void refresh() {
    ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
    FilterInvocationSecurityMetadataSource fisms = (FilterInvocationSecurityMetadataSource) ctx
            .getBean("securityMetadataSource");
    // Get  FilterSecurityInterceptor
    FilterSecurityInterceptor fsi = (FilterSecurityInterceptor) ctx.getBean("filterSecurityInterceptor");
    // Set new SecurityMetadataSource to FilterSecurityInterceptor
    fsi.setSecurityMetadataSource(fisms);
    log.info(" SecurityMetadataSource updating ....");
}