/** * Register ServletContextAwareProcessor. * @see ServletContextAwareProcessor */ @Override protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { beanFactory.addBeanPostProcessor(new ServletContextAwareProcessor(this.servletContext)); beanFactory.ignoreDependencyInterface(ServletContextAware.class); WebApplicationContextUtils.registerWebApplicationScopes(beanFactory, this.servletContext); WebApplicationContextUtils.registerEnvironmentBeans(beanFactory, this.servletContext); }
/** * Register request/session scopes, a {@link ServletContextAwareProcessor}, etc. */ @Override protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { beanFactory.addBeanPostProcessor(new ServletContextAwareProcessor(this.servletContext, this.servletConfig)); beanFactory.ignoreDependencyInterface(ServletContextAware.class); beanFactory.ignoreDependencyInterface(ServletConfigAware.class); WebApplicationContextUtils.registerWebApplicationScopes(beanFactory, this.servletContext); WebApplicationContextUtils.registerEnvironmentBeans(beanFactory, this.servletContext, this.servletConfig); }
@Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (getServletContext() != null && bean instanceof ServletContextAware) { ((ServletContextAware) bean).setServletContext(getServletContext()); } if (getServletConfig() != null && bean instanceof ServletConfigAware) { ((ServletConfigAware) bean).setServletConfig(getServletConfig()); } return bean; }
/** * Register request/session scopes, a {@link PortletContextAwareProcessor}, etc. */ @Override protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { beanFactory.addBeanPostProcessor(new ServletContextAwareProcessor(this.servletContext)); beanFactory.addBeanPostProcessor(new PortletContextAwareProcessor(this.portletContext, this.portletConfig)); beanFactory.ignoreDependencyInterface(ServletContextAware.class); beanFactory.ignoreDependencyInterface(PortletContextAware.class); beanFactory.ignoreDependencyInterface(PortletConfigAware.class); PortletApplicationContextUtils.registerPortletApplicationScopes(beanFactory, this.portletContext); PortletApplicationContextUtils.registerEnvironmentBeans( beanFactory, this.servletContext, this.portletContext, this.portletConfig); }
@Override public void setServletContext(ServletContext servletContext) { for (ViewResolver viewResolver : this.viewResolvers) { if (viewResolver instanceof ServletContextAware) { ((ServletContextAware)viewResolver).setServletContext(servletContext); } } }
@Override public void setServletContext(ServletContext servletContext) { RequestUpgradeStrategy strategy = getRequestUpgradeStrategy(); if (strategy instanceof ServletContextAware) { ((ServletContextAware) strategy).setServletContext(servletContext); } }
@Override protected void initServletContext(ServletContext servletContext) { for (Object handler : getUrlMap().values()) { if (handler instanceof ServletContextAware) { ((ServletContextAware) handler).setServletContext(servletContext); } } }
@Override public void setServletContext(ServletContext servletContext) { for (TransportHandler handler : getTransportHandlers().values()) { if (handler instanceof ServletContextAware) { ((ServletContextAware) handler).setServletContext(servletContext); } } }
/** * Register ServletContextAwareProcessor. * @see ServletContextAwareProcessor */ @Override protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { beanFactory.addBeanPostProcessor( new WebApplicationContextServletContextAwareProcessor(this)); beanFactory.ignoreDependencyInterface(ServletContextAware.class); }
@Test public void servletContextAwareBeansAreInjected() throws Exception { addEmbeddedServletContainerFactoryBean(); ServletContextAware bean = mock(ServletContextAware.class); this.context.registerBeanDefinition("bean", beanDefinition(bean)); this.context.refresh(); verify(bean).setServletContext( getEmbeddedServletContainerFactory().getServletContext()); }
/** * Registers the {@code Lifecycle}, {@code Phased} and * {@code ServletContextAware} aspects of the specified instance. * * @param instance the object to examine, not null */ private void registerInstanceInterfaces0(Object instance) { if (instance instanceof Lifecycle) { registerLifecycle0((Lifecycle) instance); } else { findAndRegisterLifeCycle(instance); } if (instance instanceof ServletContextAware) { registerServletContextAware0((ServletContextAware) instance); } }
/** * Registers a non-component object implementing {@code Lifecycle}. * <p> * Certain interfaces are automatically detected. * If it implements {@code InitializingBean}, then it will be initialized * as though using {@link #initialize(InitializingBean)}. * * @param servletContextAware the object that requires a servlet context, not null * @throws OpenGammaRuntimeException if an error occurs */ public void registerServletContextAware(ServletContextAware servletContextAware) { ArgumentChecker.notNull(servletContextAware, "servletContextAware"); checkStatus(Status.CREATING); try { initialize0(servletContextAware); registerServletContextAware0(servletContextAware); _logger.logDebug(" Registered lifecycle-stop: " + servletContextAware); } catch (RuntimeException ex) { _status.set(Status.FAILED); throw new OpenGammaRuntimeException("Failed during registering ServletContextAware: " + servletContextAware, ex); } }
/** * Sets the {@code ServletContext}. * * @param servletContext the servlet context, not null */ @Override public void setServletContext(ServletContext servletContext) { servletContext.setAttribute(SERVLET_CONTEXT_KEY, this); for (ServletContextAware obj : _servletContextAware) { obj.setServletContext(servletContext); } }
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (this.servletContext != null && bean instanceof ServletContextAware) { ((ServletContextAware) bean).setServletContext(this.servletContext); } if (this.servletConfig != null && bean instanceof ServletConfigAware) { ((ServletConfigAware) bean).setServletConfig(this.servletConfig); } return bean; }
/** * {@inheritDoc} * * Registers request/session scopes, a {@link ServletContextAwareProcessor}, * etc. */ protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { super.postProcessBeanFactory(beanFactory); beanFactory.addBeanPostProcessor(new ServletContextAwareProcessor(this.servletContext, this.servletConfig)); beanFactory.ignoreDependencyInterface(ServletContextAware.class); beanFactory.ignoreDependencyInterface(ServletConfigAware.class); beanFactory.registerResolvableDependency(ServletContext.class, this.servletContext); beanFactory.registerResolvableDependency(ServletConfig.class, this.servletConfig); WebApplicationContextUtils.registerWebApplicationScopes(beanFactory); }
public void testPostProcessBeanFactoryConfigurableListableBeanFactory() { ConfigurableListableBeanFactory mock = new DefaultListableBeanFactory() { public void ignoreDependencyInterface(Class ifc) { ignored.add(ifc); } public void addBeanPostProcessor(BeanPostProcessor beanPostProcessor) { super.addBeanPostProcessor(beanPostProcessor); bpp.add(beanPostProcessor.getClass()); } public void registerResolvableDependency(Class dependencyType, Object autowiredValue) { super.registerResolvableDependency(dependencyType, autowiredValue); resolved.add(dependencyType); } }; context.postProcessBeanFactory(mock); assertTrue(ignored.contains(ServletConfigAware.class)); assertTrue(ignored.contains(ServletContextAware.class)); assertTrue(resolved.contains(ServletContext.class)); assertTrue(resolved.contains(ServletConfig.class)); assertTrue(bpp.contains(ServletContextAwareProcessor.class)); }
@Override public void setServletContext(ServletContext servletContext) { if (this.handshakeHandler instanceof ServletContextAware) { ((ServletContextAware) this.handshakeHandler).setServletContext(servletContext); } }
@Override public void init(ComponentRepository repo, LinkedHashMap<String, String> configuration) { final LongPollingConnectionManager longPolling = buildLongPolling(); ChangeManager changeMgr = buildChangeManager(); MasterChangeManager masterChangeMgr = buildMasterChangeManager(); final ConnectionManagerImpl connectionMgr = new ConnectionManagerImpl(changeMgr, masterChangeMgr, longPolling); AggregatorNamesResource aggregatorsResource = new AggregatorNamesResource(getPortfolioAggregationFunctions().getMappedFunctions().keySet()); MarketDataSnapshotListResource snapshotResource = new MarketDataSnapshotListResource(getMarketDataSnapshotMaster()); MasterConfigSource configSource = new MasterConfigSource(getConfigMaster()); AggregatedViewDefinitionManager aggregatedViewDefManager = new AggregatedViewDefinitionManager(getPositionSource(), getSecuritySource(), getCombinedConfigSource(), getUserConfigMaster(), getUserPortfolioMaster(), getUserPositionMaster(), getPortfolioAggregationFunctions().getMappedFunctions()); CurrencyPairsSource currencyPairsSource = new ConfigDBCurrencyPairsSource(configSource); // TODO should be able to configure the currency pairs CurrencyPairs currencyPairs = currencyPairsSource.getCurrencyPairs(CurrencyPairs.DEFAULT_CURRENCY_PAIRS); SecurityAttributeMapper blotterColumnMapper = DefaultSecurityAttributeMappings.create(currencyPairs); AnalyticsViewManager analyticsViewManager = new AnalyticsViewManager(getViewProcessor(), getParallelViewRecompilation(), aggregatedViewDefManager, getComputationTargetResolver(), getFunctionRepository(), getMarketDataSpecificationRepository(), blotterColumnMapper, getPositionSource(), getCombinedConfigSource(), getSecuritySource(), getSecurityMaster(), getPositionMaster()); ResultsFormatter resultsFormatter = new ResultsFormatter(_suppressCurrencyDisplay ? SUPPRESS_CURRENCY : DISPLAY_CURRENCY); GridColumnsJsonWriter columnWriter = new GridColumnsJsonWriter(resultsFormatter); ViewportResultsJsonCsvWriter viewportResultsWriter = new ViewportResultsJsonCsvWriter(resultsFormatter); repo.getRestComponents().publishResource(aggregatorsResource); repo.getRestComponents().publishResource(snapshotResource); if (getMarketDataSpecificationRepository() != null) { repo.getRestComponents().publishResource(new LiveMarketDataSpecificationNamesResource(getMarketDataSpecificationRepository())); } else { repo.getRestComponents().publishResource(new LiveMarketDataProviderNamesResource(getLiveMarketDataProviderFactory())); } repo.getRestComponents().publishResource(new WebUiResource(analyticsViewManager, connectionMgr)); repo.getRestComponents().publishResource(new Compressor()); repo.getRestComponents().publishResource(new LogResource()); repo.getRestComponents().publishResource(new UserResource()); repo.getRestComponents().publishResource(new BlotterResource(getSecurityMaster(), getPortfolioMaster(), getPositionMaster())); repo.getRestComponents().publishResource(new TimeSeriesResolverKeysResource(getConfigMaster())); repo.getRestComponents().publishHelper(new PrimitivesGridStructureMessageBodyWriter(columnWriter)); repo.getRestComponents().publishHelper(new PortfolioGridStructureMessageBodyWriter(columnWriter)); repo.getRestComponents().publishHelper(new DependencyGraphGridStructureMessageBodyWriter(columnWriter)); repo.getRestComponents().publishHelper(new ValueRequirementMessageBodyWriter()); repo.getRestComponents().publishHelper(new GridColumnGroupsMessageBodyWriter(columnWriter)); repo.getRestComponents().publishHelper(new ViewportResultsMessageBodyWriter(viewportResultsWriter)); repo.getRestComponents().publishHelper(new ViewDefinitionEntriesResource(configSource)); repo.getRestComponents().publishHelper(new ErrorInfoMessageBodyWriter()); // these items need to be available to the servlet, but aren't important enough to be published components repo.registerServletContextAware(new ServletContextAware() { @Override public void setServletContext(ServletContext servletContext) { WebPushServletContextUtils.setConnectionManager(servletContext, connectionMgr); WebPushServletContextUtils.setLongPollingConnectionManager(servletContext, longPolling); } }); }
@Override public void setServletContext(ServletContext servletContext) { if (this.sockJsService instanceof ServletContextAware) { ((ServletContextAware) this.sockJsService).setServletContext(servletContext); } }
/** * Registers a {@code ServletContextAware} instance. * * @param servletContextAware the object that requires a servlet context, not null */ private void registerServletContextAware0(ServletContextAware servletContextAware) { _servletContextAware.add(servletContextAware); }
/** * Check if the controller implements {@link ServletContextAware} and set the servlet context * * @param controller * the controller to set the servlet context */ private void setServletContext(Controller controller) { if (controller instanceof ServletContextAware) { ((ServletContextAware) controller).setServletContext(this.getServletContext()); } }