• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading multiple values from a properties file.

 
David C Shaw
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I've had a search and while a few have asked something similar I've not seen a working answer as of yet. In short I'm using java to query a properties file and run a password encryption app against all DB connections. In real world terms the process is:

read property->Identify DB connections->prompt user for password to DB user->Run encrypter against password entry -> write encrypted value back out to property file.

My properties look similar to the below but also contain information on applications, urls etc :

xadatasource.SETDataTxDs_1.driver=oracle.jdbc.xa.client.OracleXADataSource
xadatasource.SETDataTxDs_1.url=jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=)(PORT=))(FAILOVER=)(LOAD_BALANCE=))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=)))
xadatasource.SETDataTxDs_1.jndi=SETDataTxDs_1
xadatasource.SETDataTxDs_1.globalTransaction = TwoPhaseCommit
xadatasource.SETDataTxDs_1.user=helloworld
xadatasource.SETDataTxDs_1.password=
xadatasource.SETDataTxDs_1.initial=${domain.jdbc.initial}
xadatasource.SETDataTxDs_1.capacity=${domain.jdbc.capacity}
xadatasource.SETDataTxDs_1.increment=${domain.jdbc.increment}
xadatasource.SETDataTxDs_1.targets=cluster

My property file will no doubt have a few connections. I've used pro.keyset which reads all of the file. Essentially what I need is a bit of code that does:



I've done similar in jython before as you can probably see with my logic above, however with jython using weblogic's WLST it is impossible to mask password inputs so I'm having to add a small java applet to my build.xml to handle this for me.

Any help greatly appreciated.

Many thanks!

Dave
(ps. my middle name is Charles, I'm not taking the mick with my display name - thanks Mum n Dad!)
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,

It looks like you have a hierarchy in your properties file based on the key string. For example:
xadtasource.
represents a 'list' of data sources. Inside the list you might have multiple sources named, for example:
SETDataTxDs_1.
SETDataTxDs_2.
...

Then in each data source definition you have 'properties' which store the information you want to get to. In Java, Properties files don't have hierarchies like that, each key is unique and independent. You would have to build something that iterates all of the keys, parses them to their parts, and then builds a structure you can iterate over the way you want. I would imagine the need for a 'DataSource' class to hold the properties (jndi, user, password, etc...) then a Collection of some sort to hold the DataSource objects.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49827
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch

I never thought there was anything suspicious about your displayed name.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49827
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this thread is too difficult for "beginning Java", so I shall move it.
 
David C Shaw
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou sir! I am a beginner so I guess that's why I put the question in that section. Fingers crossed someone can give me a couple of pointers to set me on my way!

Steve, you are indeed correct. My build scripts basically have unique configuration code that looks at the props files, each individual resource (whether thats xa, an ear etc) has its own section and the scripts know the .'s separate different configurable values.

Thanks again!

Dave
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic