Solved

HttpServletRequest getServerName returning internal IP address

Posted on 2008-10-08
1
2,444 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

929 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now