use of com.bluenimble.platform.api.ApiSpace.Endpoint in project serverless by bluenimble.
the class SecurityUtils method onFinish.
public static ApiOutput onFinish(Api api, ApiConsumer consumer, ApiRequest pRequest, final JsonObject onFinish, JsonObject account) throws ApiServiceExecutionException {
if (onFinish == null || onFinish.isEmpty()) {
return null;
}
ApiRequest request = api.space().request(pRequest, consumer, new Endpoint() {
@Override
public String space() {
return Json.getString(onFinish, Config.onFinish.Space, api.space().getNamespace());
}
@Override
public String api() {
return Json.getString(onFinish, Config.onFinish.Api, api.getNamespace());
}
@Override
public String[] resource() {
String resource = Json.getString(onFinish, Config.onFinish.Resource);
if (resource.startsWith(Lang.SLASH)) {
resource = resource.substring(1);
}
if (resource.endsWith(Lang.SLASH)) {
resource = resource.substring(0, resource.length() - 1);
}
if (Lang.isNullOrEmpty(resource)) {
return null;
}
return Lang.split(resource, Lang.SLASH);
}
@Override
public ApiVerb verb() {
try {
return ApiVerb.valueOf(Json.getString(onFinish, Config.onFinish.Verb, ApiVerb.POST.name()).toUpperCase());
} catch (Exception ex) {
return ApiVerb.POST;
}
}
});
request.set(ApiRequest.Payload, account);
return api.call(request);
}
use of com.bluenimble.platform.api.ApiSpace.Endpoint in project serverless by bluenimble.
the class ApiUtils method call.
public static ApiOutput call(final Api api, final ApiConsumer consumer, final ApiRequest pRequest, final JsonObject oRequest) throws ApiServiceExecutionException {
ApiRequest request = api.space().request(pRequest, consumer, new Endpoint() {
@Override
public String space() {
return Json.getString(oRequest, Spec.Space, api.space().getNamespace());
}
@Override
public String api() {
return Json.getString(oRequest, Spec.Api, api.getNamespace());
}
@Override
public String[] resource() {
String resource = Json.getString(oRequest, Spec.Service);
if (resource.startsWith(Lang.SLASH)) {
resource = resource.substring(1);
}
if (resource.endsWith(Lang.SLASH)) {
resource = resource.substring(0, resource.length() - 1);
}
if (Lang.isNullOrEmpty(resource)) {
return null;
}
return Lang.split(resource, Lang.SLASH);
}
@Override
public ApiVerb verb() {
try {
return ApiVerb.valueOf(Json.getString(oRequest, Spec.Verb, ApiVerb.POST.name()).toUpperCase());
} catch (Exception ex) {
return ApiVerb.POST;
}
}
});
JsonObject parameters = Json.getObject(oRequest, Spec.Parameters);
if (!Json.isNullOrEmpty(parameters)) {
Iterator<String> keys = parameters.keys();
while (keys.hasNext()) {
String key = keys.next();
request.set(key, parameters.get(key));
}
}
JsonObject headers = Json.getObject(oRequest, Spec.Headers);
if (!Json.isNullOrEmpty(headers)) {
Iterator<String> keys = headers.keys();
while (keys.hasNext()) {
String key = keys.next();
request.set(key, headers.get(key), Scope.Header);
}
}
return api.call(request);
}
Aggregations