Example usage for org.springframework.web.context.support WebApplicationContextUtils getWebApplicationContext

List of usage examples for org.springframework.web.context.support WebApplicationContextUtils getWebApplicationContext

Introduction

In this page you can find the example usage for org.springframework.web.context.support WebApplicationContextUtils getWebApplicationContext.

Prototype

@Nullable
public static WebApplicationContext getWebApplicationContext(ServletContext sc) 

Source Link

Document

Find the root WebApplicationContext for this web app, typically loaded via org.springframework.web.context.ContextLoaderListener .

Usage

From source file:org.ops4j.pax.exam.spring.SpringInjectorFactory.java

@Override
public Injector createInjector() {
    assert servletContext != null;
    WebApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
    SpringInjector injector = new SpringInjector(appContext.getAutowireCapableBeanFactory());

    return injector;
}

From source file:pl.chilldev.web.spring.context.SpringBeansJspPageMetaModelResolver.java

/**
 * {@inheritDoc}//www  .j  a  v a2  s  . c o  m
 * @since 0.0.1
 */
@Override
public PageMetaModel getPageMetaModel(JspContext context) throws PageMetaModelContextException {
    WebApplicationContext applicationContext;

    // try to get web context
    if (context instanceof PageContext) {
        applicationContext = WebApplicationContextUtils
                .getWebApplicationContext(((PageContext) context).getServletContext());
    } else {
        this.logger.error("Could not acquire appplication context.");
        throw new PageMetaModelContextException(
                "SpringBeansJspPageMetaModelResolver requires JSP to be run with PageContenxt implmentation.");
    }

    try {
        this.logger.debug("Taking PageMetaModel from Spring context.");
        return applicationContext.getBean(PageMetaModel.class);
    } catch (BeansException error) {
        this.logger.error("Error while fethcing page model from Spring context.", error);
        throw new PageMetaModelContextException("Error fetching page meta model from Spring context.", error);
    }
}

From source file:org.openamf.invoker.SpringBeanInvoker.java

public SpringBeanInvoker(ServiceRequest request, HttpServletRequest servletRequest,
        ServletContext servletContext) {
    super(request, servletRequest, servletContext);
    this.context = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
}

From source file:au.edu.uq.cmm.paul.queue.QueueFeedServlet.java

protected Provider createProvider() {
    // Grab the JPA EntityManagerFactory for the QueueAdapter from the services object.
    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
    EntityManagerFactory emf = ctx.getBean("entityManagerFactory", EntityManagerFactory.class);

    // Initialize the Abdera infrastructure ... 
    QueueFeedAdapter ca = new QueueFeedAdapter(emf);
    ca.setHref("queue");
    SimpleWorkspaceInfo wi = new SimpleWorkspaceInfo();
    wi.setTitle("Ingestion Queue Workspace");
    wi.addCollection(ca);/*w ww . ja  va  2 s  .c o  m*/
    DefaultProvider provider = new DefaultProvider("/atom/");
    provider.addWorkspace(wi);
    provider.init(getAbdera(), null);
    return provider;
}

From source file:rights.HasSomeRightsTag.java

private boolean hasFilialRights() {
    ApplicationContext applicationContext = WebApplicationContextUtils
            .getWebApplicationContext(pageContext.getServletContext());
    branchRightsHolder = applicationContext.getBean(BranchRightsHolder.class);
    return (!branchRightsHolder.getBranchIds(url).isEmpty());
}

From source file:org.echocat.nodoodle.server.ServiceServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    final WebApplicationContext applicationContext = WebApplicationContextUtils
            .getWebApplicationContext(config.getServletContext());
    final String serviceName = config.getInitParameter(SERVICE_PARAM);
    if (StringUtils.isEmpty(serviceName)) {
        throw new ServletException("Required initParam " + SERVICE_PARAM + " not set.");
    }/*from   w w w  . j  a va2 s . co  m*/
    try {
        _service = applicationContext.getBean(serviceName, HttpService.class);
    } catch (NoSuchBeanDefinitionException e) {
        throw new ServletException("No service '" + serviceName + "' (defined under initParam '" + SERVICE_PARAM
                + "') could not be found.", e);
    }
    try {
        _service.init(config.getServletContext());
    } catch (Exception e) {
        throw new ServletException("Could not initiate the service: " + _service, e);
    }
}

From source file:org.kani.spring.ApplicationServlet.java

@SuppressWarnings("unchecked")
@Override/*  w w w.j  ava 2  s  . c om*/
public void init(ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig);

    applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletConfig.getServletContext());
    if (!applicationContext.containsBean(APPLICATION_BEAN_NAME)) {
        throw new IllegalStateException("No application bean with name " + APPLICATION_BEAN_NAME + " found.");
    }

    if (!applicationContext.isTypeMatch(APPLICATION_BEAN_NAME, Application.class)) {
        Object applicationBean = applicationContext.getBean(APPLICATION_BEAN_NAME);
        throw new IllegalStateException(
                String.format("Application bean has type %s but should be a subtype of %s.",
                        applicationBean.getClass().getName(), Application.class.getName()));
    }
    applicationClass = (Class<? extends Application>) applicationContext.getType(APPLICATION_BEAN_NAME);
}

From source file:net.arnx.jsonic.web.extension.SpringContainer.java

@Override
public void init(HttpServlet servlet) throws ServletException {
    super.init(servlet);
    this.log = LogFactory.getLog(servlet.getClass());
    appContext = WebApplicationContextUtils.getWebApplicationContext(context);
}

From source file:com.taobao.diamond.server.controller.CheckServlet.java

@Override
public void init() throws ServletException {
    super.init();
    WebApplicationContext webApplicationContext = WebApplicationContextUtils
            .getWebApplicationContext(getServletContext());
    configService = (ConfigService) webApplicationContext.getBean("configService");
    this.diskService = (DiskService) webApplicationContext.getBean("diskService");
    this.groupService = (GroupService) webApplicationContext.getBean("groupService");
    configController = new ConfigController();
    this.configController.setConfigService(configService);
    this.configController.setDiskService(diskService);
    this.configController.setGroupService(groupService);
    //        if(!StringUtils.isEmptyOrWhitespaceOnly(TimerTaskService.fn))
    //        SlfCheck.slfCheck(TimerTaskService.fn);
}

From source file:com.netflix.genie.server.startup.GenieModule.java

/**
 * Configure the Guice bindings.//  w  ww .j a  v  a  2  s . co  m
 */
@Override
protected void configureServlets() {
    final ApplicationContext springApplicationContext = WebApplicationContextUtils
            .getWebApplicationContext(getServletContext());
    bind(BeanFactory.class).toInstance(springApplicationContext);
    bind(JobJanitor.class).toProvider(SpringIntegration.fromSpring(JobJanitor.class, "JobJanitorImpl"));
    bind(GenieNodeStatistics.class)
            .toProvider(SpringIntegration.fromSpring(GenieNodeStatistics.class, "GenieNodeStatisticsImpl"));
    bind(JobCountManager.class)
            .toProvider(SpringIntegration.fromSpring(JobCountManager.class, "JobCountManagerImpl"));
    bind(JobCountMonitor.class)
            .toProvider(SpringIntegration.fromSpring(JobCountMonitor.class, "JobCountMonitorImpl"));
}