Invoking System.setProperty() two times on the same property

H

Hugo

Hello,

I have a big problem.
My program sets a property using System.setProperty(). The purpose of
this property is for secured LDAP connection. Everything works fine
until I decide to change the same property. I chanage it (and by
invoking System.getproperty() I check that it is properly changed) but
the system still behaves with the old value ...

I don't understand, is it possible to set the vlaue of a property only
one time in a program ?

Thanks for your kind assistance.

Hugo
 
G

Gordon Beaton

My program sets a property using System.setProperty(). The purpose
of this property is for secured LDAP connection. Everything works
fine until I decide to change the same property. I chanage it (and
by invoking System.getproperty() I check that it is properly
changed) but the system still behaves with the old value ...

I don't understand, is it possible to set the vlaue of a property
only one time in a program ?

The system properties aren't an "alternative API" for the various
classes that use them. The values are normally just used for
initialization, and need to be set before the corresponding classes
are used in order to have the desired effect. In other cases they only
provide information to the application, and setting them has
absolutely no effect at all.

It seems that you need to rethink your solution. You need to either
use the existing LDAP classes differently, or find a different LDAP
library that can do what you want.

/gordon
 
N

nos

Gordon Beaton said:
The system properties aren't an "alternative API" for the various
classes that use them. The values are normally just used for
initialization, and need to be set before the corresponding classes
are used in order to have the desired effect. In other cases they only
provide information to the application, and setting them has
absolutely no effect at all.

It seems that you need to rethink your solution. You need to either
use the existing LDAP classes differently, or find a different LDAP
library that can do what you want.

/gordon

I don't have my book handy but I thought there was a method
that you could use to set a change listener for the system properties.
Then when the property changes the listener code can do what you need.
 
H

Hugo

nos said:
I don't have my book handy but I thought there was a method
that you could use to set a change listener for the system properties.
Then when the property changes the listener code can do what you need.

So, if I understand, it is a normal behaviour that the
System.setProperty() works only one time on a same property ?
 
P

P.Hill

Hugo said:
So, if I understand, it is a normal behaviour that the
System.setProperty() works only one time on a same property ?

No, not at all.

I think your LDAP classes must already have been intialized with
the properties list and thus you change the property and the
LDAP instance doesn't care. Somehow you need to get it to
start over and re-read the properties. I have no idea if
this is possible.

-Paul
 
H

Hugo

P.Hill said:
No, not at all.

I think your LDAP classes must already have been intialized with
the properties list and thus you change the property and the
LDAP instance doesn't care. Somehow you need to get it to
start over and re-read the properties. I have no idea if
this is possible.

-Paul

But, why does it work a the first time ??
I mean, I use exactly the same method to connect LDAP the two times.
At the beginning of the method I set these system properties, and then
I create my LDAP Client. The second time, I call the exact same
method, reset the properties (which have effectively been changed,
because I check by calling getProperties()), and I create a totally
new LDAP client, so it should use the new properties. I miss something
apparently ...

Thanks a lot for your answers
 
G

Gordon Beaton

But, why does it work a the first time ?? I mean, I use exactly the
same method to connect LDAP the two times. At the beginning of the
method I set these system properties, and then I create my LDAP
Client. The second time, I call the exact same method, reset the
properties (which have effectively been changed, because I check by
calling getProperties()), and I create a totally new LDAP client, so
it should use the new properties. I miss something apparently ...

Because apparently your LDAP library only *reads* the value of the
property when it initializes, i.e. the first time you use it. The
second time you create a client, the library is already initialized
and it doesn't read the value of the property again.

If there is a different way to modify the behaviour of your library
(e.g. by invoking one of its methods directly instead of setting a
system property) then use that instead. Otherwise, there might be a
different LDAP library available that can do what you want.

So far you haven't said exactly what you are trying to achieve, so
nobody has been able to recommend an alternative mechanism.

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top