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.conwet.silbops.connectors.comet.CometServlet.java

@Override
protected void loadConfiguration(ServletConfig sc) throws ServletException {
    WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(sc.getServletContext());

    // Adding the handler to avoid auto-detection in super.init()
    this.addAtmosphereHandler(this.getInitParameter("mapping"),
            wac.getBean("cometHandler", AtmosphereHandler.class));

    super.loadConfiguration(sc);
}

From source file:grails.util.GrailsWebUtil.java

/**
 * Looks up a GrailsApplication instance from the ServletContext.
 *
 * @param servletContext The ServletContext
 * @return A GrailsApplication or null if there isn't one
 *//*from w  w  w.j av a 2s.  c om*/
public static GrailsApplication lookupApplication(ServletContext servletContext) {
    if (servletContext == null) {
        return null;
    }

    final WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
    if (context == null || !context.containsBean(GrailsApplication.APPLICATION_ID)) {
        return null;
    }

    return context.getBean(GrailsApplication.APPLICATION_ID, GrailsApplication.class);
}

From source file:com.redip.servlet.GetDistinctValueFromNonconformitiesAction.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
    String id = policy.sanitize(request.getParameter("parameter"));
    String parameter = ParameterParserUtil.parseStringParam(id, "");

    ApplicationContext appContext = WebApplicationContextUtils
            .getWebApplicationContext(this.getServletContext());
    IQualityNonconformitiesActionService nqcService = appContext
            .getBean(IQualityNonconformitiesActionService.class);
    try {/*from ww  w .j  a va2s . co  m*/
        JSONArray valueList = new JSONArray();
        try {
            for (String value : nqcService.findDistinctValueFromParameter(parameter)) {
                valueList.put(value);
            }
        } catch (Exception ex) {
            response.setContentType("text/html");
            response.getWriter().print(ex);

        }
        response.setContentType("application/json");
        response.getWriter().print(valueList.toString());
    } catch (Exception e) {
        Logger.log(GetInvariantList.class.getName(), Level.FATAL, "" + e);
        response.setContentType("text/html");
        response.getWriter().print(e.getMessage());
    }
}

From source file:com.ewcms.plugin.vote.manager.web.ResultServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    ServletOutputStream out = null;/*  w  w  w  .  j a va 2  s.c om*/
    StringBuffer output = new StringBuffer();
    try {
        String id = req.getParameter("id");

        if (!id.equals("") && StringUtils.isNumeric(id)) {
            Long questionnaireId = new Long(id);

            ServletContext application = getServletContext();
            WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(application);
            VoteFacable voteFac = (VoteFacable) wac.getBean("voteFac");

            String ipAddr = req.getRemoteAddr();

            output = voteFac.getQuestionnaireResultClientToHtml(questionnaireId,
                    getServletContext().getContextPath(), ipAddr);
        }
        out = resp.getOutputStream();
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html; charset=UTF-8");
        out.write(output.toString().getBytes("UTF-8"));
        out.flush();
    } finally {
        if (out != null) {
            out.close();
            out = null;
        }
    }
}

From source file:com.ewcms.content.vote.web.ResultServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    ServletOutputStream out = null;//from  ww w  .j a  va  2 s.  co m
    StringBuffer output = new StringBuffer();
    try {
        String id = req.getParameter("id");

        if (!id.equals("") && StringUtils.isNumeric(id)) {
            Long questionnaireId = new Long(id);

            ServletContext application = getServletContext();
            WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(application);
            QuestionnaireService questionnaireService = (QuestionnaireService) wac
                    .getBean("questionnaireService");

            String ipAddr = req.getRemoteAddr();

            output = questionnaireService.getQuestionnaireResultClientToHtml(questionnaireId,
                    getServletContext().getContextPath(), ipAddr);
        }
        out = resp.getOutputStream();
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html; charset=UTF-8");
        out.write(output.toString().getBytes("UTF-8"));
        out.flush();
    } finally {
        if (out != null) {
            out.close();
            out = null;
        }
    }
}

From source file:no.dusken.aranea.filter.PluginAwareConf.java

public PluginAwareConf(ServletContext context, InputStream inputStream, String fileName, String systemId) {
    super(context, inputStream, fileName, systemId);
    WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(context);

    pluginManager = webApplicationContext.getBean(araneaPluginManagerName, PluginManager.class);
    addPluginRules(context);/*from   ww w .  ja  v a 2 s.co  m*/
}

From source file:com.redoute.datamap.servlet.GetDistinctValueFromTableColumn.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
    String table = policy.sanitize(request.getParameter("table"));
    String colName = policy.sanitize(request.getParameter("colName"));

    ApplicationContext appContext = WebApplicationContextUtils
            .getWebApplicationContext(this.getServletContext());
    IDatamapService datamapService = appContext.getBean(IDatamapService.class);
    IPictureService pictureService = appContext.getBean(IPictureService.class);
    IDatamapLocationTypeService datamapLocationTypeService = appContext
            .getBean(IDatamapLocationTypeService.class);

    if (table != null && colName != null) {
        try {/*www .  j  a va  2 s .  c o  m*/
            JSONArray valueList = new JSONArray();
            try {
                if (table.equals("Datamap")) {
                    for (String value : datamapService.findDistinctValuesfromColumn(colName)) {
                        valueList.put(value);
                    }
                }
                if (table.equals("Picture")) {
                    for (String value : pictureService.findDistinctValuesfromColumn(colName)) {
                        valueList.put(value);
                    }
                }
                if (table.equals("DatamapLocationType")) {
                    for (String value : datamapLocationTypeService.findDistinctValuesfromColumn(colName)) {
                        valueList.put(value);
                    }
                }

            } catch (Exception ex) {
                response.setContentType("text/html");
                response.getWriter().print(ex);

            }
            response.setContentType("application/json");
            response.getWriter().print(valueList.toString());
        } catch (Exception e) {
            Logger.log(GetDistinctValueFromTableColumn.class.getName(), Level.FATAL, "" + e);
            response.setContentType("text/html");
            response.getWriter().print(e.getMessage());
        }
    }
}

From source file:ar.com.jrules.core.listener.JRuleListener.java

public void contextInitialized(ServletContextEvent servletContextEvent) {
    log.debug("start initialize jRules");

    ServletContext ctx = servletContextEvent.getServletContext();
    WebApplicationContext springContext = WebApplicationContextUtils.getWebApplicationContext(ctx);

    LoadJRules loadJRules = new LoadJRules(springContext);

    loadJRules.loadJRules();//from  w  w  w. ja v  a 2  s. c o m

    log.debug("end initialize jRules");
}

From source file:jahspotify.web.tags.FullTrackTag.java

@Override
protected int doStartTagInternal() throws Exception {
    final JahSpotify jahSpotify = WebApplicationContextUtils
            .getWebApplicationContext(pageContext.getServletContext()).getBean(JahSpotify.class);
    FullTrack fullTrack = BaseController.createFullTrack(jahSpotify, jahSpotify.readTrack(Link.create(_link)));

    pageContext.setAttribute(_var, fullTrack);
    return Tag.SKIP_BODY;
}

From source file:org.brekka.paveway.web.servlet.AbstractPavewayServlet.java

protected PavewayService initPavewayService() {
    WebApplicationContext applicationContext = WebApplicationContextUtils
            .getWebApplicationContext(getServletContext());
    return applicationContext.getBean(PavewayService.class);
}