List of usage examples for org.springframework.web.context.support WebApplicationContextUtils getRequiredWebApplicationContext
public static WebApplicationContext getRequiredWebApplicationContext(ServletContext sc) throws IllegalStateException
From source file:fr.openwide.talendalfresco.rest.server.processor.RestCommandBase.java
protected Object getBean(String name) { return WebApplicationContextUtils .getRequiredWebApplicationContext(this.httpRequest.getSession().getServletContext()).getBean(name); }
From source file:no.dusken.common.plugin.velocity.RenderPluginDirective.java
private List<PluginManager<DuskenPlugin>> getPluginManagers(InternalContextAdapter context) { if (pluginManagers == null) { InternalContextAdapter ica = context.getBaseContext(); AbstractRefreshableWebApplicationContext webApplicationContext = (AbstractRefreshableWebApplicationContext) ica .get("org.springframework.web.servlet.DispatcherServlet.CONTEXT"); ServletContext sc = webApplicationContext.getServletContext(); WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc); Map<String, PluginManager> beans = wac.getBeansOfType(PluginManager.class); pluginManagers = new LinkedList<PluginManager<DuskenPlugin>>(); //This do seem a bit strange. But I did not manage to get the casting right. for (String name : beans.keySet()) { PluginManager<DuskenPlugin> pluginManager = (PluginManager<DuskenPlugin>) wac.getBean(name); pluginManagers.add(pluginManager); }/*from w w w. j a va 2 s . com*/ } return pluginManagers; }
From source file:com.edgenius.core.webapp.filter.LocaleFilter.java
private UserReadingService getUserService() { if (userReadingService == null) { ApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServletContext()); try {//w w w. j av a 2 s. com userReadingService = (UserReadingService) ctx.getBean(UserReadingService.SERVICE_NAME); } catch (Exception e) { return null; } } return userReadingService; }
From source file:com.att.nsa.filter.ContentLengthFilter.java
/** * @see Filter#init(FilterConfig)// w w w. j a v a 2 s.co m */ public void init(FilterConfig fConfig) throws ServletException { // TODO Auto-generated method stub this.filterConfig = fConfig; log.info("Filter Content Length Initialize"); ApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(fConfig.getServletContext()); DefaultLength defLength = (DefaultLength) ctx.getBean("defLength"); DMaaPErrorMessages errorMessages = (DMaaPErrorMessages) ctx.getBean("DMaaPErrorMessages"); this.errorMessages = errorMessages; this.defaultLength = defLength; }
From source file:com.edgenius.wiki.util.WikiUtil.java
/** * @param userService// w w w . j a va2s.c om * @return */ public static User getAnonymous() { ApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(WebUtil.getServletContext()); UserReadingService userReadingService = (UserReadingService) ctx.getBean(UserReadingService.SERVICE_NAME); return userReadingService.getUserByName(null); }
From source file:com.rainbow.fw.web.taglib.CodeListTag.java
/** * ??/*w w w . j a v a 2 s .c o m*/ * * <p> * ??ApplicationContext??? "page" ??? id ? * CodeListLoader ??????? pageContext ?? * * ?????????ArrayList pageContext ?? ????? * "page" ?? * </p> * * @return ?? EVAL_BODY_INCLUDE * @throws JspException * JSP */ @Override public int doStartTag() throws JspException { if (log.isDebugEnabled()) { log.debug("doStartTag() called."); } if ("".equals(id)) { // id????? log.error("id is required."); throw new JspTagException("id is required."); } // ?ApplicationContext?? ServletContext sc = pageContext.getServletContext(); ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(sc); CodeListLoader loader = null; if (null == codeDefineList) { try { loader = ContextProvider.getBean(CodeListLoader.class); } catch (ClassCastException e) { // ???Bean?CodeListLoader?????? String errorMessage = "bean id:" + id + " is not instance of CodeListLoader."; log.error(errorMessage); throw new JspTagException(errorMessage, e); } codeDefineList = loader.getCodeBeans(id); } // List<CodeDefine> codeDefineList = loader.getCodeBeans(id); Map<String, String> cardType = new LinkedHashMap<String, String>(); for (CodeDefine codeDefine : codeDefineList) { cardType.put(codeDefine.getCodeValue(), codeDefine.getCodeKey()); } cardType = Collections.unmodifiableMap(cardType); if (cardType == null) { // codeBeanList?null???ArrayList? if (log.isWarnEnabled()) { log.warn("Codebean is null. CodeListLoader(bean id:" + id + ")"); } pageContext.setAttribute(id, new ArrayList(), PageContext.PAGE_SCOPE); } else { // ? pageContext.setAttribute(id, cardType, PageContext.PAGE_SCOPE); } return EVAL_BODY_INCLUDE; }
From source file:com.zh.snmp.snmpweb.service.SnmpWebService.java
public void init() { if (service == null) { ServletContext servletContext = (ServletContext) context.getMessageContext() .get(MessageContext.SERVLET_CONTEXT); WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); service = (SnmpService) wac.getBean("snmpService"); deviceService = (DeviceService) wac.getBean("deviceService"); configService = (ConfigService) wac.getBean("configService"); }/*from w w w. j a v a 2 s.c o m*/ }
From source file:de.tudarmstadt.ukp.csniper.webapp.page.ApplicationPageBase.java
public TaskService getTaskService() { return (TaskService) WebApplicationContextUtils .getRequiredWebApplicationContext(((WebApplication) getApplication()).getServletContext()) .getBean("taskService"); }
From source file:com.mindquarry.user.webapp.AuthenticationFilter.java
/** * @see javax.servlet.Filter#init(javax.servlet.FilterConfig) *//*from w ww . j ava2s. c o m*/ public void init(FilterConfig config) throws ServletException { ServletContext servletContext = config.getServletContext(); beanFactory_ = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); log_ = (Logger) beanFactory_.getBean(AvalonUtils.LOGGER_ROLE); realm_ = config.getInitParameter("realm"); String authenticationBeanName = Authentication.class.getName(); if (!beanFactory_.containsBean(authenticationBeanName)) { throw new ServletException( "there is no spring bean with name: " + authenticationBeanName + " available."); } }
From source file:grails.plugin.errorpagesfix.PatchedErrorHandlingServlet.java
private UrlMappingsHolder lookupUrlMappings() { WebApplicationContext wac = WebApplicationContextUtils .getRequiredWebApplicationContext(getServletContext()); return (UrlMappingsHolder) wac.getBean(UrlMappingsHolder.BEAN_ID); }