Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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

 
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,
 
Rancher
Posts: 43016
76
  • 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.
 
Marshal
Posts: 25682
69
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic