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.i4change.app.http.javarpc.UserServiceRPC.java

public UserSidebarPropertyDTO getUserSidebarPropertyByDiagram(String SID, Long diagramNo) {
    try {/*  ww  w  .  j ava 2  s .  co  m*/

        ServletContext servletContext = this.servletRequest.getSession().getServletContext();

        ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
        IUserservice userservice = (IUserservice) context.getBean("userservice.service");

        return userservice.getUserSidebarPropertyByDiagram(SID, diagramNo);

    } catch (Exception err) {
        log.error("[getUserSidebarPropertyByDiagram]", err);
    }
    return null;
}

From source file:org.i4change.app.http.javarpc.UserServiceRPC.java

public Long checkUserStatus(String SID) {
    try {//from  www.  java  2s .c  om

        ServletContext servletContext = this.servletRequest.getSession().getServletContext();

        ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
        IUserservice userservice = (IUserservice) context.getBean("userservice.service");

        return userservice.checkUserStatus(SID);

    } catch (Exception err) {
        log.error("[checkUserStatus]", err);
    }
    return null;
}

From source file:org.i4change.app.http.javarpc.UserServiceRPC.java

public Long activateUserByMod(String SID, Long user_id) {
    try {//from   ww w.j  a  v a2 s  .  c  o  m

        ServletContext servletContext = this.servletRequest.getSession().getServletContext();

        ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
        IUserservice userservice = (IUserservice) context.getBean("userservice.service");

        return userservice.activateUserByMod(SID, user_id);

    } catch (Exception err) {
        log.error("[activateUserByMod]", err);
    }
    return null;
}

From source file:org.i4change.app.http.javarpc.UserServiceRPC.java

public Long addTransaction(String SID, String amount, Long numberOfLicenses) {
    try {//from  w  w  w.  j  ava2 s.  c  om

        log.debug("addTransaction amount :: " + amount);

        ServletContext servletContext = this.servletRequest.getSession().getServletContext();

        ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
        IUserservice userservice = (IUserservice) context.getBean("userservice.service");

        return userservice.addTransaction(SID, amount, numberOfLicenses);

    } catch (Exception err) {
        log.error("[addTransaction]", err);
    }
    return null;
}

From source file:org.i4change.app.http.javarpc.UserServiceRPC.java

public SearchResult getTransactions(String SID, int start, int max, String orderby, boolean asc,
        HttpServletRequest request) {/*w  w  w  .  j  av  a2 s  .co m*/
    try {

        ServletContext servletContext = this.servletRequest.getSession().getServletContext();

        ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
        IUserservice userservice = (IUserservice) context.getBean("userservice.service");

        return userservice.getTransactions(SID, start, max, orderby, asc);

    } catch (Exception err) {
        log.error("[getTransactions]", err);
    }
    return null;
}

From source file:org.i4change.app.http.javarpc.UserServiceRPC.java

public TransactionPaypal getTransactionById(String SID, Long transactionId) {
    try {/* w  ww  .java 2s .c  o  m*/

        ServletContext servletContext = this.servletRequest.getSession().getServletContext();

        ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
        IUserservice userservice = (IUserservice) context.getBean("userservice.service");

        return userservice.getTransactionById(SID, transactionId);

    } catch (Exception err) {
        log.error("[getTransactionById]", err);
    }
    return null;
}

From source file:org.i4change.app.http.javarpc.UserServiceRPC.java

public PaymentStatus payLicense(String SID, Long transactionId, String firstName, String lastName,
        String address1, String address2, String city, String state, String zip, String countryCode,
        String creditCardType, String creditCardNumber, String expDateMonth, String expDateYear,
        String cvv2Number, String firstName2, String lastName2) {
    try {/*from   www . j a  v a  2  s .  c  o m*/

        ServletContext servletContext = this.servletRequest.getSession().getServletContext();

        ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
        IUserservice userservice = (IUserservice) context.getBean("userservice.service");

        String remoteAddr = this.servletRequest.getRemoteAddr();

        return userservice.payLicense(SID, transactionId, firstName, lastName, address1, address2, city, state,
                zip, countryCode, creditCardType, creditCardNumber, expDateMonth, expDateYear, cvv2Number,
                remoteAddr, firstName2, lastName2);

    } catch (Exception err) {
        log.error("[getTransactionById]", err);
    }
    return null;
}

From source file:org.infoscoop.web.InitializeServlet.java

/**
 * <P>initialize the servlet.</P><BR>
 * It is a precondition to operate a servlet that a file of DAO setting (/WEB-INF/conf/dao-config.xml) is set definitely.
 *//*from   w ww .ja v  a  2 s. c o  m*/
public void init(ServletConfig config) throws ServletException {

    initLog4jProperties(config);
    //loadDAOConfig(config);
    initVelocity(config);

    ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext());
    SpringUtil.setContext(ctx);
    initSearchUserService();
    Security.setProperty("networkaddress.cache.ttl", "60");
}

From source file:org.jasig.portal.spring.PortalApplicationContextLocator.java

/**
 * If running in a web application the existing {@link WebApplicationContext} will be returned. if
 * not a singleton {@link ApplicationContext} is created if needed and returned. Unless a {@link WebApplicationContext}
 * is specifically needed this method should be used as it will work both when running in and out
 * of a web application/*from  w  w  w  .j a  v a 2 s  .c om*/
 * 
 * @return The {@link ApplicationContext} for the portal. 
 */
public static ApplicationContext getApplicationContext() {
    Log logger = LogFactory.getLog(LOGGER_NAME);
    final ServletContext context = servletContext;

    if (context != null) {
        logger.debug("Using WebApplicationContext");

        if (applicationContextCreator.isCreated()) {
            final IllegalStateException createException = new IllegalStateException(
                    "A portal managed ApplicationContext has already been created but now a ServletContext is available and a WebApplicationContext will be returned. "
                            + "This situation should be resolved by delaying calls to this class until after the web-application has completely initialized.");
            logger.error(createException, createException);
            logger.error("Stack trace of original ApplicationContext creator", directCreatorThrowable);
            throw createException;
        }

        final WebApplicationContext webApplicationContext = WebApplicationContextUtils
                .getWebApplicationContext(context);
        if (webApplicationContext == null) {
            throw new IllegalStateException(
                    "ServletContext is available but WebApplicationContextUtils.getWebApplicationContext(ServletContext) returned null. Either the application context failed to load or is not yet done loading.");
        }
        return webApplicationContext;
    }

    return applicationContextCreator.get();
}

From source file:org.jumpmind.metl.ui.init.AppInitializer.java

@Override
public void contextInitialized(ServletContextEvent sce) {
    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
    LogUtils.initLogging(getConfigDir(false), ctx);
    initDatabase(ctx);//w  w  w  .ja  v  a2s.co  m
    initAgentRuntime(ctx);
}