List of usage examples for org.springframework.web.context.support WebApplicationContextUtils getRequiredWebApplicationContext
public static WebApplicationContext getRequiredWebApplicationContext(ServletContext sc) throws IllegalStateException
From source file:com.expressui.core.util.SpringApplicationServlet.java
@Override public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); log.debug("initializing SpringApplicationServlet"); try {/*from w w w. java 2 s . com*/ webApplicationContext = WebApplicationContextUtils .getRequiredWebApplicationContext(servletConfig.getServletContext()); } catch (IllegalStateException e) { throw new ServletException(e); } }
From source file:org.openxdata.server.servlet.FormDownloadServlet.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); ServletContext sctx = this.getServletContext(); WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(sctx); // Manual Injection formsServer = (FormsServer) ctx.getBean("formsServer"); userService = (UserService) ctx.getBean("userService"); formDownloadService = (FormDownloadService) ctx.getBean("formDownloadService"); serializationService = (SerializationService) ctx.getBean("serializationService"); authenticationService = (AuthenticationService) ctx.getBean("authenticationService"); }
From source file:de.fhg.igd.vaadin.util.VaadinUtil.java
/** * can only be used if the Vaadin Application has been set with {@link VaadinUtil#setApplication()} * during a still running request/*from w ww . j a va 2 s. c o m*/ * this does not work outside of the request thread * */ public static ApplicationContext getSpringApplicationContext() { return WebApplicationContextUtils .getRequiredWebApplicationContext(getServletContext(getApplicationInstance())); }
From source file:gov.nih.nci.cadsr.formloader.struts2.ValidateFormsAction.java
private void validateFormCollection(FormCollection aColl) { applicationContext = WebApplicationContextUtils .getRequiredWebApplicationContext(ServletActionContext.getServletContext()); ContentValidationServiceImpl xmlContentValidator = (ContentValidationServiceImpl) this.applicationContext .getBean("contentValidationService"); try {/* w ww. ja va 2 s .c o m*/ validatedFormCollection = xmlContentValidator.validateXmlContent(aColl); validatedForms = extractValidedForms(validatedFormCollection); if (validatedForms.size() == 0) addActionError("All your forms failed DB validation"); servletRequest.getSession().setAttribute("formCollection", aColl); logger.debug(validatedForms.size() + " Forms selected for validation"); } catch (FormLoaderServiceException e) { addActionError("Got FormLoaderServiceException: " + e.getMessage()); } }
From source file:org.ringojs.jsgi.ExtJsgiServlet.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); _servletContext = config.getServletContext(); _springContext = WebApplicationContextUtils.getRequiredWebApplicationContext(_servletContext); // Hacky way of shoving an object into the System properties LOG.info("Injecting spring context into Java system property [{}]", PROP_SPRING_CONTEXT); System.getProperties().put(PROP_SPRING_CONTEXT, _springContext); // Hacky way of shoving the current servlet instance into System properties LOG.info("Injecting this servlet into Java system property [{}]", PROP_SERVLET); System.getProperties().put(PROP_SERVLET, this); }
From source file:com.wikipy.security.AuthenticationFilter.java
@Override public void init(FilterConfig config) throws ServletException { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(config.getServletContext()); userService = (BasicUserService) ctx.getBean("userService"); cacheService = (EhCacheService) ctx.getBean("cacheService"); }
From source file:net.sourceforge.vulcan.web.ProjectFileServlet.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); final WebApplicationContext wac = WebApplicationContextUtils .getRequiredWebApplicationContext(config.getServletContext()); projectManager = (ProjectManager) wac.getBean(Keys.PROJECT_MANAGER); buildManager = (BuildManager) wac.getBean(Keys.BUILD_MANAGER); }
From source file:com.sun.xml.ws.transport.http.servlet.GrailsWsServlet.java
@Override public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); // get the configured adapters from Spring, they may come from two different contexts WebApplicationContext wac = WebApplicationContextUtils .getRequiredWebApplicationContext(getServletContext()); ApplicationContext ac = Holders.getGrailsApplication().getParentContext(); Set<SpringBinding> bindings = new LinkedHashSet<SpringBinding>(); // backward compatibility. recognize all bindings Map m = ac.getBeansOfType(SpringBindingList.class); for (SpringBindingList sbl : (Collection<SpringBindingList>) m.values()) bindings.addAll(sbl.getBindings()); m = wac.getBeansOfType(SpringBindingList.class); for (SpringBindingList sbl : (Collection<SpringBindingList>) m.values()) bindings.addAll(sbl.getBindings()); bindings.addAll(ac.getBeansOfType(SpringBinding.class).values()); bindings.addAll(wac.getBeansOfType(SpringBinding.class).values()); // create adapters ServletAdapterList l = new ServletAdapterList(); for (SpringBinding binding : bindings) binding.create(l);//from w w w.jav a 2 s . c om delegate = new WSServletDelegate(l, getServletContext()); }
From source file:nijhof2axon.ui.AutowiringApplicationServlet.java
/** * Initialize this servlet./*from w w w. j av a 2s . c om*/ * * @throws ServletException if there is no {@link WebApplicationContext} associated with this servlet's context */ @Override public void init(ServletConfig config) throws ServletException { super.init(config); log.debug("finding containing WebApplicationContext"); try { this.webApplicationContext = WebApplicationContextUtils .getRequiredWebApplicationContext(config.getServletContext()); } catch (IllegalStateException e) { throw new ServletException("could not locate containing WebApplicationContext"); } }
From source file:org.openmrs.contrib.metadatarepository.webapp.listener.StartupListener.java
/** * {@inheritDoc}/* ww w.ja va2 s . c o m*/ */ @SuppressWarnings("unchecked") public void contextInitialized(ServletContextEvent event) { log.debug("Initializing context..."); ServletContext context = event.getServletContext(); // Orion starts Servlets before Listeners, so check if the config // object already exists Map<String, Object> config = (HashMap<String, Object>) context.getAttribute(Constants.CONFIG); if (config == null) { config = new HashMap<String, Object>(); } if (context.getInitParameter(Constants.CSS_THEME) != null) { config.put(Constants.CSS_THEME, context.getInitParameter(Constants.CSS_THEME)); } ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context); /*String[] beans = ctx.getBeanDefinitionNames(); for (String bean : beans) { log.debug(bean); }*/ PasswordEncoder passwordEncoder = null; try { ProviderManager provider = (ProviderManager) ctx .getBean("org.springframework.security.authentication.ProviderManager#0"); for (Object o : provider.getProviders()) { AuthenticationProvider p = (AuthenticationProvider) o; if (p instanceof RememberMeAuthenticationProvider) { config.put("rememberMeEnabled", Boolean.TRUE); } else if (ctx.getBean("passwordEncoder") != null) { passwordEncoder = (PasswordEncoder) ctx.getBean("passwordEncoder"); } } } catch (NoSuchBeanDefinitionException n) { log.debug("authenticationManager bean not found, assuming test and ignoring..."); // ignore, should only happen when testing } context.setAttribute(Constants.CONFIG, config); // output the retrieved values for the Init and Context Parameters if (log.isDebugEnabled()) { log.debug("Remember Me Enabled? " + config.get("rememberMeEnabled")); if (passwordEncoder != null) { log.debug("Password Encoder: " + passwordEncoder.getClass().getSimpleName()); } log.debug("Populating drop-downs..."); } setupContext(context); }