response = new FileResponse(u, datum, this, getConf()); // make a request
int code = response.getCode();
if (code == 200) { // got a good response
return new ProtocolOutput(response.toContent()); // return it
} else if (code == 304) { // got not modified
return new ProtocolOutput(response.toContent(), ProtocolStatus.STATUS_NOTMODIFIED);
} else if (code == 401) { // access denied / no read permissions
return new ProtocolOutput(response.toContent(), new ProtocolStatus(ProtocolStatus.ACCESS_DENIED));
} else if (code == 404) { // no such file
return new ProtocolOutput(response.toContent(), ProtocolStatus.STATUS_NOTFOUND);
} else if (code >= 300 && code < 400) { // handle redirect
u = new URL(response.getHeader("Location"));
if (LOG.isTraceEnabled()) {
LOG.trace("redirect to " + u);
}
if (symlinksAsRedirects) {
return new ProtocolOutput(response.toContent(), new ProtocolStatus(
ProtocolStatus.MOVED, u));
} else if (redirects == MAX_REDIRECTS) {
LOG.trace("Too many redirects: {}", url);
return new ProtocolOutput(response.toContent(), new ProtocolStatus(
ProtocolStatus.REDIR_EXCEEDED, u));
}
redirects++;
} else { // convert to exception
throw new FileError(code);
}
}
} catch (Exception e) {
e.printStackTrace();
return new ProtocolOutput(null, new ProtocolStatus(e));
}
}