// If the name is project relative then make it absolute.
if (name.startsWith("/")) {
name = runtimeProject.makeAbsolutePolicyURL(name);
}
HttpGetMethod method = methodFactory.createGetMethod(name);
Throwable throwable = null;
try {
method.addRequestHeader(REQUEST_TYPE_HEADER_NAME,
"singlePolicy");
// todo The policy may not exist but the project may in which case
// todo this should load the project and then try and load the
// todo policy from a fallback (if any).
HttpStatusCode code = method.execute();
if (code == HttpStatusCode.OK) {
project = updateProject(project, method);
InputStream in = method.getResponseBodyAsStream();
builder = parser.parsePolicyBuilder(in, name);
} else {
// Log the fact that the remote policy could not be found.
logger.warn("remote-policy-not-found", new Object[]{
name, code
});
builder = null;
}
} catch (IOException e) {
throwable = e;
} catch (ResourceMigrationException e) {
throwable = e;
} finally {
if (throwable != null) {
// If we get an error, we log it but don't throw an exception.
// We just carry on as if we hadn't found the asset.
logger.error("remote-component-not-available",
new Object[]{name}, throwable);
}
method.releaseConnection();
}
return new PolicyBuilderResponse(project, builder);
}