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;
}
Aggregations