use of org.forgerock.json.resource.Router in project OpenAM by OpenRock.
the class SmsRouteTree method tree.
/**
* Creates a {@code SmsRouteTree} structure with the provided sub trees.
*
* @param subTreeBuilders The sub trees.
* @return A {@code SmsRouteTree}.
*/
static SmsRouteTree tree(Map<MatchingResourcePath, CrestAuthorizationModule> authModules, CrestAuthorizationModule defaultAuthModule, SmsRouteTreeBuilder... subTreeBuilders) {
Router router = new Router();
SmsRouteTree tree = new SmsRouteTree(authModules, defaultAuthModule, true, router, null, ResourcePath.empty());
for (SmsRouteTreeBuilder subTreeBuilder : subTreeBuilders) {
tree.addSubTree(subTreeBuilder.build(tree));
}
return tree;
}
use of org.forgerock.json.resource.Router in project OpenAM by OpenRock.
the class Requester method action.
/**
* Request to perform an action at a specified endpoint.
*
* @param location Endpoint destination of this request. May not be null.
* @param resourceId Specific resource ID to perform action on. May be null.
* @param actionId act ID to delete. May not be null.
* @param context Context of this request.
* @return The {@link org.forgerock.json.JsonValue} returned from the endpoint.
* @throws ResourceException If any exception occurred during processing.
*/
public JsonValue action(String location, String resourceId, String actionId, JsonValue payload, Context context) throws ResourceException {
Reject.ifTrue(StringUtils.isEmpty(location), "The endpoint destination may not be null or empty.");
Reject.ifTrue(StringUtils.isEmpty(actionId), "The specific action to perform may not be null or empty.");
final Router rootRouter = router.get();
final ActionRequest actionRequest = Requests.newActionRequest(location, actionId);
if (payload != null) {
actionRequest.setContent(payload);
}
if (resourceId != null) {
actionRequest.setResourcePath(resourceId);
}
return rootRouter.handleAction(context, actionRequest).getOrThrowUninterruptibly().getJsonContent();
}
use of org.forgerock.json.resource.Router in project OpenAM by OpenRock.
the class Requester method query.
/**
* Request to perform a query at a specified endpoint.
*
* @param location Endpoint destination of this request. May not be null.
* @param queryId Specific query ID to perform. May be null.
* @param context Context of this request.
* @return The {@link org.forgerock.json.JsonValue} returned from the endpoint.
* @throws ResourceException If any exception occurred during processing.
*/
public JsonValue query(String location, String queryId, Context context) throws ResourceException {
Reject.ifTrue(StringUtils.isEmpty(location), "The endpoint destination may not be null or empty.");
final Router rootRouter = router.get();
final QueryRequest queryRequest = Requests.newQueryRequest(location);
if (queryId != null) {
queryRequest.setQueryId(queryId);
}
final InMemoryQueryResourceHandler resourceHandler = new InMemoryQueryResourceHandler();
return rootRouter.handleQuery(context, queryRequest, resourceHandler).thenAsync(new AsyncFunction<QueryResponse, JsonValue, ResourceException>() {
@Override
public Promise<JsonValue, ResourceException> apply(QueryResponse value) {
final JsonArray responses = JsonValueBuilder.jsonValue().array("results");
for (ResourceResponse resource : resourceHandler.getResources()) {
responses.add(resource.getContent());
}
return newResultPromise(responses.build().build());
}
}).getOrThrowUninterruptibly();
}
use of org.forgerock.json.resource.Router in project OpenAM by OpenRock.
the class Requester method create.
/**
* Request to create a resource at a specified endpoint.
*
* @param location Endpoint destination of this request. May not be null.
* @param resourceId Resource ID to be created. May be null.
* @param payload Payload of the resource to generate. May not be null.
* @param context Context of this request.
* @return The {@link org.forgerock.json.JsonValue} returned from the endpoint.
* @throws ResourceException If any exception occurred during processing.
*/
public JsonValue create(String location, String resourceId, JsonValue payload, Context context) throws ResourceException {
Reject.ifTrue(StringUtils.isEmpty(location), "The endpoint destination may not be null or empty.");
Reject.ifNull(payload, "The payload object to create must not be null.");
final Router rootRouter = router.get();
final CreateRequest createRequest = Requests.newCreateRequest(location, payload);
if (resourceId != null) {
createRequest.setNewResourceId(resourceId);
}
return rootRouter.handleCreate(context, createRequest).getOrThrowUninterruptibly().getContent();
}
use of org.forgerock.json.resource.Router in project OpenAM by OpenRock.
the class Requester method delete.
/**
* Request to delete a specified resource at a specified endpoint.
*
* @param location Endpoint destination of this request. May not be null.
* @param resourceId Resource ID to delete. May not be null.
* @param context Context of this request.
* @return The {@link org.forgerock.json.JsonValue} returned from the endpoint.
* @throws ResourceException If any exception occurred during processing.
*/
public JsonValue delete(String location, String resourceId, Context context) throws ResourceException {
Reject.ifTrue(StringUtils.isEmpty(location), "The endpoint destination may not be null or empty.");
Reject.ifTrue(StringUtils.isEmpty(resourceId), "The resourceId to delete may not be null or empty.");
final Router rootRouter = router.get();
final DeleteRequest deleteRequest = Requests.newDeleteRequest(location, resourceId);
return rootRouter.handleDelete(context, deleteRequest).getOrThrowUninterruptibly().getContent();
}
Aggregations