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