0

I have a common codebase deployed in four different servers for various purposes like testing env, development env, production env etc.

But I need to know inside the code, which server's code is running to decide the flow of my code. Anybody know how to fetch the sever url or id inside the web service code which is deployed on the server?

  • See the second answer in following question: http://stackoverflow.com/questions/10619021/getting-instance-name-of-a-websphere-app-server – home Sep 24 '12 at 05:09

1 Answers1

0

Approach 1 : 4 different servers, mean four different URLs ok.

suppose ur application url is

http(s)://ipaddress:port/application 

now it is possible that all four server instances are on same machine. in that case "ipaddress" would be same. but port would be different. if machines are different in that case both ipaddress and port would be different.

now inside your code you can get absoultepath. absolutepath would consist of the complete URL of the file absolutepath is requested on. like

http://ipaddress:port/application/abc/def/x.java. 

Now from this you can extract the port/ipaddress and write your logic.

Approach2:

have a property file inside your application that contains the server its being deployed on. ( right now I cant think of something to set this automatically, but while deployment you can set the server name in this property file)

later on when you need. you can read the property file and you will know which version of application you are running on.

personally I`d prefer approach2 (and should be prefered in case we can think of initializing the properties file automatically)

Hope it helps :-)

Mukul Goel
  • 8,387
  • 6
  • 37
  • 77