List of usage examples for org.springframework.web.context.support WebApplicationContextUtils getWebApplicationContext
@Nullable public static WebApplicationContext getWebApplicationContext(ServletContext sc)
From source file:org.glimpse.server.servlet.LoginServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { UserManager userManager = WebApplicationContextUtils.getWebApplicationContext(getServletContext()) .getBean(UserManager.class); String login = request.getParameter("login"); String password = request.getParameter("password"); try {/*from w ww . j av a2s . c om*/ String connectionId = userManager.connect(login, password); GlimpseUtils.setConnectionId(request, response, connectionId, false); response.setContentType("text/plain"); response.getWriter().print("OK"); } catch (AuthenticationException e) { logger.error("Connection error", e); } }
From source file:org.glimpse.server.tag.ThemeTag.java
public int doStartTag() throws JspException { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); String theme = "default"; if (GlimpseUtils.isConnected(request)) { UserManager userManager = WebApplicationContextUtils .getWebApplicationContext(pageContext.getServletContext()).getBean(UserManager.class); UserAttributes userAttributes = userManager.getUserAttributes(GlimpseUtils.getUserId(request)); theme = userAttributes.getPreferences().getTheme(); if (logger.isDebugEnabled()) { logger.debug("User is connected, using theme <" + theme + ">"); }// w w w.j a v a 2 s . com } else { logger.debug("User is not connected, using default theme"); } try { pageContext.getOut().print(theme); } catch (IOException e) { throw new JspException(e); } return Tag.SKIP_BODY; }
From source file:org.grails.web.mapping.DefaultUrlMappingEvaluator.java
/** * @param servletContext The servlet context * @deprecated Used DefaultUrLMappingsEvaluator(ApplicationContext) instead *//*from w ww . ja v a2 s . c o m*/ @Deprecated public DefaultUrlMappingEvaluator(ServletContext servletContext) { this(WebApplicationContextUtils.getWebApplicationContext(servletContext)); }
From source file:org.hyperic.hq.ui.servlet.RenditServlet.java
protected void handleRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { boolean useInclude = false; // Since we may be processing via an internal RequestDispatcher // include(), we need to investigate the subrequest URIs, etc. // and use those, as Tomcat won't set them up in subrequest objects String reqUri = (String) req.getAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE); if (reqUri != null) useInclude = true;//from w w w . ja va 2 s .com if (reqUri == null && !useInclude) reqUri = req.getRequestURI(); String ctxPath = (String) req.getAttribute(WebUtils.INCLUDE_CONTEXT_PATH_ATTRIBUTE); if (ctxPath != null) useInclude = true; if (ctxPath == null && !useInclude) ctxPath = req.getContextPath(); String pathInfo = (String) req.getAttribute(WebUtils.INCLUDE_PATH_INFO_ATTRIBUTE); if (pathInfo != null) useInclude = true; if (pathInfo == null && !useInclude) pathInfo = req.getPathInfo(); String servletPath = (String) req.getAttribute(WebUtils.INCLUDE_SERVLET_PATH_ATTRIBUTE); if (servletPath != null) useInclude = true; if (servletPath == null && !useInclude) servletPath = req.getServletPath(); String queryStr = (String) req.getAttribute(WebUtils.INCLUDE_QUERY_STRING_ATTRIBUTE); if (queryStr != null) useInclude = true; if (queryStr == null && !useInclude) queryStr = req.getQueryString(); List fullPath = StringUtil.explode(reqUri, "/"); int pathSize = fullPath.size(); if (_log.isDebugEnabled()) { _log.debug("Request path [" + fullPath + "]"); } if (((String) fullPath.get(pathSize - 1)).endsWith(".groovy")) { _log.warn(".groovy file requested [" + fullPath + "]"); throw new ServletException("Illegal request path [" + fullPath + "]"); } if (!requestIsValid(req)) { throw new ServletException("Illegal request path [" + fullPath + "]"); } List subPath = fullPath.subList(pathSize - 3, fullPath.size()); String plugin = (String) subPath.get(0); if (_log.isDebugEnabled()) { _log.debug("Request for [" + plugin + "]: " + reqUri + (queryStr == null ? "" : ("?" + queryStr))); } int sessId = RequestUtils.getSessionIdInt(req); WebApplicationContext springContext = WebApplicationContextUtils .getWebApplicationContext(getServletContext()); AuthzBoss authzBoss = springContext.getBean(AuthzBoss.class); AuthzSubject user; try { user = authzBoss.getCurrentSubject(sessId); } catch (SessionException e) { // Could not get the current user. We should default to a 'nobody' // user here. _log.error("Unable to get current user. Bailing", e); throw new ServletException(e); } RequestInvocationBindings b = new RequestInvocationBindings(reqUri, ctxPath, pathInfo, servletPath, queryStr, user, req, resp, getServletContext()); long start = System.currentTimeMillis(); try { Bootstrap.getBean(RenditServer.class).handleRequest(plugin, b); } catch (Exception e) { throw new ServletException(e); } finally { _log.debug("Processed request for [" + plugin + "] in " + (System.currentTimeMillis() - start) + " ms"); } }
From source file:org.i4change.app.http.javarpc.ConfigServiceRPC.java
public SearchResult getAllConf(String SID, int start, int max, String orderby, boolean asc) { try {//from ww w. j a v a 2 s. co m ServletContext servletContext = this.servletRequest.getSession().getServletContext(); ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext); IConfigurationService configService = (IConfigurationService) context.getBean("configservice.service"); return configService.getAllConf(SID, start, max, orderby, asc); } catch (Exception err) { log.error("[getAllConf]", err); } return null; }
From source file:org.i4change.app.http.javarpc.ConfigServiceRPC.java
public Configuration getConfByConfigurationId(String SID, long configuration_id) { try {/*w w w . ja va 2 s. c o m*/ ServletContext servletContext = this.servletRequest.getSession().getServletContext(); ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext); IConfigurationService configService = (IConfigurationService) context.getBean("configservice.service"); return configService.getConfByConfigurationId(SID, configuration_id); } catch (Exception err) { log.error("[getConfByConfigurationId]", err); } return null; }
From source file:org.i4change.app.http.javarpc.ConfigServiceRPC.java
public Long saveOrUpdateConfiguration(String SID, Map values) { try {/*ww w . j av a2 s .c o m*/ ServletContext servletContext = this.servletRequest.getSession().getServletContext(); ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext); IConfigurationService configService = (IConfigurationService) context.getBean("configservice.service"); return configService.saveOrUpdateConfiguration(SID, values); } catch (Exception err) { log.error("[getConfByConfigurationId]", err); } return null; }
From source file:org.i4change.app.http.javarpc.ConfigServiceRPC.java
public Long deleteConfiguration(String SID, Map values) { try {//from w ww . ja v a 2 s .c om ServletContext servletContext = this.servletRequest.getSession().getServletContext(); ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext); IConfigurationService configService = (IConfigurationService) context.getBean("configservice.service"); return configService.deleteConfiguration(SID, values); } catch (Exception err) { log.error("[deleteConfiguration]", err); } return null; }
From source file:org.i4change.app.http.javarpc.ConfigServiceRPC.java
public List<Configuration> getLicenseDefaultConfiguration(String SID) { try {/*from ww w . j a va2 s. co m*/ ServletContext servletContext = this.servletRequest.getSession().getServletContext(); ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext); IConfigurationService configService = (IConfigurationService) context.getBean("configservice.service"); return configService.getLicenseDefaultConfiguration(SID); } catch (Exception err) { log.error("[getLicenseDefaultConfiguration]", err); } return null; }
From source file:org.i4change.app.http.javarpc.UserServiceRPC.java
public UserAuthDTO getUserSelfAutoLogin(String SID) { try {//from w w w . j a va 2 s . c o m ServletContext servletContext = this.servletRequest.getSession().getServletContext(); ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext); IUserservice userservice = (IUserservice) context.getBean("userservice.service"); return userservice.getUserSelfAutoLogin(SID); } catch (Exception err) { log.error("[getUserSelfAutoLogin]", err); } return null; }