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:com.cubusmail.gwtui.server.services.MailboxService.java

@Override
public String processCall(String payload) throws SerializationException {

    if (this.applicationContext == null) {
        this.applicationContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
    }/*from  ww w.  j av a2s.c o  m*/

    if (SessionManager.isLoggedIn()) {
        try {
            return super.processCall(payload);
        } catch (SerializationException e) {
            log.error(e.getMessage(), e);
            throw e;
        }
    } else {
        RPCRequest rpcRequest = RPC.decodeRequest(payload, this.getClass(), this);
        return RPC.encodeResponseForFailure(rpcRequest.getMethod(), new GWTInvalidSessionException());
    }
}

From source file:org.LexGrid.LexBIG.caCore.web.util.LexEVSHTTPUtils.java

public LexEVSHTTPUtils(ServletContext context) {
    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(context);
    this.classCache = (LexEVSClassCache) ctx.getBean("ClassCache");
    this.applicationService = (LexEVSApplicationService) ctx.getBean("ApplicationServiceImpl");

    Properties systemProperties = (Properties) ctx.getBean("WebSystemProperties");

    try {//from   w ww.ja v  a2 s. c  o  m
        String rowCounter = systemProperties.getProperty("rowCounter");
        log.debug("rowCounter: " + rowCounter);
        if (rowCounter != null) {
            this.pageSize = rowCounter;
        }
    } catch (Exception ex) {
        log.error("Exception: ", ex);
    }
}

From source file:org.openmeetings.servlet.outputhandler.Export.java

public AuthLevelmanagement getAuthLevelManagement() {
    try {/* w ww .ja  v  a 2s.co  m*/
        if (ScopeApplicationAdapter.initComplete) {
            ApplicationContext context = WebApplicationContextUtils
                    .getWebApplicationContext(getServletContext());
            return (AuthLevelmanagement) context.getBean("authLevelManagement");
        }
    } catch (Exception err) {
        log.error("[getAuthLevelManagement]", err);
    }
    return null;
}

From source file:com.openmeap.services.ServiceManagementServlet.java

public void init() {

    context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());

    modelManager = (ModelManager) context.getBean("modelManager");

    modelServiceRefreshHandler = (ModelServiceRefreshHandler) context.getBean("modelServiceRefreshHandler");

    archiveUploadHandler = (ArchiveFileUploadHandler) context.getBean("archiveUploadHandler");
    archiveDeleteHandler = (ArchiveFileDeleteHandler) context.getBean("archiveDeleteHandler");
}

From source file:org.springside.modules.security.jcaptcha.JCaptchaFilter.java

/**
 * ApplicatonContext?CaptchaService./*from w ww . j  a v  a 2s  . c o  m*/
 */
protected void initCaptchaService(final FilterConfig fConfig) {
    ApplicationContext context = WebApplicationContextUtils
            .getWebApplicationContext(fConfig.getServletContext());
    captchaService = (CaptchaService) context.getBean(captchaServiceId);
}

From source file:org.openmeetings.servlet.outputhandler.CalendarServlet.java

public OmTimeZoneDaoImpl getOmTimeZoneDaoImpl() {
    try {//  www. j a va2s .  c o  m
        if (ScopeApplicationAdapter.initComplete) {
            ApplicationContext context = WebApplicationContextUtils
                    .getWebApplicationContext(getServletContext());
            return (OmTimeZoneDaoImpl) context.getBean("omTimeZoneDaoImpl");
        }
    } catch (Exception err) {
        log.error("[getOmTimeZoneDaoImpl]", err);
    }
    return null;
}

From source file:py.una.pol.karaku.util.Util.java

