Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-4410

Custom configuration providers accessing servlet-context

    XMLWordPrintableJSON

Details

    Description

      I'm using custom configuration providers following the suggestion of this post.

      I figured out that my custom configuration provider needed access to the servlet-context so I patched the code in the Dispatcher class to let, in case the constructor is available, instantiate a ConfigurationProvider with the servlet-context as argument

      private void init_CustomConfigurationProviders() {
      	String configProvs = initParams.get("configProviders");
      	if (configProvs != null) {
      		String[] classes = configProvs.split("\\s*[,]\\s*");
      		for (String cname : classes) {
      			try {
      				Class cls = ClassLoaderUtil.loadClass(cname, this.getClass());
      				
      				ConfigurationProvider prov;
      				try {
      					Constructor constructor = cls.getConstructor(ServletContext.class);
      					prov = (ConfigurationProvider)constructor.newInstance(servletContext);
      				} catch (Exception e) {
      					prov = (ConfigurationProvider)cls.newInstance();	
      				}
      				configurationManager.addContainerProvider(prov);
      			} catch (InstantiationException e) {
      				throw new ConfigurationException("Unable to instantiate provider: "+cname, e);
      			} catch (IllegalAccessException e) {
      				throw new ConfigurationException("Unable to access provider: "+cname, e);
      			} catch (ClassNotFoundException e) {
      				throw new ConfigurationException("Unable to locate provider class: "+cname, e);
      			}
      		}
      	}
      }
      

      Attachments

        Activity

          People

            lukaszlenart Lukasz Lenart
            fustaki Lorenzo Bernacchioni
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: