svctype = decodePathExtension(trueurl); // look at the path extension if(svctype == null && checkIfNcml(new File(location))) { svctype = ServiceType.NCML;
static private boolean checkIfRemoteNcml(String location) throws IOException { if (decodePathExtension(location)==ServiceType.NCML) { // just because location ends with ncml does not mean it's ncml // if the ncml file is being served up via http by a remote server, // we should be able to read the first bit of it and see if it even // looks like an ncml file. try (HTTPMethod method = HTTPFactory.Get(location)) { method.setRange(0, NUM_BYTES_TO_DETERMINE_NCML); method.setRequestHeader("accept-encoding", "identity"); int statusCode = method.execute(); if (statusCode >= 300) { if (statusCode == 401) { throw new IOException("Unauthorized to open dataset " + location); } else if (statusCode == 406) { String msg = location + " - this server does not support returning content without any encoding."; msg = msg + " Please download the file locally. Return status=" + statusCode; throw new IOException(msg); } else { throw new IOException(location + " is not a valid URL, return status=" + statusCode); } } return checkIfNcml(method.getResponseAsString()); } } return false; }