Search in sources :

Example 1 with MultiMap

use of io.vertx.reactivex.core.MultiMap in project knotx by Cognifide.

the class MultiMapConverterTest method fromJsonObject_whenNotEmptyJson_expectSizeOfMultiMap.

@TestWith({ "{\"mapKey1\":[\"A\",\"B\",\"C\"]};1", "{\"mapKey1\":[\"A\"],\"mapKey2\":[\"B\"]};2", "{\"mapKey1\":[\"A\"],\"mapKey2\":[\"B\"],\"mapKey3\":[\"C\"]};3" })
public void fromJsonObject_whenNotEmptyJson_expectSizeOfMultiMap(JsonObject jsonObject, int multimapSize) throws Exception {
    final MultiMap multiMap = MultiMapConverter.fromJsonObject(jsonObject);
    assertThat(multiMap.size(), equalTo(multimapSize));
}
Also used : MultiMap(io.vertx.reactivex.core.MultiMap) TestWith(com.googlecode.zohhak.api.TestWith)

Example 2 with MultiMap

use of io.vertx.reactivex.core.MultiMap in project knotx by Cognifide.

the class MultiMapConverterTest method provideMultiMap.

@Coercion
public MultiMap provideMultiMap(String input) {
    final MultiMap multiMap = MultiMap.caseInsensitiveMultiMap();
    final String[] entries = input.split("\\|");
    for (String entry : entries) {
        final String[] keyWithValues = entry.split(":");
        final String[] elements = keyWithValues[1].split(",");
        for (String e : elements) {
            multiMap.add(keyWithValues[0], e);
        }
    }
    return multiMap;
}
Also used : MultiMap(io.vertx.reactivex.core.MultiMap) Coercion(com.googlecode.zohhak.api.Coercion)

Example 3 with MultiMap

use of io.vertx.reactivex.core.MultiMap in project knotx by Cognifide.

the class RequestProcessorKnotProxyImpl method getHeaders.

private MultiMap getHeaders(ClientResponse clientResponse, int bodyLength) {
    MultiMap headers = clientResponse.getHeaders();
    headers.add(HttpHeaders.CONTENT_LENGTH.toString().toLowerCase(), Integer.toString(bodyLength)).add("Content-Type", "application/json");
    return headers;
}
Also used : MultiMap(io.vertx.reactivex.core.MultiMap)

Example 4 with MultiMap

use of io.vertx.reactivex.core.MultiMap in project knotx by Cognifide.

the class UriHelper method getParams.

public static MultiMap getParams(String uri) {
    QueryStringDecoder queryStringDecoder = new QueryStringDecoder(uri);
    Map<String, List<String>> queryParams = queryStringDecoder.parameters();
    io.vertx.core.MultiMap params = io.vertx.core.MultiMap.caseInsensitiveMultiMap();
    if (!queryParams.isEmpty()) {
        for (Map.Entry<String, List<String>> entry : queryParams.entrySet()) {
            params.add(entry.getKey(), entry.getValue());
        }
    }
    return MultiMap.newInstance(params);
}
Also used : QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) List(java.util.List) MultiMap(io.vertx.reactivex.core.MultiMap) Map(java.util.Map)

Example 5 with MultiMap

use of io.vertx.reactivex.core.MultiMap in project knotx by Cognifide.

the class MultiMapConverter method fromJsonObject.

/**
 * Converts JsonObject to MultiMap. It expects the JsonObject key, contains JsonArray with list of
 * String objects.<br>
 * Each jsonObject key is converted into MultiMap "key", while JsonArray as List of String objects
 * for this velue.
 *
 * @param json - {@link JsonObject} to convert
 * @return - {@link MultiMap} created from {@link JsonObject}
 */
public static MultiMap fromJsonObject(JsonObject json) {
    MultiMap map = MultiMap.caseInsensitiveMultiMap();
    json.stream().forEach(entry -> ((JsonArray) entry.getValue()).stream().forEach(value -> map.add(entry.getKey(), (String) value)));
    return map;
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonArray(io.vertx.core.json.JsonArray) MultiMap(io.vertx.reactivex.core.MultiMap) JsonObject(io.vertx.core.json.JsonObject) MultiMap(io.vertx.reactivex.core.MultiMap)

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