aspose file tools*
The moose likes Web Services and the fly likes How to use value of variable dynamically rather than hard coding... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "How to use value of variable dynamically rather than hard coding..." Watch "How to use value of variable dynamically rather than hard coding..." New topic
Author

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

Rohit David
Greenhorn

Joined: Feb 18, 2008
Posts: 12
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
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
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.


Ping & DNS - updated with new look and Ping home screen widget
Rohit David
Greenhorn

Joined: Feb 18, 2008
Posts: 12
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
Bartender

Joined: Oct 14, 2005
Posts: 18122
    
    8

Why not just put the file in a predetermined location outside the web application?
Rohit David
Greenhorn

Joined: Feb 18, 2008
Posts: 12
yes after giving it a thought thats what i plan on doing. Thanks all of you for all your help and assistance.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use value of variable dynamically rather than hard coding...
 
Similar Threads
load log4j property file from url
how to configure a JNDI URL resource
Hibernate with Spring
load log4j property file from url
how to configure a JNDI URL resource