struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF subversion and git services (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (WW-4410) Custom configuration providers accessing servlet-context
Date Thu, 25 Feb 2016 20:30:18 GMT

    [ https://issues.apache.org/jira/browse/WW-4410?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15167815#comment-15167815
] 

ASF subversion and git services commented on WW-4410:
-----------------------------------------------------

Commit 9860ef829a95428be4fd2638f984b830855e5812 in struts's branch refs/heads/support-2-3
from [~lukaszlenart]
[ https://git-wip-us.apache.org/repos/asf?p=struts.git;h=9860ef8 ]

WW-4410 Adds dedicated interface to allow inject ServletContext


> Custom configuration providers accessing servlet-context
> --------------------------------------------------------
>
>                 Key: WW-4410
>                 URL: https://issues.apache.org/jira/browse/WW-4410
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Dispatch Filter
>    Affects Versions: 2.3.16.3
>            Reporter: Lorenzo Bernacchioni
>            Priority: Minor
>              Labels: configuration, custom, provider, servlet-context
>             Fix For: 2.3.25, 2.5
>
>
> I'm using custom configuration providers following the suggestion of [this post|http://cppoon.wordpress.com/2013/11/11/change-apache-struts2-configuration-programmatically/comment-page-1/#comment-157].
> 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
> {code}
> 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);
> 			}
> 		}
> 	}
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message