Changeset 2924


Ignore:
Timestamp:
2002-01-30T02:09:44+13:00 (20 years ago)
Author:
cs025
Message:

Added the ability to directly state a host URL.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/java-client/org/nzdl/gsdl/util/NzdlHosts.java

    r2163 r2924  
    122122  }
    123123
    124   static public String getUrl(String code)
    125   {
    126     return "http://" + getHost(code) + "/cgi-bin/getior";
    127   }
     124  static public String getUrlFromSite(String sitename)
     125  {
     126    return "http://" + sitename + "/cgi-bin/getior";
     127  }
     128
     129  static public String getUrlFromCode(String code)
     130  {
     131    return "http://" + getFullName(code) + "/cgi-bin/getior";
     132  }
     133
     134    static String getIOR(URL url)
     135    {
     136    try {
     137        InputStream his = url.openStream();
     138        DataInputStream dhis = new DataInputStream(his) ;
     139        String ior = dhis.readLine();
     140        System.out.println(ior);
     141        return ior;
     142    }
     143    catch (Throwable throwable) {
     144        System.err.println("NzdlHosts:getIOR() unable to communicate with URL \"" + url + "\"");
     145    }
     146    return "";
     147    }
    128148
    129149  static public String getIOR(String code)
     
    132152      singleton = new NzdlHosts();
    133153
    134     String str = getUrl(code);
     154    String str = getUrlFromCode(code);
    135155    String ior = null;
     156    URL    url;
    136157
    137158    try {
    138       URL url = new URL(str);
    139       InputStream his = url.openStream();
    140       DataInputStream dhis = new DataInputStream(his) ;
    141       ior = dhis.readLine();
    142       return ior;
    143     } catch (Throwable throwable) {
     159    url = new URL(str);
     160    }
     161    catch (Throwable malEx) {
    144162      System.err.println("NzdlHosts::getIOR() unable to construct or read URL \"" +
    145              str + "\", \"" + ior + "\": " + throwable);
     163             str + "\", \"" + ior + "\": " + malEx);
    146164      return "";
    147165    }
     166
     167    return getIOR(url);
    148168  }
    149169
     
    156176      System.err.println("NzdlHosts::getHost() constructing NzdlServiceClient(" +
    157177               code + ") " + throwable);
     178    }
     179    return nzdl;
     180  }
     181
     182  static public NzdlService getSite(String sitename) {
     183    NzdlService nzdl = null;
     184
     185    try {
     186    String siteUrl = getUrlFromSite(sitename);
     187    URL url = new URL(siteUrl);
     188      nzdl = new NzdlServiceClient(null,null,getIOR(url));
     189    } catch (Throwable throwable) {
     190      System.err.println("NzdlHosts::getHost() constructing NzdlServiceClient(" +
     191               sitename + ") " + throwable);
    158192    }
    159193    return nzdl;
Note: See TracChangeset for help on using the changeset viewer.