Search in sources :

Example 1 with Endpoint

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);
}
Also used : Endpoint(com.bluenimble.platform.api.ApiSpace.Endpoint) ApiRequest(com.bluenimble.platform.api.ApiRequest) ApiVerb(com.bluenimble.platform.api.ApiVerb) ApiServiceExecutionException(com.bluenimble.platform.api.ApiServiceExecutionException) ApiManagementException(com.bluenimble.platform.api.ApiManagementException)

Example 2 with Endpoint

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);
}
Also used : Endpoint(com.bluenimble.platform.api.ApiSpace.Endpoint) JsonObject(com.bluenimble.platform.json.JsonObject) ApiRequest(com.bluenimble.platform.api.ApiRequest) ApiVerb(com.bluenimble.platform.api.ApiVerb) ApiServiceExecutionException(com.bluenimble.platform.api.ApiServiceExecutionException)

Aggregations

ApiRequest (com.bluenimble.platform.api.ApiRequest)2 ApiServiceExecutionException (com.bluenimble.platform.api.ApiServiceExecutionException)2 Endpoint (com.bluenimble.platform.api.ApiSpace.Endpoint)2 ApiVerb (com.bluenimble.platform.api.ApiVerb)2 ApiManagementException (com.bluenimble.platform.api.ApiManagementException)1 JsonObject (com.bluenimble.platform.json.JsonObject)1