3

I want to be able to deploy a .war file and detect which port the application is being served on. I have two grails' apps running within different tomcat instances, and ideally I would like to adapt the configuration of each app according to each specific tomcat instance. Each tomcat instance uses a different port, therefore detecting the port upon which the app is served means the app knows which tomcat instance the app is running in.

Thanks for any help!

tim_yates
  • 167,322
  • 27
  • 342
  • 338
Kurent
  • 99
  • 1
  • 6
  • Can you give me feedback on my answer? Did it help? – rdmueller Sep 17 '12 at 07:22
  • Thanks Ralf, but I used a different solution. I needed the solution to work before the first request. – Kurent Sep 17 '12 at 08:50
  • 2
    Note that in general "which port" may not have a single answer - you can configure several different connectors for the same tomcat, each on a different port number (e.g. SSL and non-SSL). – Ian Roberts Sep 17 '12 at 09:33

2 Answers2

1

I used an externalized configuration so that both grails apps would read a configuration relative to where each respective tomcat instance was started. By controlling from where each tomcat instance is started, then each grails app is configured appropriately. Therefore by placing the externalized configuration relative to the starting tomcat directory specific grail's app configuration is achieved!

Kurent
  • 99
  • 1
  • 6
0

Is it enough to get the port when the first request arrives? Then this could help:

    println request.requestURL
    println request.request.request.request.connector.port

If not, take look at these tow pages - I guess they might help

Get the server port number from tomcat with out a request

http://www.asjava.com/tomcat/how-to-get-tomcat-port-number-in-java/

always remember that oyu can use all the available java code in your grails application.

Community
  • 1
  • 1
rdmueller
  • 10,742
  • 10
  • 69
  • 126
  • Caveat: If Tomcat is behind a proxy, the request values will be what the proxy uses - not the port/scheme/etc that Tomcat is using. – Dan Tanner Jan 06 '15 at 23:14