/** * Replace {@code Servlet}-based {@link StubPropertySource stub property sources} with * actual instances populated with the given {@code servletContext} and * {@code servletConfig} objects. * <p>This method is idempotent with respect to the fact it may be called any number * of times but will perform replacement of stub property sources with their * corresponding actual property sources once and only once. * @param sources the {@link MutablePropertySources} to initialize (must not * be {@code null}) * @param servletContext the current {@link ServletContext} (ignored if {@code null} * or if the {@link StandardServletEnvironment#SERVLET_CONTEXT_PROPERTY_SOURCE_NAME * servlet context property source} has already been initialized) * @param servletConfig the current {@link ServletConfig} (ignored if {@code null} * or if the {@link StandardServletEnvironment#SERVLET_CONFIG_PROPERTY_SOURCE_NAME * servlet config property source} has already been initialized) * @see org.springframework.core.env.PropertySource.StubPropertySource * @see org.springframework.core.env.ConfigurableEnvironment#getPropertySources() */ public static void initServletPropertySources(MutablePropertySources sources, @Nullable ServletContext servletContext, @Nullable ServletConfig servletConfig) { Assert.notNull(sources, "'propertySources' must not be null"); String name = StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME; if (servletContext != null && sources.contains(name) && sources.get(name) instanceof StubPropertySource) { sources.replace(name, new ServletContextPropertySource(name, servletContext)); } name = StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME; if (servletConfig != null && sources.contains(name) && sources.get(name) instanceof StubPropertySource) { sources.replace(name, new ServletConfigPropertySource(name, servletConfig)); } }
/** * Replace {@code Servlet}-based {@link StubPropertySource stub property sources} with * actual instances populated with the given {@code servletContext} and * {@code servletConfig} objects. * <p>This method is idempotent with respect to the fact it may be called any number * of times but will perform replacement of stub property sources with their * corresponding actual property sources once and only once. * @param sources the {@link MutablePropertySources} to initialize (must not * be {@code null}) * @param servletContext the current {@link ServletContext} (ignored if {@code null} * or if the {@link StandardServletEnvironment#SERVLET_CONTEXT_PROPERTY_SOURCE_NAME * servlet context property source} has already been initialized) * @param servletConfig the current {@link ServletConfig} (ignored if {@code null} * or if the {@link StandardServletEnvironment#SERVLET_CONFIG_PROPERTY_SOURCE_NAME * servlet config property source} has already been initialized) * @see org.springframework.core.env.PropertySource.StubPropertySource * @see org.springframework.core.env.ConfigurableEnvironment#getPropertySources() */ public static void initServletPropertySources(MutablePropertySources sources, @Nullable ServletContext servletContext, @Nullable ServletConfig servletConfig) { Assert.notNull(sources, "'propertySources' must not be null"); String name = StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME; if (servletContext != null && sources.contains(name) && sources.get(name) instanceof StubPropertySource) { sources.replace(name, new ServletContextPropertySource(name, servletContext)); } name = StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME; if (servletConfig != null && sources.contains(name) && sources.get(name) instanceof StubPropertySource) { sources.replace(name, new ServletConfigPropertySource(name, servletConfig)); } }
/** * Replace {@code Servlet}-based {@link StubPropertySource stub property sources} with * actual instances populated with the given {@code servletContext} and * {@code servletConfig} objects. * <p>This method is idempotent with respect to the fact it may be called any number * of times but will perform replacement of stub property sources with their * corresponding actual property sources once and only once. * @param sources the {@link MutablePropertySources} to initialize (must not * be {@code null}) * @param servletContext the current {@link ServletContext} (ignored if {@code null} * or if the {@link StandardServletEnvironment#SERVLET_CONTEXT_PROPERTY_SOURCE_NAME * servlet context property source} has already been initialized) * @param servletConfig the current {@link ServletConfig} (ignored if {@code null} * or if the {@link StandardServletEnvironment#SERVLET_CONFIG_PROPERTY_SOURCE_NAME * servlet config property source} has already been initialized) * @see org.springframework.core.env.PropertySource.StubPropertySource * @see org.springframework.core.env.ConfigurableEnvironment#getPropertySources() */ public static void initServletPropertySources(MutablePropertySources sources, @Nullable ServletContext servletContext, @Nullable ServletConfig servletConfig) { Assert.notNull(sources, "'propertySources' must not be null"); String name = StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME; if (servletContext != null && sources.contains(name) && sources.get(name) instanceof StubPropertySource) { sources.replace(name, new ServletContextPropertySource(name, servletContext)); } name = StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME; if (servletConfig != null && sources.contains(name) && sources.get(name) instanceof StubPropertySource) { sources.replace(name, new ServletConfigPropertySource(name, servletConfig)); } }
/** * Replace {@code Servlet}-based {@link StubPropertySource stub property sources} with * actual instances populated with the given {@code servletContext} and * {@code servletConfig} objects. * <p>This method is idempotent with respect to the fact it may be called any number * of times but will perform replacement of stub property sources with their * corresponding actual property sources once and only once. * @param sources the {@link MutablePropertySources} to initialize (must not * be {@code null}) * @param servletContext the current {@link ServletContext} (ignored if {@code null} * or if the {@link StandardServletEnvironment#SERVLET_CONTEXT_PROPERTY_SOURCE_NAME * servlet context property source} has already been initialized) * @param servletConfig the current {@link ServletConfig} (ignored if {@code null} * or if the {@link StandardServletEnvironment#SERVLET_CONFIG_PROPERTY_SOURCE_NAME * servlet config property source} has already been initialized) * @see org.springframework.core.env.PropertySource.StubPropertySource * @see org.springframework.core.env.ConfigurableEnvironment#getPropertySources() */ public static void initServletPropertySources(MutablePropertySources sources, @Nullable ServletContext servletContext, @Nullable ServletConfig servletConfig) { Assert.notNull(sources, "'propertySources' must not be null"); String name = StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME; if (servletContext != null && sources.contains(name) && sources.get(name) instanceof StubPropertySource) { sources.replace(name, new ServletContextPropertySource(name, servletContext)); } name = StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME; if (servletConfig != null && sources.contains(name) && sources.get(name) instanceof StubPropertySource) { sources.replace(name, new ServletConfigPropertySource(name, servletConfig)); } }
public final void init(FilterConfig filterConfig) throws ServletException { Assert.notNull(filterConfig, "FilterConfig must not be null"); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Initializing filter '" + filterConfig.getFilterName() + "'"); } initPlaceHolderConfigure(filterConfig); // Set bean properties from init parameters. try { PropertyValues pvs = new JndiSupportFilterConfigPropertyValues(filterConfig, this.requiredProperties); BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this); ResourceLoader resourceLoader = new ServletContextResourceLoader(filterConfig.getServletContext()); ServletContextPropertySource servletContextPropertySource = new ServletContextPropertySource(NAME + "_ServletContextPropertySource", filterConfig.getServletContext()); MutablePropertySources propertySources = new MutablePropertySources(); propertySources.addFirst(servletContextPropertySource); PropertySourcesPropertyResolver propertySourcesPropertyResolver = new PropertySourcesPropertyResolver(propertySources); bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, propertySourcesPropertyResolver)); bw.setPropertyValues(pvs, true); } catch (BeansException ex) { String msg = "Failed to set bean properties on filter '" + filterConfig.getFilterName() + "': " + ex.getMessage(); LOGGER.error(msg, ex); throw new NestedServletException(msg, ex); } doInit(filterConfig); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Filter '" + filterConfig.getFilterName() + "' configured successfully"); } }