Solved

HttpServletRequest getServerName returning internal IP address

Posted on 2008-10-08
1
2,473 Views
Last Modified: 2013-11-24
public String getWebrootUrl() {
            if (webrootUrl.length() == 0) {
                  HttpServletRequest request = FacesUtils.getRequest();
                  if (request != null) {
                        try {
                              URL reconstructedURL = new URL(request.getScheme(),
                                          request.getServerName(),
                                          request.getServerPort(),
                                          getWebroot());
                              webrootUrl = reconstructedURL.toString();
                        } catch (MalformedURLException e) {
                              webrootUrl = "";
                        }
                  }
            }
            return webrootUrl;
      }

The above code is use to generate the correct url when we were using a virtual name-based server, we've since moved off using named-based and switched to an IP based scheme so instead of returning somehting like https://www.myurl.com/ it now returns https://192.168.200.10 on our production server which is obviously a private network IP! Is there a way to get code to do a reverse-lookup on the IP in the local /etc/hosts file?

0
Comment
Question by:mhp2007
1 Comment
 
LVL 1

Accepted Solution

by:
Jorge Fraser earned 500 total points
ID: 22669901
Look at InetAddress and the getHostName() method. It is supposed to do a reverse lookup for you.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
object oriented programming comparison 5 77
ejb example issues 3 26
Selenium docs api java index 3 48
hashmap order 17 37
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question