}
}
// not sure what other opendap servers do, so fall back on check for dds
static private ServiceType checkIfDods(HTTPSession session, String location) throws IOException {
HTTPMethod method = null;
// Strip off any trailing constraints
if(location.indexOf('?') >= 0) {
location = location.substring(0,location.indexOf('?'));
}
// Strip off any trailing .dds, .das, or .dods
if(location.endsWith(".dds"))
location = location.substring(0,location.length()-".dds".length());
if(location.endsWith(".das"))
location = location.substring(0,location.length()-".das".length());
if(location.endsWith(".dods"))
location = location.substring(0,location.length()-".dods".length());
// Must encode the URL before sending
location = EscapeStrings.escapeURL(location);
try {
// For some reason, the head method is not using credentials
// method = session.newMethodHead(location + ".dds");
method = session.newMethodGet(location + ".dds");
int status = method.execute();
if (status == 200) {
Header h = method.getResponseHeader("Content-Description");
if ((h != null) && (h.getValue() != null)) {
String v = h.getValue();
if (v.equalsIgnoreCase("dods-dds") || v.equalsIgnoreCase("dods_dds"))
return ServiceType.OPENDAP;
else
throw new IOException("OPeNDAP Server Error= " + method.getResponseAsString());
}
}
if (status == 401)
throw new IOException("Unauthorized to open dataset " + location);
// not dods
return null;
} finally {
if (method != null) method.close();
}
}