/**
 * Utiliza el servlet del contexto actual de Faces para obtener una
 * instancia del {@link WebApplicationContext} y as obtener los beans que
 * cargo el mismo./*  w ww.  ja va2  s  .c  o  m*/
 *
 * <p>
 * <b>Uso:</b>
 *
 * <pre>
 *
 * FacesContext fc = getContext(); // o FacesContext.getCurrentInstance();
 * PropertiesUtil pu = Util.getSpringBeanBYJSFContext(fc, PropertiesUtil.class);
 * </pre>
 *
 * En este punto <code>pu</code> es una variable ya instanciada por Spring,
 * es decir ya tiene inyectadas todas las dependencias.
 * </p>
 *
 * @param context
 *            contexto actual, puede ser nulo
 * @param beanType
 *            tipo del bean que se desea, tiene que estar anotado con alguna
 *            herencia de {@link Component}, o estar definido en los
 *            archivos de configuracin.
 * @return bean del tipo especificado
 * @see WebApplicationContext#getBean(Class)
 */
public static <T> T getSpringBeanByJSFContext(FacesContext context, @NotNull Class<T> beanType) {

    FacesContext contexto = context == null ? FacesContext.getCurrentInstance() : context;
    ServletContext sv = (ServletContext) contexto.getExternalContext().getContext();

    WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(sv);
    return wac.getBean(beanType);
}

From source file:org.jasig.portlet.announcements.spring.PortletApplicationContextLocator.java

/**
 * @return The WebApplicationContext for the portal, null if no ServletContext is available
 * @deprecated This method is a work-around for areas in uPortal that do not have the ability to use the {@link org.springframework.web.context.support.WebApplicationContextUtils#getWebApplicationContext(javax.servlet.ServletContext)} directly.
 *///from w  w  w.j  a v  a  2  s.  c  o  m
@Deprecated
public static WebApplicationContext getWebApplicationContext() {
    final ServletContext context = servletContext;
    if (context == null) {
        return null;
    }

    return WebApplicationContextUtils.getWebApplicationContext(context);
}

From source file:com.xyxy.platform.examples.showcase.demos.web.StaticContentServlet.java

/**
 * ?./*from  www. jav a  2s.com*/
 */
@Override
public void init() throws ServletException {
    // ?applicationContext?.
    applicationContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext());

    // ?mimeTypes, css,.
    mimetypesFileTypeMap = new MimetypesFileTypeMap();
    mimetypesFileTypeMap.addMimeTypes("text/css css");
}

From source file:org.carewebframework.ui.RequestProcessingServlet.java

/**
 * Method to centralize the processing of various Http request methods (e.g. GET, PUT, POST,
 * DELETE)//from   w w w  .j  a va  2 s  .com
 * 
 * @param req HttpServletRequest
 * @param res HttpServletResponse
 * @throws IllegalArgumentException If there is not the appropriate request parameter or if the
 *             bean found is not of type RequestProcessor
 * @throws ServletException Servlet exception.
 * @throws IOException IO Exception.
 * @throws BeansException If the bean could not be obtained
 * @throws NoSuchBeanDefinitionException If there is no bean definition with the specified name
 * @throws BeanNotOfRequiredTypeException If bean found is not a RequestProcessor implementation
 * @throws RequestProcessingException Request processing exception.
 */
protected final void processRequest(final HttpServletRequest req, final HttpServletResponse res)
        throws ServletException, IOException, NoSuchBeanDefinitionException, BeanNotOfRequiredTypeException,
        RequestProcessingException {
    final String processorBeanName = req.getParameter(REQUEST_PROCESSOR_BEAN);
    if (processorBeanName == null) {
        throw new IllegalArgumentException(getClass() + " expects the parameter " + REQUEST_PROCESSOR_BEAN
                + ", which is an instance of org.carewebframework.ui.RequestProcessor");
    }

    if (log.isDebugEnabled()) {
        log.debug("Request Method: " + req.getMethod());
        log.debug("Attempting to lookup the following bean in the registry: " + processorBeanName);
    }

    final IRequestProcessor processor = WebApplicationContextUtils
            .getWebApplicationContext(this.getServletContext())
            .getBean(processorBeanName, IRequestProcessor.class);
    try {
        processor.process(req, res);
    } catch (final Exception e) {
        throw new RequestProcessingException(EXC_REC_PROC, e, processor.getClass().getName());
    }
}