use of io.vertx.reactivex.core.MultiMap in project knotx by Cognifide.
the class FilesystemRepositoryConnectorProxyImpl method headers.
private MultiMap headers(Optional<String> contentType) {
MultiMap headers = MultiMap.caseInsensitiveMultiMap();
contentType.ifPresent(s -> headers.add("Content-Type", s));
return headers;
}
use of io.vertx.reactivex.core.MultiMap in project knotx by Cognifide.
the class HttpRepositoryConnectorProxyImpl method process.
@Override
public void process(ClientRequest request, Handler<AsyncResult<ClientResponse>> result) {
MultiMap requestHeaders = buildHeaders(clientDestination.getString("hostHeader"), request.getHeaders());
RequestOptions httpRequestData = buildRequestData(request);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("GET HTTP Repository: {}://{}:{}/{} with headers [{}]", httpRequestData.isSsl() ? "https" : "http", httpRequestData.getHost(), httpRequestData.getPort(), httpRequestData.getURI(), DataObjectsUtil.toString(requestHeaders));
}
get(httpClient, httpRequestData, requestHeaders).doOnNext(this::traceHttpResponse).flatMap(this::processResponse).subscribe(response -> result.handle(Future.succeededFuture(response)), error -> {
LOGGER.error(ERROR_MESSAGE, error);
result.handle(Future.succeededFuture(toInternalError()));
});
}
use of io.vertx.reactivex.core.MultiMap in project knotx by Cognifide.
the class HttpRepositoryConnectorProxyImpl method buildRepoUri.
private String buildRepoUri(ClientRequest repoRequest) {
StringBuilder uri = new StringBuilder(repoRequest.getPath());
MultiMap params = repoRequest.getParams();
if (params != null && params.names() != null && !params.names().isEmpty()) {
uri.append("?").append(params.names().stream().map(name -> new StringBuilder(encode(name)).append("=").append(encode(params.get(name)))).collect(Collectors.joining("&")));
}
return uri.toString();
}
use of io.vertx.reactivex.core.MultiMap in project knotx by Cognifide.
the class MockActionAdapterHandler method matchRequest.
private boolean matchRequest(ClientRequest request, Map.Entry<String, Object> transition) {
final JsonObject condition = ((JsonObject) transition.getValue()).getJsonObject("condition");
final MultiMap formAttributes = request.getFormAttributes();
return condition.stream().allMatch(entry -> formAttributes.contains(entry.getKey()) && formAttributes.get(entry.getKey()).matches(String.valueOf(entry.getValue())));
}
use of io.vertx.reactivex.core.MultiMap in project knotx by Cognifide.
the class HttpClientFacadeTest method whenSupportedDynamicPathServiceRequested_expectRequestExecutedAndResponseOKWithBody.
@Test
@KnotxConfiguration("knotx-action-adapter-http-test.json")
public void whenSupportedDynamicPathServiceRequested_expectRequestExecutedAndResponseOKWithBody(TestContext context) throws Exception {
Async async = context.async();
// given
final WebClient mockedWebClient = PowerMockito.spy(webClient());
HttpClientFacade clientFacade = new HttpClientFacade(mockedWebClient, getConfiguration());
final JsonObject expectedResponse = new JsonObject(FileReader.readText("first-response.json"));
// FIXME - params to request
MultiMap requestParams = MultiMap.caseInsensitiveMultiMap().add("dynamicValue", "first");
Single<ClientResponse> result = clientFacade.process(payloadMessage(new JsonObject().put("path", "/services/mock/{param.dynamicValue}.json"), clientRequest.setParams(requestParams)), HttpMethod.POST);
// then
result.doOnSuccess(response -> {
context.assertEquals(HttpResponseStatus.OK.code(), response.getStatusCode());
context.assertEquals(expectedResponse, response.getBody().toJsonObject());
Mockito.verify(mockedWebClient, Mockito.times(1)).request(HttpMethod.POST, PORT, DOMAIN, REQUEST_PATH);
}).subscribe(response -> async.complete(), error -> context.fail(error.getMessage()));
}
Aggregations