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:com.application.model.dao.AuthenticationService.java

public void handleLogout(HttpServletRequest httpRequest) {

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

    WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);

    LogoutHandler logoutHandler = wac.getBean(LogoutHandler.class);

    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

    // Response should not be used?
    logoutHandler.logout(httpRequest, null, authentication);
}

From source file:org.sventon.web.tags.AuthorDecoratorTag.java

@Override
protected int doStartTagInternal() throws Exception {
    String result = author;/*from  ww  w  . j  av a2s.  co m*/

    try {
        final WebApplicationContext webApplicationContext = getRequestContext().getWebApplicationContext();
        final AuthorNameTransformer transformer = webApplicationContext.getBean(AuthorNameTransformer.class);
        result = transformer.transform(author);
    } catch (Exception e) {
        // Ignore - simply return the unprocessed input string.
    }
    pageContext.getOut().write(result);
    return EVAL_BODY_INCLUDE;
}

From source file:com.dynamobi.ws.util.LucidDBEncoder.java

public boolean isPasswordValid(String encPass, String rawPass, Object salt) {
    String pass1 = "" + encPass;
    String pass2 = encodePassword(rawPass, salt);

    //         System.out.println("ZZZZ rawPass= [" + rawPass + "] pass1 = [" +
    //         pass1
    //         + "] pass2 = [" + pass2 + "]");

    // We were successful, update session bean.
    if (pass1.equals(pass2)) {
        WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();

        UserCredentialsDataSourceAdapter ds = (UserCredentialsDataSourceAdapter) wac.getBean("myDataSource");
        ds.setPassword(rawPass);// www . j  ava 2s .co m
    }

    return pass1.equals(pass2);
}

From source file:com.ewcms.component.interaction.web.servlate.JavaScriptServlet.java

private InteractionServiceable getInteractionService() {
    ServletContext application = getServletContext();
    WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(application);
    return (InteractionServiceable) wac.getBean("interactionService");
}

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

@Override
public void init() throws ServletException {
    WebApplicationContext context = WebApplicationContextUtils
            .getRequiredWebApplicationContext(getServletContext());
    employerService = context.getBean(EmployerManager.class);
}

From source file:com.vityuk.ginger.servlet.SpringWebLocalizationResolver.java

@Override
public Localization resolve(ServletRequest servletRequest, ServletContext servletContext) {
    WebApplicationContext applicationContext = RequestContextUtils.getWebApplicationContext(servletRequest,
            servletContext);/*from ww w  .j av  a2s.  c  o m*/
    Localization localization = applicationContext.getBean(Localization.class);

    if (localization == null) {
        String message = "Unable to find " + Localization.class.getName() + " bean in Spring context";
        throw new IllegalStateException(message);
    }
    return localization;
}

From source file:cn.im47.cloud.storage.ftp.FtpServerListener.java

public void contextInitialized(ServletContextEvent sce) {
    logger.debug("Starting FtpServer");

    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
    FtpServer server = (FtpServer) ctx.getBean("myFtpServer");
    sce.getServletContext().setAttribute(FTPSERVER_CONTEXT_NAME, server);

    try {//w w  w .  ja v a  2 s .  c  o m
        server.start();
        logger.debug("FtpServer started");
    } catch (Exception e) {
        logger.error("Failed to start FtpServer", e);
        throw new RuntimeException("Failed to start FtpServer", e);
    }
}

From source file:com.ovalsearch.listener.OvalsearchContextListener.java

@Override
public void contextInitialized(ServletContextEvent sce) {
    LOG.info("Context Initialization event called");
    WebApplicationContext context = WebApplicationContextUtils
            .getWebApplicationContext(sce.getServletContext());
    final IStartupService startupService = context.getBean(IStartupService.class);
    try {//from   w  w  w. j  a  v a2s  .c om
        LOG.info("Loading Application Context");
        startupService.loadContext();
    } catch (Exception e) {
        LOG.error("Error while initializing application:", e);
    }
}

From source file:com.nec.harvest.servlet.listener.WebApplicationContextLoaderListener.java

/**
 * Get report path//from  w w w  . ja v  a 2  s . c  om
 * 
 * @param webApplicationContext
 * @return
 */
private String getReportPath(WebApplicationContext webApplicationContext) {
    JasperReportResolver jasperReportResolver = webApplicationContext.getBean(JasperReportResolver.class);

    // No JasperReportResolver specified of Bean
    Assert.notNull(jasperReportResolver, "No JasperReportResolver Bean Specified");
    return jasperReportResolver.getReportPath();
}

From source file:org.apache.ftpserver.example.springwar.FtpServerListener.java

public void contextInitialized(ServletContextEvent sce) {
    System.out.println("Starting FtpServer");

    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());

    FtpServer server = (FtpServer) ctx.getBean("myServer");

    sce.getServletContext().setAttribute(FTPSERVER_CONTEXT_NAME, server);

    try {/*from ww  w .j  a  v a 2s  .c  o m*/
        server.start();
        System.out.println("FtpServer started");
    } catch (Exception e) {
        throw new RuntimeException("Failed to start FtpServer", e);
    }
}