List of usage examples for org.springframework.web.context.support WebApplicationContextUtils getWebApplicationContext
@Nullable public static WebApplicationContext getWebApplicationContext(ServletContext sc)
From source file:org.parancoe.plugin.configuration.InitializerContextListener.java
@Override public void contextInitialized(ServletContextEvent evt) { log.info("parancoe-plugin-configuration contextInitialized"); WebApplicationContext webApplicationContext = WebApplicationContextUtils .getWebApplicationContext(evt.getServletContext()); Map<String, ConfigurationCollection> configurationCollections = webApplicationContext .getBeansOfType(ConfigurationCollection.class); log.info("Found " + configurationCollections.size() + " configuration collections."); for (Map.Entry<String, ConfigurationCollection> entry : configurationCollections.entrySet()) { log.info("Loading " + entry.getKey() + " configuration collection..."); ConfigurationCollection value = entry.getValue(); configurationService.initializeConfiguration(value); }//ww w . j a v a 2 s . c o m }
From source file:egovframework.rte.itl.webservice.EgovWebServiceServlet.java
public void loadBus(ServletConfig servletConfig) throws ServletException { super.loadBus(servletConfig); LOG.debug("EgovWebServiceServlet loadBus"); ApplicationContext applicationContext = WebApplicationContextUtils .getWebApplicationContext(servletConfig.getServletContext()); if (applicationContext == null) { LOG.error("applicationContext is null"); return;/*w w w.ja v a2 s . c o m*/ } EgovWebServiceContext context = null; try { context = (EgovWebServiceContext) applicationContext.getBean("egovWebServiceContext", EgovWebServiceContext.class); } catch (BeansException e) { LOG.error("Cannot get EgovWebServiceContext", e); return; } context.publishServer(bus); }
From source file:com.consol.citrus.simulator.servlet.AbstractSimulatorServlet.java
@Override public void init() throws ServletException { super.init(); ClassPathTemplateLoader loader = new ClassPathTemplateLoader(); loader.setSuffix(".html"); handlebars = new Handlebars(loader); applicationContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); applicationContext.getBean(TestListeners.class).addTestListener(this); applicationContext.getBean(TestActionListeners.class).addTestActionListener(this); applicationContext.getBean(MessageListeners.class).addMessageListener(this); }
From source file:cz.muni.fi.dndtroopsweb.security.ProtectFilter.java
/** * Provides authentication for troop part of project - as specified in class * annotation Checks whether the user exists, if the password is matching * and if the user is admin and is allowed to access this part of the app *//*from ww w.j a v a 2 s . c om*/ @Override public void doFilter(ServletRequest r, ServletResponse s, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) r; HttpServletResponse response = (HttpServletResponse) s; String auth = request.getHeader("Authorization"); if (auth == null) { response401(response); return; } String[] creds = parseAuthHeader(auth); String logname = creds[0]; String password = creds[1]; //get Spring context and UserFacade from it UserFacade userFacade = WebApplicationContextUtils.getWebApplicationContext(r.getServletContext()) .getBean(UserFacade.class); UserDTO matchingUser = userFacade.findUserByName(logname); if (matchingUser == null) { log.warn("no user with name {}", logname); response401(response); return; } UserAuthDTO userAuthDTO = new UserAuthDTO(); userAuthDTO.setUserId(matchingUser.getId()); userAuthDTO.setPassword(password); if (!userFacade.isAdmin(matchingUser)) { log.warn("user not admin {}", matchingUser); response401(response); return; } if (!userFacade.authenticate(userAuthDTO)) { log.warn("wrong credentials: user={} password={}", creds[0], creds[1]); response401(response); return; } request.setAttribute("authenticatedUser", matchingUser); chain.doFilter(request, response); }
From source file:com.thoughtworks.go.server.web.ConfigValidityFilter.java
public void init(FilterConfig config) { WebApplicationContext appContext = WebApplicationContextUtils .getWebApplicationContext(config.getServletContext()); if (this.licenseInterceptor == null) { GoLicenseService licenseService = (GoLicenseService) appContext.getBean("goLicenseService"); licenseInterceptor = new LicenseInterceptor(licenseService); }//from ww w . ja va 2 s . c o m logRequestTimings = new SystemEnvironment().getEnableRequestTimeLogging(); }
From source file:org.netxilia.server.service.user.SessionListener.java
@Override public void sessionDestroyed(HttpSessionEvent sessionEvent) { if (windowProcessor == null) { // not thread-safe but the same object is returned each time ServletContext servletContext = sessionEvent.getSession().getServletContext(); ApplicationContext springContext = WebApplicationContextUtils.getWebApplicationContext(servletContext); windowProcessor = springContext.getBean(IWindowProcessor.class); }// w w w. j a v a 2 s.co m windowProcessor.terminateSession(sessionEvent.getSession().getId()); }
From source file:com.mb.framework.web.filter.ReqRespLoggerFilter.java
/** * /* ww w . j a v a 2 s .c o m*/ * This method is not implemented */ @Override public void init(FilterConfig filterConfig) throws ServletException { ServletContext servletContext = filterConfig.getServletContext(); WebApplicationContext webApplicationContext = WebApplicationContextUtils .getWebApplicationContext(servletContext); AutowireCapableBeanFactory autowireCapableBeanFactory = webApplicationContext .getAutowireCapableBeanFactory(); autowireCapableBeanFactory.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false); logger.trace("This method implementation not needed"); }
From source file:com.telefonica.euro_iaas.sdc.bootstrap.PropertiesLoaderBootstrap.java
/** * {@inheritDoc}/* w ww .java 2 s. c o m*/ */ public void contextInitialized(ServletContextEvent event) { WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext()); EntityManagerFactory emf = (EntityManagerFactory) ctx.getBean("entityManagerFactory"); PropertiesProvider propertiesProvider = new PropertiesProviderFactoryImpl().createPropertiesProvider(emf); Properties properties = propertiesProvider.load(NAMESPACE); try { log.info("store namespace: " + NAMESPACE); propertiesProvider.store(properties, NAMESPACE); } catch (Exception e) { throw new SdcRuntimeException(e); } }
From source file:com.orangeandbronze.jblubble.sample.UploadServlet.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); applicationContext = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext()); blobstoreService = applicationContext.getBean(BlobstoreService.class); blobKeys = new LinkedList<>(); }
From source file:org.smigo.config.RequestLogFilter.java
@Override public void init(FilterConfig config) throws ServletException { ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext()); logHandler = ctx.getBean(LogHandler.class); }