0

In a Spring or Restlet web application, how can I get the domain name of the client?

What I can do now is get client IP address only:

String clientIp = getRequest().getClientInfo().getAddress();

However I need to get the domain name of the client.

Mainly because I am making a proxy app which domains from GoDaddy (for example):

  • Forward www CNAME to the proxy app.
  • Proxy app gets the domain name, say xyz.com, or abc.com and forward it to a specific IP or another domain.
Community
  • 1
  • 1
quarks
  • 33,478
  • 73
  • 290
  • 513
  • What is a 'proxy app'? If you use apache http proxy so use proxy ajp instead. Other way edit your questin and add technologies and configuratins. The answer probably isn't belong java code. – Martin Strejc Aug 21 '14 at 04:24

2 Answers2

5

You can try with this.

InetAddress addr = InetAddress.getByName(clientIp);
String host = addr.getHostName();
System.out.println(host);

Converting an IP address to host name

Community
  • 1
  • 1
codebot
  • 2,540
  • 3
  • 38
  • 89
1

In a general way, I suggest you have a look at the full content of the incoming request. Check the provided headers and see if they contain the data you need.

Uusing Restlet, you can have a look at the request#ClientInfo#UpStreamAddress method. It takes care of forwarding data provided by the request, and returns the client's IP. I don't know what you mean by client's host domain.

user229044
  • 232,980
  • 40
  • 330
  • 338
Thierry Boileau
  • 866
  • 5
  • 8
  • I have two domains, say www.xyz.com and www.abc.com these two domain points to the same Restlet app. Now I need the app to determine or get if the client accessed xyz or abc. I mean this is the reason why I need to do this – quarks Aug 26 '14 at 12:00