use of com.bluenimble.platform.api.impls.ApiResourceOutput in project serverless by bluenimble.
the class GetResourceApiServiceSpi method execute.
@Override
public ApiOutput execute(Api api, ApiConsumer consumer, ApiRequest request, ApiResponse response) throws ApiServiceExecutionException {
String path = (String) request.get(Spec.Path);
if (Lang.isNullOrEmpty(path)) {
throw new ApiServiceExecutionException("Resource / not found").status(ApiResponse.BAD_REQUEST);
}
String location = (String) Json.find(request.getService().getCustom(), Custom.Resources, Custom.Root);
if (!Lang.isNullOrEmpty(location)) {
path = location + Lang.SLASH + path;
}
ApiResource r;
try {
r = api.getResourcesManager().get(Lang.split(path, Lang.SLASH));
} catch (ApiResourcesManagerException e) {
throw new ApiServiceExecutionException(e.getMessage()).status(ApiResponse.BAD_REQUEST);
}
if (r == null) {
throw new ApiServiceExecutionException("Resource " + path + " not found").status(ApiResponse.NOT_FOUND);
}
return new ApiResourceOutput(r);
}
Aggregations