hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Albretch Mueller <lbrt...@gmail.com>
Subject getting Fully Qualified Domain Name (FQDN) ...
Date Fri, 24 Feb 2012 16:31:43 GMT
 Say you want to keep the local copies of documents you download/view
online in a directory structure that somewhat resembles the URL path.
 Firefox seems to darken the FQDN, but then you can check it doesn't
do it truthfully. Try for example:
 Why is it that u-tokyo.ac.jp throws an UnknownHostException?
 As I see it, neither the java API nor HTTP Client offer an utility
that would let you know for example that "nces.ed.gov" is not a FQDN,
but "ed.gov", so that you can build local directory structures that
better resemble the URLs
 In the case of cognition.iig.uni-freiburg.de, the FQDN is
"uni-freiburg.de" and there are indeed separate hosts at
"cognition.iig.uni-freiburg.de" and "iig.uni-freiburg.de", so that
"iig" would be a directory inside of "cognition", but in the case of
"www-hiel.ist.osaka-u.ac.jp" the host seems to be
"www-hiel.ist.osaka-u.ac.jp" ...
 Here is the demo/toy code I used:

import java.net.*;
import java.util.*;

// __
public class GetCanonicalHostName{
 public static void main(String[] args){
  String[][] aHNms = new String[][]{
   {"sussex.ac.uk", "ac.uk"},
   {"www.mathstat.dal.ca", "mathstat.dal.ca", "dal.ca"},
   {"www-hiel.ist.osaka-u.ac.jp", "ist.osaka-u.ac.jp",
"osaka-u.ac.jp", "ac.jp"},
   {"www.c.u-tokyo.ac.jp", "c.u-tokyo.ac.jp", "u-tokyo.ac.jp"},
   {"hardware.slashdot.org", "slashdot.org"},
   {"cognition.iig.uni-freiburg.de", "iig.uni-freiburg.de", "uni-freiburg.de"},
   {"www.york.ac.uk", "york.ac.uk", "ac.uk"},
   {"newyorkweb.york.ac.uk", "york.ac.uk", "ac.uk"},
   {"pas.fdle.state.fl.us", "fdle.state.fl.us", "state.fl.us", "fl.us"},
   {"nces.ed.gov", "ed.gov"},
// __
  InetAddress ia = null;
  for(int i = 0; (i < aHNms.length); ++i){
   System.out.println("// __ " + aHNms[i].length + ":");
   for(int j = 0; (j < aHNms[i].length); ++j){
    System.out.print("// __  " + aHNms[i][j] + " | ");
     ia = InetAddress.getByName(aHNms[i][j]);
     System.out.println(ia.getCanonicalHostName() + " | " +
    }catch(UnknownHostException UnkHX){ UnkHX.printStackTrace(); }

To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org

View raw message