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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get the port dynamically

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I have a servlet (parent) that needs to invoke another servlet (child) that resides on the same appserver. The way we build the URL now to reach the child servlet is to build the URL up by pulling the protocol, host and port out of the request object when the parent servlet executes. Since the child is on the same appserver, we use the same host/port and protocol. The host is always going to be local, so we could just use localhost instead of a getHost() call.




This code works fine, but some clients have started to use a load balancer and if the LB is not configured to pass through the client's address in the request object, what happens is we wind up getting back the IP/port of the LB instead of the app server and our servlet request will fail.

As a solution, we could change to use "localhost" instead of calling srcURL.getHost(), however how would we resolve the port? The port Tomcat is listening on is not guaranteed to be 8080 and can be changed by the user. Is there a way to dynamically determine what port Tomcat is using without requiring the user to have to tell the servlet or by getting it out of the request object?

thank you

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place. Please click this link ⇒ CarefullyChooseOneForum ⇐ for more information.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic