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

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

Introduction

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

Prototype

Object getBean(String name) throws BeansException;

Source Link

Document

Return an instance, which may be shared or independent, of the specified bean.

Usage

From source file:org.vaadin.spring.security.shared.PushSecurityInterceptor.java

private synchronized SecurityContextRepository getSecurityContextRepository(ServletContext servletContext) {
    if (securityContextRepository == null) {
        final WebApplicationContext applicationContext = WebApplicationContextUtils
                .getWebApplicationContext(servletContext);
        try {/* ww  w. j  av  a 2s .  c o  m*/
            securityContextRepository = applicationContext.getBean(SecurityContextRepository.class);
        } catch (BeansException ex) {
            LOGGER.info(
                    "Found no SecurityContextRepository in the application context, using HttpSessionSecurityContextRepository");
            securityContextRepository = new HttpSessionSecurityContextRepository();
        }
    }
    return securityContextRepository;
}

From source file:ru.org.linux.auth.SecurityFilter.java

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {

    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
    HttpServletRequest request = (HttpServletRequest) req;
    request.setAttribute("configuration", ctx.getBean(Configuration.class));
    request.setAttribute("template", new Template(ctx));
    request.setCharacterEncoding("utf-8"); // ?? tomcat
    CSRFManipulation(request, (HttpServletResponse) res);
    forWikiManipulation(request, (HttpServletResponse) res);
    chain.doFilter(req, res);// ww  w  .j a va  2 s  .c  om
}

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:net.naijatek.myalumni.util.taglib.FrontPageLinksTag.java

/**
 * Includes the body of the tag if the page attribute equals the value set
 * in the 'match' attribute.//from  ww w  .  ja  va2s. c o m
 *
 * @return SKIP_BODY if equalsAttribute body content does not equal the
 *   value of the match attribute, EVAL_BODY_include if it does
 * @throws JspException
 */
@Override
public final int doStartTag() throws JspException {
    request = (HttpServletRequest) pageContext.getRequest();
    WebApplicationContext wac = WebApplicationContextUtils
            .getWebApplicationContext(pageContext.getServletContext());
    frontPageService = (IFrontPageService) wac.getBean(BaseConstants.SERVICE_FRONT_PAGE);
    return EVAL_BODY_BUFFERED;
}

From source file:org.openxdata.server.servlet.WMDownloadServlet.java

@Override
public void init() throws ServletException {
    ServletContext sctx = this.getServletContext();
    WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(sctx);
    formDownloadService = (FormDownloadService) ctx.getBean("formDownloadService");
}

From source file:se.vgregion.sitemap.servlet.DefaultSitemapServlet.java

/**
 * Override if you want to load/set other service bean than default "sitemapService" from Spring context.
 *///  w ww .  j a va2 s .  c  om
protected void loadSitemapService() {
    WebApplicationContext springContext = WebApplicationContextUtils
            .getWebApplicationContext(getServletContext());

    setSitemapService((SitemapService<?>) springContext.getBean("sitemapService"));
}

From source file:com.bt.aloha.batchtest.ultramonkey.Servlet.java

@Override
public void init(ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig);

    WebApplicationContext applicationContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletConfig.getServletContext());
    service = (Service) applicationContext.getBean("serviceBean");
    // check for a system property to set the Stack contact address
    if (null != System.getProperty("sip.stack.contact.address", null)) {
        SimpleSipStack simpleSipStack = (SimpleSipStack) applicationContext.getBean("simpleSipStack");
        simpleSipStack.setContactAddress(System.getProperty("sip.stack.contact.address"));
    }/*from  ww  w .j a v  a  2  s .c  om*/
}

From source file:com.sbu.controller.Update_Form_Employer_Controller.java

@Override
public void init() throws ServletException {
    WebApplicationContext context = WebApplicationContextUtils
            .getRequiredWebApplicationContext(getServletContext());
    skillsService = context.getBean(SkillsManager.class);
    employeeService = context.getBean(EmployeeManager.class);
    projectService = context.getBean(ProjectManager.class);
    employerService = context.getBean(EmployerManager.class);
    feedService = context.getBean(FeedManager.class);
}

From source file:com.cubusmail.server.services.CubusStartupListener.java

public void contextInitialized(ServletContextEvent servletcontextevent) {

    WebApplicationContext context = WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletcontextevent.getServletContext());

    try {/*from  www . j  av  a 2  s  .  c o  m*/
        DBManager dbManager = context.getBean(DBManager.class);
        dbManager.initInternalDB();
    } catch (Exception e) {
        log.fatal(e.getMessage(), e);
        throw new IllegalStateException("Could not initialize internal database!");
    }

    try {
        URL test = CubusStartupListener.class.getClassLoader()
                .getResource(CubusConstants.LOGIN_MODULE_CONFIG_FILE);
        System.setProperty(CubusConstants.JAAS_PROPERTY_NANE, test.getFile());
    } catch (Exception e) {
        log.fatal(e.getMessage(), e);
        throw new IllegalStateException("Could not load " + CubusConstants.LOGIN_MODULE_CONFIG_FILE);
    }
}

From source file:org.lamsfoundation.lams.admin.web.ScheduledJobListAction.java

/**
  * Get all waitting queue jobs scheduled in Quartz table and display job name, job start time and 
  * description. The description will be in format "Lesson Name":"the lesson creator", or 
  * "The gate name":"The relatived lesson name".
  * /*ww  w .  j  a v a  2 s. c  om*/
  * @param mapping The ActionMapping used to select this instance
  * @param actionForm The optional ActionForm bean for this request (if any)
  * @param request The HTTP request we are processing
  * @param response The HTTP response we are creating
  *
  * @exception IOException if an input/output error occurs
  * @exception ServletException if a servlet exception occurs
  * 
  */
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    WebApplicationContext ctx = WebApplicationContextUtils
            .getWebApplicationContext(this.getServlet().getServletContext());
    Scheduler scheduler = (Scheduler) ctx.getBean("scheduler");
    ArrayList<ScheduledJobDTO> jobList = new ArrayList<ScheduledJobDTO>();
    try {
        String[] jobNames = scheduler.getJobNames(Scheduler.DEFAULT_GROUP);
        for (String name : jobNames) {
            ScheduledJobDTO jobDto = new ScheduledJobDTO();
            JobDetail detail = scheduler.getJobDetail(name, Scheduler.DEFAULT_GROUP);
            jobDto.setName(name);
            jobDto.setDescription(detail.getDescription());
            Trigger[] triggers = scheduler.getTriggersOfJob(name, Scheduler.DEFAULT_GROUP);
            for (Trigger trigger : triggers) {
                jobDto.setStartDate(trigger.getStartTime());
                jobList.add(jobDto);
            }
        }
    } catch (SchedulerException e) {
        log.equals("Failed get job names:" + e.getMessage());
    }

    request.setAttribute("jobList", jobList);
    return mapping.findForward("list");
}