List of usage examples for org.springframework.web.context WebApplicationContext getBean
<T> T getBean(String name, Class<T> requiredType) throws BeansException;
From source file:org.echocat.nodoodle.server.ServiceServlet.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); final WebApplicationContext applicationContext = WebApplicationContextUtils .getWebApplicationContext(config.getServletContext()); final String serviceName = config.getInitParameter(SERVICE_PARAM); if (StringUtils.isEmpty(serviceName)) { throw new ServletException("Required initParam " + SERVICE_PARAM + " not set."); }/*w w w .ja v a 2s. c om*/ try { _service = applicationContext.getBean(serviceName, HttpService.class); } catch (NoSuchBeanDefinitionException e) { throw new ServletException("No service '" + serviceName + "' (defined under initParam '" + SERVICE_PARAM + "') could not be found.", e); } try { _service.init(config.getServletContext()); } catch (Exception e) { throw new ServletException("Could not initiate the service: " + _service, e); } }
From source file:net.mlw.vlh.web.tag.ValueListSpaceTag.java
/** * @param configName The config to set./*from w w w. ja v a2 s.co m*/ */ public void setConfigName(String configName) { try { WebApplicationContext context = WebApplicationContextUtils .getWebApplicationContext(pageContext.getServletContext()); config = (ValueListConfigBean) context.getBean(configName, ValueListConfigBean.class); } catch (BeansException e) { config = null; LOGGER.error("Check spelling of the config='" + configName + "' Error: " + e.getMessage()); } }
From source file:com.jaspersoft.jasperserver.war.tags.JasperViewerTag.java
protected DataCacheProvider getDataCacheProvider() { WebApplicationContext applicationContext = getRequestContext().getWebApplicationContext(); DataCacheProvider dataCacheProvider = applicationContext.getBean(DATA_CACHE_PROVIDER_BEAN_NAME, DataCacheProvider.class); return dataCacheProvider; }
From source file:net.sourceforge.vulcan.web.struts.RestRequestProcessor.java
@Override public void init(ActionServlet servlet, ModuleConfig moduleConfig) throws ServletException { super.init(servlet, moduleConfig); final WebApplicationContext wac = WebApplicationContextUtils .getRequiredWebApplicationContext(servlet.getServletContext()); this.restRequestDetector = (RestRequestDetector) wac.getBean("restRequestDetector", RestRequestDetector.class); }
From source file:com.jaspersoft.jasperserver.war.tags.JasperViewerTag.java
protected SessionObjectSerieAccessor getJasperPrintAccessor() { WebApplicationContext applicationContext = getRequestContext().getWebApplicationContext(); SessionObjectSerieAccessor jasperPrintAccessor = (SessionObjectSerieAccessor) applicationContext .getBean(JASPER_PRINT_ACCESSOR_BEAN_NAME, SessionObjectSerieAccessor.class); return jasperPrintAccessor; }
From source file:com.jaspersoft.jasperserver.war.tags.JasperViewerTag.java
protected WebflowReportContextAccessor getReportContextAccessor() { WebApplicationContext applicationContext = getRequestContext().getWebApplicationContext(); WebflowReportContextAccessor contextAccessor = (WebflowReportContextAccessor) applicationContext .getBean(REPORT_CONTEXT_ACCESSOR_BEAN_NAME, WebflowReportContextAccessor.class); return contextAccessor; }
From source file:org.ws13.vaadin.osgi.dm.app.SpringApplicationServlet.java
/** * Get the application bean in Spring's context. * /* w ww . j av a 2s. co m*/ * @see AbstractApplicationServlet#getNewApplication(HttpServletRequest) */ @Override protected Application getNewApplication(HttpServletRequest request) throws ServletException { WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); if (wac == null) { throw new ServletException("Cannot get an handle on Spring's context. Is Spring running?" + "Check there's an org.springframework.web.context.ContextLoaderListener configured."); } String[] beanDefinitionNames = wac.getBeanDefinitionNames(); for (String string : beanDefinitionNames) { System.out.println("SpringApplicationServlet.getNewApplication() ->" + string); } Application bean = wac.getBean(name, Application.class); if (!(bean instanceof Application)) { throw new ServletException("Bean " + name + " is not of expected class Application"); } return bean; }
From source file:org.ws13.vaadin.osgi.dm.app.SpringApplicationServlet.java
/** * Get the application class from the bean configured in Spring's context. * //w ww. j ava 2 s .c o m * @see AbstractApplicationServlet#getApplicationClass() */ @Override protected Class<? extends Application> getApplicationClass() throws ClassNotFoundException { WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); if (wac == null) { throw new ClassNotFoundException("Cannot get an handle on Spring's context. Is Spring running? " + "Check there's an org.springframework.web.context.ContextLoaderListener configured."); } String[] beanDefinitionNames = wac.getBeanDefinitionNames(); for (String string : beanDefinitionNames) { System.out.println("SpringApplicationServlet.getApplicationClass() " + string); } Application bean = wac.getBean(name, Application.class); if (bean == null) { throw new ClassNotFoundException("No application bean found under name " + name); } return bean.getClass(); }
From source file:com.qut.middleware.esoe.authn.servlet.AuthnServlet.java
@Override public void init() throws ServletException { FileInputStream configFile;/*from w w w . j a va 2s .c o m*/ Properties props; WebApplicationContext webAppContext; try { configFile = new FileInputStream(System.getProperty("esoe.data") + ConfigurationConstants.ESOE_CONFIG); props = new java.util.Properties(); props.load(configFile); /* Spring integration to make our servlet aware of IoC */ webAppContext = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext()); this.authnProcessor = (AuthnProcessor) webAppContext.getBean(ConfigurationConstants.AUTHN_PROCESSOR, com.qut.middleware.esoe.authn.AuthnProcessor.class); if (this.authnProcessor == null) { this.logger.error(MessageFormat.format(Messages.getString("AuthnServlet.1"), //$NON-NLS-1$ ConfigurationConstants.AUTHN_PROCESSOR)); throw new IllegalArgumentException( Messages.getString("AuthnServlet.1") + ConfigurationConstants.AUTHN_PROCESSOR); //$NON-NLS-1$ } this.authnDynamicURLParam = props.getProperty(ConfigurationConstants.AUTHN_DYNAMIC_URL_PARAM); this.sessionTokenName = props.getProperty(ConfigurationConstants.ESOE_SESSION_TOKEN_NAME); this.sessionDomain = props.getProperty(ConfigurationConstants.ESOE_SESSION_DOMAIN); this.disableSSOTokenName = props.getProperty(ConfigurationConstants.DISABLE_SSO_TOKEN_NAME); if (this.authnDynamicURLParam == null) { this.logger.error(Messages.getString("AuthnServlet.10") //$NON-NLS-1$ + ConfigurationConstants.AUTHN_DYNAMIC_URL_PARAM + Messages.getString("AuthnServlet.11")); //$NON-NLS-1$ throw new IllegalArgumentException(Messages.getString("AuthnServlet.10") //$NON-NLS-1$ + ConfigurationConstants.AUTHN_DYNAMIC_URL_PARAM + Messages.getString("AuthnServlet.11")); //$NON-NLS-1$ } if (this.sessionTokenName == null) { this.logger.error(Messages.getString("AuthnServlet.10") //$NON-NLS-1$ + ConfigurationConstants.ESOE_SESSION_TOKEN_NAME + Messages.getString("AuthnServlet.11")); //$NON-NLS-1$ throw new IllegalArgumentException(Messages.getString("AuthnServlet.10") //$NON-NLS-1$ + ConfigurationConstants.ESOE_SESSION_TOKEN_NAME + Messages.getString("AuthnServlet.11")); //$NON-NLS-1$ } if (this.sessionDomain == null) { this.logger.error(Messages.getString("AuthnServlet.10") //$NON-NLS-1$ + ConfigurationConstants.ESOE_SESSION_DOMAIN + Messages.getString("AuthnServlet.11")); //$NON-NLS-1$ throw new IllegalArgumentException(Messages.getString("AuthnServlet.10") //$NON-NLS-1$ + ConfigurationConstants.ESOE_SESSION_DOMAIN + Messages.getString("AuthnServlet.11")); //$NON-NLS-1$ } if (this.disableSSOTokenName == null) { this.logger.error(Messages.getString("AuthnServlet.10") //$NON-NLS-1$ + ConfigurationConstants.DISABLE_SSO_TOKEN_NAME + Messages.getString("AuthnServlet.11")); //$NON-NLS-1$ throw new IllegalArgumentException(Messages.getString("AuthnServlet.10") //$NON-NLS-1$ + ConfigurationConstants.DISABLE_SSO_TOKEN_NAME + Messages.getString("AuthnServlet.11")); //$NON-NLS-1$ } this.logger.info(Messages.getString("AuthnServlet.33")); //$NON-NLS-1$ } catch (BeansException e) { this.logger.error(MessageFormat.format(Messages.getString("AuthnServlet.12"), //$NON-NLS-1$ ConfigurationConstants.AUTHN_PROCESSOR, e.getLocalizedMessage())); throw new ServletException(MessageFormat.format(Messages.getString("AuthnServlet.12"), //$NON-NLS-1$ ConfigurationConstants.AUTHN_PROCESSOR, e.getLocalizedMessage())); } catch (MalformedURLException e) { this.logger.error(Messages.getString("AuthnServlet.14") //$NON-NLS-1$ + ConfigurationConstants.ESOE_CONFIG + Messages.getString("AuthnServlet.15") //$NON-NLS-1$ + e.getLocalizedMessage()); throw new ServletException(Messages.getString("AuthnServlet.14") //$NON-NLS-1$ + ConfigurationConstants.ESOE_CONFIG + Messages.getString("AuthnServlet.15")); //$NON-NLS-1$ } catch (IllegalStateException e) { this.logger.error(Messages.getString("AuthnServlet.16") + e.getLocalizedMessage()); //$NON-NLS-1$ throw new ServletException(Messages.getString("AuthnServlet.16")); //$NON-NLS-1$ } catch (IOException e) { this.logger.error(Messages.getString("AuthnServlet.17") //$NON-NLS-1$ + ConfigurationConstants.ESOE_CONFIG + Messages.getString("AuthnServlet.18") //$NON-NLS-1$ + e.getLocalizedMessage()); throw new ServletException(Messages.getString("AuthnServlet.17") //$NON-NLS-1$ + ConfigurationConstants.ESOE_CONFIG + Messages.getString("AuthnServlet.18")); //$NON-NLS-1$ } }
From source file:de.itsvs.cwtrpc.controller.CacheControlFilter.java
public void init(FilterConfig filterConfig) throws ServletException { final WebApplicationContext applicationContext; final CacheControlConfig config; final List<CacheControlUriConfig> uriConfigs; String configBeanName;//from w w w . j ava2 s . co m configBeanName = filterConfig.getInitParameter(CONFIG_BEAN_NAME_INIT_PARAM); if (configBeanName == null) { configBeanName = CacheControlConfig.DEFAULT_BEAN_ID; } applicationContext = WebApplicationContextUtils.getWebApplicationContext(filterConfig.getServletContext()); if (log.isDebugEnabled()) { log.debug("Resolving cache control config with bean name '" + configBeanName + "' from application context"); } config = applicationContext.getBean(configBeanName, CacheControlConfig.class); setLowerCaseMatch(config.isLowerCaseMatch()); uriConfigs = new ArrayList<CacheControlUriConfig>(); if (config.isDefaultsEnabled()) { log.debug("Adding default URI configurations"); uriConfigs.addAll(createDefaultUriConfigs(config)); } uriConfigs.addAll(config.getUriConfigs()); setUriConfigs(createCacheControlUriConfigBuilder().build(uriConfigs)); }