use of org.forgerock.json.resource.InternalServerErrorException in project OpenAM by OpenRock.
the class SitesResourceProvider method readInstance.
@Override
public Promise<ResourceResponse, ResourceException> readInstance(Context context, String id, ReadRequest request) {
try {
SSOToken token = getSsoToken(context);
ResourceResponse site = getSite(token, id);
return newResultPromise(site);
} catch (SMSException | SSOException | ConfigurationException e) {
debug.error("Could not read site {}", id, e);
return new InternalServerErrorException("Could not read site").asPromise();
} catch (NotFoundException e) {
return e.asPromise();
}
}
use of org.forgerock.json.resource.InternalServerErrorException in project OpenAM by OpenRock.
the class SmsCollectionProvider method queryCollection.
/**
* Queries for child instances of config. The parent config referenced by the request path is found, and
* all child config for the type is returned.
* <p>
* Note that only query filter is supported, and only a filter of value {@code true} (i.e. all values).
* Sorting and paging are not supported.
* {@inheritDoc}
*/
@Override
public Promise<QueryResponse, ResourceException> queryCollection(Context context, QueryRequest request, QueryResourceHandler handler) {
if (!"true".equals(request.getQueryFilter().toString())) {
return new NotSupportedException("Query not supported: " + request.getQueryFilter()).asPromise();
}
if (request.getPagedResultsCookie() != null || request.getPagedResultsOffset() > 0 || request.getPageSize() > 0) {
return new NotSupportedException("Query paging not currently supported").asPromise();
}
try {
ServiceConfigManager scm = getServiceConfigManager(context);
String realm = realmFor(context);
if (subSchemaPath.isEmpty()) {
Set<String> instanceNames = new TreeSet<String>(scm.getInstanceNames());
for (String instanceName : instanceNames) {
ServiceConfig config = type == SchemaType.GLOBAL ? scm.getGlobalConfig(instanceName) : scm.getOrganizationConfig(realm, instanceName);
if (config != null) {
JsonValue value = getJsonValue(realm, config);
handler.handleResource(newResourceResponse(instanceName, String.valueOf(value.hashCode()), value));
}
}
} else {
ServiceConfig config = parentSubConfigFor(context, scm);
Set<String> names = config.getSubConfigNames("*", lastSchemaNodeName());
for (String configName : names) {
JsonValue value = getJsonValue(realm, config.getSubConfig(configName));
handler.handleResource(newResourceResponse(configName, String.valueOf(value.hashCode()), value));
}
}
return newResultPromise(newQueryResponse());
} catch (SMSException e) {
debug.warning("::SmsCollectionProvider:: SMSException on query", e);
return new InternalServerErrorException("Unable to query SMS config: " + e.getMessage()).asPromise();
} catch (SSOException e) {
debug.warning("::SmsCollectionProvider:: SSOException on query", e);
return new InternalServerErrorException("Unable to query SMS config: " + e.getMessage()).asPromise();
}
}
use of org.forgerock.json.resource.InternalServerErrorException in project OpenAM by OpenRock.
the class SmsCollectionProvider method readInstance.
/**
* Reads a child instance of config. The parent config referenced by the request path is found, and
* the config is read using the resourceId.
* {@inheritDoc}
*/
@Override
public Promise<ResourceResponse, ResourceException> readInstance(Context context, String resourceId, ReadRequest request) {
try {
ServiceConfigManager scm = getServiceConfigManager(context);
ServiceConfig config = parentSubConfigFor(context, scm);
ServiceConfig item = checkedInstanceSubConfig(context, resourceId, config);
JsonValue result = getJsonValue(realmFor(context), item);
return newResultPromise(newResourceResponse(resourceId, String.valueOf(result.hashCode()), result));
} catch (SMSException e) {
debug.warning("::SmsCollectionProvider:: SMSException on read", e);
return new InternalServerErrorException("Unable to read SMS config: " + e.getMessage()).asPromise();
} catch (SSOException e) {
debug.warning("::SmsCollectionProvider:: SSOException on read", e);
return new InternalServerErrorException("Unable to read SMS config: " + e.getMessage()).asPromise();
} catch (NotFoundException e) {
return e.asPromise();
}
}
use of org.forgerock.json.resource.InternalServerErrorException in project OpenAM by OpenRock.
the class SmsCollectionProvider method deleteInstance.
/**
* Deletes a child instance of config. The parent config referenced by the request path is found, and
* the config is deleted using the resourceId.
* {@inheritDoc}
*/
@Override
public Promise<ResourceResponse, ResourceException> deleteInstance(Context context, final String resourceId, DeleteRequest request) {
try {
ServiceConfigManager scm = getServiceConfigManager(context);
ServiceConfig config = parentSubConfigFor(context, scm);
checkedInstanceSubConfig(context, resourceId, config);
if (isDefaultCreatedAuthModule(context, resourceId)) {
scm.removeOrganizationConfiguration(realmFor(context), null);
} else {
config.removeSubConfig(resourceId);
}
return awaitDeletion(context, resourceId).then(new Function<Void, ResourceResponse, ResourceException>() {
@Override
public ResourceResponse apply(Void aVoid) {
return newResourceResponse(resourceId, "0", json(object(field("success", true))));
}
});
} catch (ServiceNotFoundException e) {
debug.warning("::SmsCollectionProvider:: ServiceNotFoundException on delete", e);
return new NotFoundException("Unable to delete SMS config: " + e.getMessage()).asPromise();
} catch (SMSException e) {
debug.warning("::SmsCollectionProvider:: SMSException on delete", e);
return new InternalServerErrorException("Unable to delete SMS config: " + e.getMessage()).asPromise();
} catch (SSOException e) {
debug.warning("::SmsCollectionProvider:: SSOException on delete", e);
return new InternalServerErrorException("Unable to delete SMS config: " + e.getMessage()).asPromise();
} catch (NotFoundException e) {
return e.asPromise();
}
}
use of org.forgerock.json.resource.InternalServerErrorException in project OpenAM by OpenRock.
the class SmsSingletonProvider method handleRead.
/**
* Reads config for the singleton instance referenced, and returns the JsonValue representation.
* {@inheritDoc}
*/
@Override
public Promise<ResourceResponse, ResourceException> handleRead(Context serverContext, ReadRequest readRequest) {
String resourceId = resourceId();
try {
ServiceConfig config = getServiceConfigNode(serverContext, resourceId);
String realm = realmFor(serverContext);
JsonValue result = withExtraAttributes(realm, convertToJson(realm, config));
return newResultPromise(newResourceResponse(resourceId, String.valueOf(result.hashCode()), result));
} catch (SMSException e) {
debug.warning("::SmsCollectionProvider:: SMSException on create", e);
return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
} catch (SSOException e) {
debug.warning("::SmsCollectionProvider:: SSOException on create", e);
return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
} catch (NotFoundException e) {
return e.asPromise();
}
}
Aggregations