use of org.forgerock.openam.utils.JsonObject in project OpenAM by OpenRock.
the class RestSTSPublishServiceRequestHandler method handleRead.
public Promise<ResourceResponse, ResourceException> handleRead(Context context, ReadRequest request) {
try {
if (EMPTY_STRING.equals(request.getResourcePath())) {
List<RestSTSInstanceConfig> publishedInstances = publisher.getPublishedInstances();
JsonObject jsonObject = JsonValueBuilder.jsonValue();
for (RestSTSInstanceConfig instanceConfig : publishedInstances) {
jsonObject.put(instanceConfig.getDeploymentSubPath(), mapStringToJson(instanceConfig.toJson().toString()));
}
/*
Note that the revision etag is not set, as this is not a resource which should really be cached.
If caching becomes necessary, a string composed of the hash codes of each of the RestSTSInstanceConfig
instances could be used (or a hash of that string).
*/
return newResultPromise(newResourceResponse(PUBLISHED_INSTANCES, EMPTY_STRING, jsonObject.build()));
} else {
final String realm = getRealmFromResourceName(request.getResourcePath());
if (!realmValidator.isRealm(realm)) {
logger.warn("Read of rest STS instance state for instance " + request.getResourcePath() + " in realm " + realm + " rejected because realm does not exist");
return new NotFoundException("The specified realm does not exist.").asPromise();
}
RestSTSInstanceConfig instanceConfig = publisher.getPublishedInstance(request.getResourcePath(), realm);
return newResultPromise(newResourceResponse(instanceConfig.getDeploymentSubPath(), Integer.toString(instanceConfig.hashCode()), JsonValueBuilder.jsonValue().put(instanceConfig.getDeploymentSubPath(), mapStringToJson(instanceConfig.toJson().toString())).build()));
}
} catch (STSPublishException e) {
String message = "Exception caught obtaining rest sts instance corresponding to id: " + request.getResourcePath() + "; Exception: " + e;
logger.error(message, e);
return e.asPromise();
}
}
Aggregations