You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ftpserver-users@mina.apache.org by Roger Marshall <ro...@aetopia.com> on 2009/05/29 19:17:13 UTC
Overriding XML configuration from system properties
We have a small FTP Server application which is based on old Apache
FTP Server code from a couple of years ago, and therefore uses
org.apache.ftpserver.config.PropertiesConfiguration, etc., for
configuration.
I'm updating it to use the production version of FtpServer, mainly
because I need the setPassiveExternalAddress method in
org.apache.ftpserver.DataConnectionConfigurationFactory.
The first step is to rewrite the configuration part of our app using
the new Spring-based system, but I know almost nothing about Spring
(and about the same about FtpServer at the moment), so I'm not totally
sure whether my issues relate to Spring or FtpServer. Since we don't
actually use Spring for anything else, I'm trying to minimise how much
Spring I introduce. My intention is to have the core 'wiring' done in
XML bundled with the application, with the host-specific configuration
coming from system properties. After a lot of head-scratching, I have
the following code:
XmlBeanFactory factory = new XmlBeanFactory(new UrlResource(
((Application) Application.application()).resourceManager()
.pathURLForResourceNamed("ftpserver.xml", null, null)));
PropertyOverrideConfigurer poc = new PropertyOverrideConfigurer();
poc.setIgnoreInvalidKeys(true);
poc.setProperties((Properties)System.getProperties().clone());
poc.postProcessBeanFactory(factory);
DefaultFtpServer server = (DefaultFtpServer)
factory.getBean("myServer");
(Application is a WebObjects com.webobjects.appserver.WOApplication)
I then started with the following ftpserver.xml:
<?xml version="1.0" encoding="UTF-8"?>
<server xmlns="http://mina.apache.org/ftpserver/spring/v1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://mina.apache.org/ftpserver/spring/v1 http://mina.apache.org/ftpserver/ftpserver-1.0.xsd
"
id="myServer" max-logins="7">
<listeners>
<nio-listener name="default" port="2222" implicit-ssl="true"
idle-timeout="60" local-address="1.2.3.4">
<data-connection idle-timeout="60">
<active enabled="true" local-address="1.2.3.4" local-port="2323"
ip-check="true" />
<passive ports="123-125" address="1.2.3.4" external-
address="1.2.3.4" />
</data-connection>
</nio-listener>
</listeners>
</server>
This worked fine, and I was able to determine that e.g. maxLogins had
been set to the specified test value. However, I was unable to conjure
the appropriate properties file entries to override maxLogins. I then
had a go at rewriting the ftpserver.xml file using regular <bean>
tags, and came up with the following:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
">
<bean id="ftpserver-connection"
class="org.apache.ftpserver.ConnectionConfigFactory">
<property name="maxLogins" value="7"></property>
</bean>
<bean id="myConnectionConfig"
factory-bean="ftpserver-connection"
factory-method="createConnectionConfig">
</bean>
<bean id="ftpServerFactory"
class="org.apache.ftpserver.FtpServerFactory">
<property name="connectionConfig" ref="myConnectionConfig"></property>
</bean>
<bean id="myServer" factory-bean="ftpServerFactory"
factory-method="createServer" />
</beans>
Not quite as pretty, but it seemed to work.
I then added the following to a properties file:
ftpserver-connection.maxLogins=11
This had the desired effect - maxLogins now reported the overridden
value. However, I'd have preferred something like
ftpserver.connection.maxLogins. When I changed the ftpserver-
connection bean id to ftpserver.connection, and the factory-bean
attribute of the myConnectionConfig bean to the same, the XML part of
the configuration still worked. Unfortunately, subsequently changing
the property to ftpserver. connection.maxLogins had no effect -- the
maxLogins property was not overridden.
My first question is whether there is actually valid set of properties
file entries that would work with the first version of ftpserver.xml
(the one using the http://mina.apache.org/ftpserver/spring/v1 schema)?
My second question (assuming the answer to the first is 'no'), is how
to reference a bean with a dot in its name from a properties file?
Thanks!
--
Roger
Re: Overriding XML configuration from system properties
Posted by David Latorre <dv...@gmail.com>.
Yeah it's a same that because of different issues none of them,
PropertyPlaceholder nor PropertyOverriden will work :-S
2009/5/31 Niklas Gustavsson <ni...@protocol7.com>:
> On Sun, May 31, 2009 at 12:06 AM, Niklas Gustavsson
> <ni...@protocol7.com> wrote:
>> On Fri, May 29, 2009 at 7:17 PM, Roger Marshall
>> <ro...@aetopia.com> wrote:
>>> My first question is whether there is actually valid set of properties file
>>> entries that would work with the first version of ftpserver.xml (the one
>>> using the http://mina.apache.org/ftpserver/spring/v1 schema)?
>>
>> We do not currently support property based configuration (I personally
>> find this a major gap since I'm a big user of property replacement
>> with Spring). However, there is an issue reported
>> (https://issues.apache.org/jira/browse/FTPSERVER-282) that we plan on
>> fixing for 1.1. Not waiting for 1.1, I think your solution is the best
>> available. I'm not very familiar with the problem your having so I do
>> not have any more input than the excellent reply you already received
>> from David.
>
> I should also have noted that you can used a
> .PropertyPlaceholderConfigurer in which case you can choose the
> property name yourself. However, as FTPSERVER-282 points out, if using
> our custom schema, you will not be able to use this for numeric
> values, instead you would have to use the standard Spring <bean> tags.
>
> /niklas
>
Re: Overriding XML configuration from system properties
Posted by Niklas Gustavsson <ni...@protocol7.com>.
On Sun, May 31, 2009 at 12:06 AM, Niklas Gustavsson
<ni...@protocol7.com> wrote:
> On Fri, May 29, 2009 at 7:17 PM, Roger Marshall
> <ro...@aetopia.com> wrote:
>> My first question is whether there is actually valid set of properties file
>> entries that would work with the first version of ftpserver.xml (the one
>> using the http://mina.apache.org/ftpserver/spring/v1 schema)?
>
> We do not currently support property based configuration (I personally
> find this a major gap since I'm a big user of property replacement
> with Spring). However, there is an issue reported
> (https://issues.apache.org/jira/browse/FTPSERVER-282) that we plan on
> fixing for 1.1. Not waiting for 1.1, I think your solution is the best
> available. I'm not very familiar with the problem your having so I do
> not have any more input than the excellent reply you already received
> from David.
I should also have noted that you can used a
.PropertyPlaceholderConfigurer in which case you can choose the
property name yourself. However, as FTPSERVER-282 points out, if using
our custom schema, you will not be able to use this for numeric
values, instead you would have to use the standard Spring <bean> tags.
/niklas
Re: Overriding XML configuration from system properties
Posted by Niklas Gustavsson <ni...@protocol7.com>.
On Fri, May 29, 2009 at 7:17 PM, Roger Marshall
<ro...@aetopia.com> wrote:
> My first question is whether there is actually valid set of properties file
> entries that would work with the first version of ftpserver.xml (the one
> using the http://mina.apache.org/ftpserver/spring/v1 schema)?
We do not currently support property based configuration (I personally
find this a major gap since I'm a big user of property replacement
with Spring). However, there is an issue reported
(https://issues.apache.org/jira/browse/FTPSERVER-282) that we plan on
fixing for 1.1. Not waiting for 1.1, I think your solution is the best
available. I'm not very familiar with the problem your having so I do
not have any more input than the excellent reply you already received
from David.
/niklas
Re: Overriding XML configuration from system properties
Posted by David Latorre <dv...@gmail.com>.
Hello Roger,
2009/5/29 Roger Marshall <ro...@aetopia.com>:
> We have a small FTP Server application which is based on old Apache FTP
> Server code from a couple of years ago, and therefore uses
> org.apache.ftpserver.config.PropertiesConfiguration, etc., for
> configuration.
>
> I'm updating it to use the production version of FtpServer, mainly because I
> need the setPassiveExternalAddress method in
> org.apache.ftpserver.DataConnectionConfigurationFactory.
>
> The first step is to rewrite the configuration part of our app using the new
> Spring-based system, but I know almost nothing about Spring (and about the
> same about FtpServer at the moment), so I'm not totally sure whether my
> issues relate to Spring or FtpServer. Since we don't actually use Spring for
> anything else, I'm trying to minimise how much Spring I introduce. My
> intention is to have the core 'wiring' done in XML bundled with the
> application, with the host-specific configuration coming from system
> properties. After a lot of head-scratching, I have the following code:
>
>
> XmlBeanFactory factory = new XmlBeanFactory(new UrlResource(
> ((Application)
> Application.application()).resourceManager()
>
> .pathURLForResourceNamed("ftpserver.xml", null, null)));
>
> PropertyOverrideConfigurer poc = new PropertyOverrideConfigurer();
> poc.setIgnoreInvalidKeys(true);
> poc.setProperties((Properties)System.getProperties().clone());
> poc.postProcessBeanFactory(factory);
>
> DefaultFtpServer server = (DefaultFtpServer) factory.getBean("myServer");
>
>
> (Application is a WebObjects com.webobjects.appserver.WOApplication)
> I then started with the following ftpserver.xml:
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <server xmlns="http://mina.apache.org/ftpserver/spring/v1"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://mina.apache.org/ftpserver/spring/v1
> http://mina.apache.org/ftpserver/ftpserver-1.0.xsd"
> id="myServer" max-logins="7">
> <listeners>
> <nio-listener name="default" port="2222" implicit-ssl="true"
> idle-timeout="60" local-address="1.2.3.4">
> <data-connection idle-timeout="60">
> <active enabled="true"
> local-address="1.2.3.4" local-port="2323"
> ip-check="true" />
> <passive ports="123-125" address="1.2.3.4"
> external-address="1.2.3.4" />
> </data-connection>
> </nio-listener>
> </listeners>
> </server>
>
>
> This worked fine, and I was able to determine that e.g. maxLogins had been
> set to the specified test value. However, I was unable to conjure the
> appropriate properties file entries to override maxLogins. I then had a go
> at rewriting the ftpserver.xml file using regular <bean> tags, and came up
> with the following:
>
>
> <beans xmlns="http://www.springframework.org/schema/beans"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
>
> <bean id="ftpserver-connection"
> class="org.apache.ftpserver.ConnectionConfigFactory">
> <property name="maxLogins" value="7"></property>
> </bean>
>
> <bean id="myConnectionConfig"
> factory-bean="ftpserver-connection"
> factory-method="createConnectionConfig">
> </bean>
>
> <bean id="ftpServerFactory"
> class="org.apache.ftpserver.FtpServerFactory">
> <property name="connectionConfig"
> ref="myConnectionConfig"></property>
> </bean>
>
> <bean id="myServer" factory-bean="ftpServerFactory"
> factory-method="createServer" />
>
> </beans>
>
>
> Not quite as pretty, but it seemed to work.
> I then added the following to a properties file:
>
>
> ftpserver-connection.maxLogins=11
>
>
> This had the desired effect - maxLogins now reported the overridden value.
> However, I'd have preferred something like ftpserver.connection.maxLogins.
> When I changed the ftpserver-connection bean id to ftpserver.connection, and
> the factory-bean attribute of the myConnectionConfig bean to the same, the
> XML part of the configuration still worked. Unfortunately, subsequently
> changing the property to ftpserver. connection.maxLogins had no effect --
> the maxLogins property was not overridden.
>
>
> My first question is whether there is actually valid set of properties file
> entries that would work with the first version of ftpserver.xml (the one
> using the http://mina.apache.org/ftpserver/spring/v1 schema)?
I don't know Spring myself but it's my understanding that adding a
factory.getBeanDefinitionNames() to your example above should print
all the bean names which are available. There are only a few of them
(i'd say you cannot see inner beans) so I don't know if this approach
is suitable for you ( Let's wait to Nilklas response but I think that
inner beans are not supported by PropertyOverrideConfigurer, you might
ask in their mailing list )
> My second question (assuming the answer to the first is 'no'), is how to
> reference a bean with a dot in its name from a properties file?
By default, PropertyOverrideConfigurer takes the right part of the
first dot as the bean name (
'ftpserver.connection.maxLogins' would mean that the bean name is 'ftpserver'
You can change the bean Name separator with
PropertyOverrideConfigurer.setBeanNameSeparator(String
beanNameSeparator) so you can do something like this:
poc.setBeanNameSeparator(":");
ftpserver.connection:maxLogins = 5;
I haven't checked if the ':' character would be accepted though.
>
> Thanks!
> --
> Roger
>
>