Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use value of variable dynamically rather than hard coding...

 
Rohit David
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am incorporating a third party API and in my WAR file I have a properties resource file which contains authentication and server access information. However having a resource file within a WAR is getting inconvenient because anytime server or authentication information changes, the prop file needs to be updated and the WAR needs to be redeployed.

Well I have figured out an easier way to access the prop file by invoking it from a url using the code below:

<code>
try{
URL destURL = new URL( "http", <IP address>, "/" + "MyRemote.Properies" );
URLConnection connection = destURL.openConnection();
InputStream is = connection.getInputStream();
PropertyResourceBundle MyBundle = new PropertyResourceBundle(is);
} catch ( java.util.MissingResourceException e ) {...}
catch (MalformedURLException e2) {...}
catch (IOException e1) {...}

</code>

However I do not like the idea of hard coding the url with my source code. I would like to make it more dynamic such that it can be accessed either from an environment variable or from the application server setting or some war file xml document. And this is where I need some advice and guidance. I am currently testing in Tomcat, but will be deploying eventually in Web sphere. So I would appreciate a answer which will be compatible with both app servers.

Thanks,
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An env=entry tag in the web.xml file would be a possibility.

But it's a dangerous thing to make this kind of file available over HTTP - anyone can access it. Or were you thinking about using authentication for it, too? Even then I would probably shy away from a scheme like this.
 
Rohit David
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much for your prompt reply, you do bring a good point forward security. Well this application is going to be limited to intranet only.
 
Paul Clapham
Sheriff
Posts: 21137
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not just put the file in a predetermined location outside the web application?
 
Rohit David
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes after giving it a thought thats what i plan on doing. Thanks all of you for all your help and assistance.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic