Search in sources :

Example 1 with UnsupportedServiceException

use of io.knotx.adapter.common.exception.UnsupportedServiceException in project knotx by Cognifide.

the class HttpClientFacade method prepareRequestData.

private Pair<ClientRequest, ServiceMetadata> prepareRequestData(AdapterRequest adapterRequest) {
    final Pair<ClientRequest, ServiceMetadata> serviceData;
    final JsonObject params = adapterRequest.getParams();
    final ClientRequest serviceRequest = buildServiceRequest(adapterRequest.getRequest(), params);
    final Optional<ServiceMetadata> serviceMetadata = findServiceMetadata(serviceRequest.getPath());
    if (serviceMetadata.isPresent()) {
        final ServiceMetadata metadata = serviceMetadata.get();
        if (params.containsKey(HEADERS_PROPERTY_KEY)) {
            metadata.setAdditionalHeaders(params.getJsonObject(HEADERS_PROPERTY_KEY));
        }
        if (params.containsKey(QUERY_PARAMS_PROPERTY_KEY)) {
            metadata.setQueryParams(params.getJsonObject(QUERY_PARAMS_PROPERTY_KEY));
        }
        serviceData = Pair.of(serviceRequest, metadata);
    } else {
        final String error = String.format("No matching service definition for the requested path '%s'", serviceRequest.getPath());
        throw new UnsupportedServiceException(error);
    }
    return serviceData;
}
Also used : UnsupportedServiceException(io.knotx.adapter.common.exception.UnsupportedServiceException) JsonObject(io.vertx.core.json.JsonObject) ClientRequest(io.knotx.dataobjects.ClientRequest)

Aggregations

UnsupportedServiceException (io.knotx.adapter.common.exception.UnsupportedServiceException)1 ClientRequest (io.knotx.dataobjects.ClientRequest)1 JsonObject (io.vertx.core.json.JsonObject)1