• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I make the web service aware of where it is deployed?  RSS feed

 
Aditya Karnad
Greenhorn
Posts: 16
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem I face is that I have the same service deployed on 3 environments (3 different servers) and these 3 deployments use 3 different Databases depending on the environment.
Rather than changing the connection string to the DB, building and packaging everytime I switch from one environment to the other, I want to write some code that would automatically recognize the environment and use the appropriate DB.

Is there some way of fetching the hostname or something else that would distinguish between the 3 environments?
Also, some code snippets to show how to get the hostname / or anything else indicating context to the web service would be very helpful.

Thanks!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bad idea. I'd use a properties file.
 
Aditya Karnad
Greenhorn
Posts: 16
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Bad idea. I'd use a properties file.


I am using a properties file where I store my connection string. But on what basis do I make the code understand which properties file to use?
Or do you mean that I must keep this file on all the hosts and have the code read the connection string from this file?
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should have one copy of the properties file in each environment, and it should contain a property which refers to the connection string which applies in that environment.
 
Aditya Karnad
Greenhorn
Posts: 16
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you - I think this would solve my problem!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!