Search in sources :

Example 11 with MultiMap

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;
}
Also used : MultiMap(io.vertx.reactivex.core.MultiMap)

Example 12 with MultiMap

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()));
    });
}
Also used : MultiMap(io.vertx.reactivex.core.MultiMap) RequestOptions(io.vertx.core.http.RequestOptions)

Example 13 with MultiMap

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();
}
Also used : MultiMap(io.vertx.reactivex.core.MultiMap)

Example 14 with MultiMap

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())));
}
Also used : MultiMap(io.vertx.reactivex.core.MultiMap) JsonObject(io.vertx.core.json.JsonObject)

Example 15 with MultiMap

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()));
}
Also used : ClientResponse(io.knotx.dataobjects.ClientResponse) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Matchers(org.mockito.Matchers) UnsupportedServiceException(io.knotx.adapter.common.exception.UnsupportedServiceException) RunWith(org.junit.runner.RunWith) Logback(io.knotx.junit.rule.Logback) Single(io.reactivex.Single) ClientResponse(io.knotx.dataobjects.ClientResponse) Vertx(io.vertx.reactivex.core.Vertx) Lists(com.google.common.collect.Lists) AdapterRequest(io.knotx.dataobjects.AdapterRequest) FileReader(io.knotx.junit.util.FileReader) ClientRequest(io.knotx.dataobjects.ClientRequest) JsonObject(io.vertx.core.json.JsonObject) HttpClientFacade(io.knotx.adapter.common.http.HttpClientFacade) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration) PowerMockito(org.powermock.api.mockito.PowerMockito) TestVertxDeployer(io.knotx.junit.rule.TestVertxDeployer) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) HttpAdapterConfiguration(io.knotx.adapter.common.http.HttpAdapterConfiguration) WebClient(io.vertx.reactivex.ext.web.client.WebClient) RuleChain(org.junit.rules.RuleChain) Mockito(org.mockito.Mockito) MultiMap(io.vertx.reactivex.core.MultiMap) List(java.util.List) Rule(org.junit.Rule) ServiceMetadata(io.knotx.adapter.common.http.ServiceMetadata) HttpMethod(io.vertx.core.http.HttpMethod) Pattern(java.util.regex.Pattern) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) Collections(java.util.Collections) MultiMap(io.vertx.reactivex.core.MultiMap) Async(io.vertx.ext.unit.Async) HttpClientFacade(io.knotx.adapter.common.http.HttpClientFacade) JsonObject(io.vertx.core.json.JsonObject) WebClient(io.vertx.reactivex.ext.web.client.WebClient) Test(org.junit.Test) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration)

Aggregations

MultiMap (io.vertx.reactivex.core.MultiMap)19 Async (io.vertx.ext.unit.Async)5 WebClient (io.vertx.reactivex.ext.web.client.WebClient)5 KnotxConfiguration (io.knotx.junit.rule.KnotxConfiguration)4 JsonObject (io.vertx.core.json.JsonObject)4 ClientResponse (io.knotx.dataobjects.ClientResponse)3 List (java.util.List)3 Test (org.junit.Test)3 UnsupportedServiceException (io.knotx.adapter.common.exception.UnsupportedServiceException)2 AdapterRequest (io.knotx.dataobjects.AdapterRequest)2 ClientRequest (io.knotx.dataobjects.ClientRequest)2 Single (io.reactivex.Single)2 HttpMethod (io.vertx.core.http.HttpMethod)2 Pattern (java.util.regex.Pattern)2 Lists (com.google.common.collect.Lists)1 Coercion (com.googlecode.zohhak.api.Coercion)1 TestWith (com.googlecode.zohhak.api.TestWith)1 AdapterServiceContractException (io.knotx.adapter.common.exception.AdapterServiceContractException)1 HttpAdapterConfiguration (io.knotx.adapter.common.http.HttpAdapterConfiguration)1 HttpClientFacade (io.knotx.adapter.common.http.HttpClientFacade)1