Java Code Examples for io.vertx.core.MultiMap#add()
The following examples show how to use
io.vertx.core.MultiMap#add() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MarsmediaBidder.java From prebid-server-java with Apache License 2.0 | 6 votes |
private static MultiMap resolveHeaders(Device device) { final MultiMap headers = HttpUtil.headers() .add("x-openrtb-version", "2.5"); if (device != null) { HttpUtil.addHeaderIfValueIsNotEmpty(headers, "User-Agent", device.getUa()); HttpUtil.addHeaderIfValueIsNotEmpty(headers, "X-Forwarded-For", device.getIp()); HttpUtil.addHeaderIfValueIsNotEmpty(headers, "Accept-Language", device.getLanguage()); final Integer deviceDnt = device.getDnt(); if (deviceDnt != null) { headers.add("DNT", deviceDnt.toString()); } } return headers; }
Example 2
Source File: S3Client.java From vertx-s3-client with Apache License 2.0 | 6 votes |
private MultiMap populateAclHeadersRequest(AclHeadersRequest aclHeadersRequest) { final MultiMap headers = MultiMap.caseInsensitiveMultiMap(); if (aclHeadersRequest.getAmzAcl() != null) { headers.add(Headers.X_AMZ_ACL, StringUtils.trim(aclHeadersRequest.getAmzAcl().getValue())); } if (StringUtils.trimToNull(aclHeadersRequest.getAmzGrantRead()) != null) { headers.add(Headers.X_AMZ_GRANT_READ, StringUtils.trim(aclHeadersRequest.getAmzGrantRead())); } if (StringUtils.trimToNull(aclHeadersRequest.getAmzGrantWrite()) != null) { headers.add(Headers.X_AMZ_GRANT_WRITE, StringUtils.trim(aclHeadersRequest.getAmzGrantWrite())); } if (StringUtils.trimToNull(aclHeadersRequest.getAmzGrantReadAcp()) != null) { headers.add(Headers.X_AMZ_GRANT_READ_ACP, StringUtils.trim(aclHeadersRequest.getAmzGrantReadAcp())); } if (StringUtils.trimToNull(aclHeadersRequest.getAmzGrantWriteAcp()) != null) { headers.add(Headers.X_AMZ_GRANT_WRITE_ACP, StringUtils.trim(aclHeadersRequest.getAmzGrantWriteAcp())); } if (StringUtils.trimToNull(aclHeadersRequest.getAmzGrantFullControl()) != null) { headers.add(Headers.X_AMZ_GRANT_FULL_CONTROL, StringUtils.trim(aclHeadersRequest.getAmzGrantFullControl())); } return headers; }
Example 3
Source File: OpenAPI3ValidationTest.java From vertx-web with Apache License 2.0 | 6 votes |
@Test public void testFormURLEncodedCharParameter() throws Exception { Operation op = testSpec.getPaths().get("/formTests/urlencodedchar").getPost(); if(op.getParameters()==null) op.setParameters(new ArrayList<>()); OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec, refsCache); loadHandlers("/formTests/urlencodedchar", HttpMethod.POST, false, validationHandler, (routingContext) -> { RequestParameters params = routingContext.get("parsedParameters"); routingContext.response().setStatusMessage(params.formParameter("name").getString()).end(); }); String name = "test+urlencoded+char"; MultiMap form = MultiMap.caseInsensitiveMultiMap(); form.add("name", name); testRequestWithForm(HttpMethod.POST, "/formTests/urlencodedchar", FormType.FORM_URLENCODED, form, 200, name); }
Example 4
Source File: S3Client.java From vertx-s3-client with Apache License 2.0 | 6 votes |
private MultiMap populateGetObjectHeaders(GetObjectRequest getObjectRequest) { final MultiMap headers = MultiMap.caseInsensitiveMultiMap(); if (StringUtils.trimToNull(getObjectRequest.getRange()) != null) { headers.add(Headers.RANGE, StringUtils.trim(getObjectRequest.getRange())); } if (StringUtils.trimToNull(getObjectRequest.getIfModifiedSince()) != null) { headers.add(Headers.IF_MODIFIED_SINCE, StringUtils.trim(getObjectRequest.getIfModifiedSince())); } if (StringUtils.trimToNull(getObjectRequest.getIfUnmodifiedSince()) != null) { headers.add(Headers.IF_UNMODIFIED_SINCE, StringUtils.trim(getObjectRequest.getIfUnmodifiedSince())); } if (StringUtils.trimToNull(getObjectRequest.getIfMatch()) != null) { headers.add(Headers.IF_MATCH, StringUtils.trim(getObjectRequest.getIfMatch())); } if (StringUtils.trimToNull(getObjectRequest.getIfNoneMatch()) != null) { headers.add(Headers.IF_NONE_MATCH, StringUtils.trim(getObjectRequest.getIfNoneMatch())); } return headers; }
Example 5
Source File: BrightrollBidder.java From prebid-server-java with Apache License 2.0 | 6 votes |
/** * Creates headers for post request with version and {@link Device} properties. */ private MultiMap createHeaders(Device device) { final MultiMap headers = HttpUtil.headers(); headers.add(OPEN_RTB_VERSION_HEADER, OPENRTB_VERSION); if (device != null) { HttpUtil.addHeaderIfValueIsNotEmpty(headers, HttpUtil.USER_AGENT_HEADER.toString(), device.getUa()); HttpUtil.addHeaderIfValueIsNotEmpty(headers, HttpUtil.ACCEPT_LANGUAGE_HEADER.toString(), device.getLanguage()); HttpUtil.addHeaderIfValueIsNotEmpty(headers, HttpUtil.X_FORWARDED_FOR_HEADER.toString(), device.getIp()); HttpUtil.addHeaderIfValueIsNotEmpty(headers, HttpUtil.DNT_HEADER.toString(), Objects.toString(device.getDnt(), null)); } return headers; }
Example 6
Source File: MailMessageTest.java From vertx-mail-client with Apache License 2.0 | 5 votes |
@Test public void testHeadersMultipleValues() { MailMessage mailMessage = new MailMessage(); MultiMap headers = MultiMap.caseInsensitiveMultiMap(); headers.add("Header", "value1"); headers.add("Header", "value2"); headers.add("Header2", "value3"); mailMessage.setHeaders(headers); assertEquals("{\"headers\":{\"Header\":[\"value1\",\"value2\"],\"Header2\":[\"value3\"]}}", mailMessage.toJson().encode()); }
Example 7
Source File: S3Client.java From vertx-s3-client with Apache License 2.0 | 5 votes |
private MultiMap populateDeleteObjectHeaders(DeleteObjectRequest deleteObjectRequest) { final MultiMap headers = MultiMap.caseInsensitiveMultiMap(); if (StringUtils.trimToNull(deleteObjectRequest.getAmzMfa()) != null) { headers.add(Headers.X_AMZ_MFA, StringUtils.trim(deleteObjectRequest.getAmzMfa())); } return headers; }
Example 8
Source File: AbstractSerializableParameterExtractorTest.java From vertx-swagger with Apache License 2.0 | 5 votes |
@Test() public void testDefault() { String name = "myName"; SerializableParameter parameter = new QueryParameter(); parameter.setName("myName"); parameter.setType("string"); String param = "toto"; MultiMap params = MultiMap.caseInsensitiveMultiMap(); params.add(name, param); Object result = abstractSerializableParameterExtractor.extract(name, parameter, params); Assert.assertEquals("toto", result); }
Example 9
Source File: MailMessageTest.java From vertx-mail-client with Apache License 2.0 | 5 votes |
@Test public void testHeadersValue() { MailMessage mailMessage = new MailMessage(); MultiMap headers = MultiMap.caseInsensitiveMultiMap(); headers.add("Header", "value"); mailMessage.setHeaders(headers); assertEquals("{\"headers\":{\"Header\":[\"value\"]}}", mailMessage.toJson().encode()); }
Example 10
Source File: AbstractSerializableParameterExtractorTest.java From vertx-swagger with Apache License 2.0 | 5 votes |
@Test() public void testArrayOther() { String name = "myName"; SerializableParameter parameter = new QueryParameter(); parameter.setName("myName"); parameter.setType("array"); parameter.setCollectionFormat("anyOtherValue"); String param = "toto,tutu,titi"; MultiMap params = MultiMap.caseInsensitiveMultiMap(); params.add(name, param); Object result = abstractSerializableParameterExtractor.extract(name, parameter, params); Assert.assertArrayEquals(new String[] { "toto", "tutu", "titi" }, ((List) result).toArray()); }
Example 11
Source File: HttpBasicAuth.java From openapi-generator with Apache License 2.0 | 5 votes |
@Override public void applyToParams(List<Pair> queryParams, MultiMap headerParams, MultiMap cookieParams) { if (username == null && password == null) { return; } String str = (username == null ? "" : username) + ":" + (password == null ? "" : password); headerParams.add("Authorization", "Basic " + Base64.getEncoder().encodeToString(str.getBytes(StandardCharsets.UTF_8))); }
Example 12
Source File: AbstractSerializableParameterExtractorTest.java From vertx-swagger with Apache License 2.0 | 5 votes |
@Test(expected = IllegalArgumentException.class) public void testNotAllowEmptyValueWithEmptyParameter() { String name = "myName"; SerializableParameter parameter = new QueryParameter(); parameter.setName("myName"); parameter.setAllowEmptyValue(false); MultiMap params = MultiMap.caseInsensitiveMultiMap(); params.add(name, ""); abstractSerializableParameterExtractor.extract(name, parameter, params); }
Example 13
Source File: ApiClient.java From vertx-web with Apache License 2.0 | 5 votes |
/** * Add cookie object with form style and not exploded * +----------------+---------+---------------+-------------------------------------+----------------------------------------+ | form | false | query, cookie | color=blue,black,brown | color=R,100,G,200,B,150 | +----------------+---------+---------------+-------------------------------------+----------------------------------------+ * * @param paramName * @param values */ private void renderCookieObjectForm(String paramName, Map<String, Object> values, MultiMap map) { List<String> listToSerialize = new ArrayList<>(); for (Map.Entry<String, Object> entry : values.entrySet()) { listToSerialize.add(entry.getKey()); listToSerialize.add(String.valueOf(entry.getValue())); } String value = String.join(",", listToSerialize); map.remove(paramName); map.add(paramName, value); }
Example 14
Source File: AbstractSerializableParameterExtractorTest.java From vertx-swagger with Apache License 2.0 | 5 votes |
@Test(expected = IllegalArgumentException.class) public void testNullAllowEmptyValueWithEmptyParameter() { String name = "myName"; SerializableParameter parameter = new QueryParameter(); parameter.setName("myName"); MultiMap params = MultiMap.caseInsensitiveMultiMap(); params.add(name, ""); abstractSerializableParameterExtractor.extract(name, parameter, params); }
Example 15
Source File: FakeApiImpl.java From openapi-generator with Apache License 2.0 | 5 votes |
/** * To test enum parameters * To test enum parameters * @param enumHeaderStringArray Header parameter enum test (string array) (optional, default to new ArrayList<>()) * @param enumHeaderString Header parameter enum test (string) (optional, default to -efg) * @param enumQueryStringArray Query parameter enum test (string array) (optional, default to new ArrayList<>()) * @param enumQueryString Query parameter enum test (string) (optional, default to -efg) * @param enumQueryInteger Query parameter enum test (double) (optional) * @param enumQueryDouble Query parameter enum test (double) (optional) * @param enumFormStringArray Form parameter enum test (string array) (optional, default to $) * @param enumFormString Form parameter enum test (string) (optional, default to -efg) * @param resultHandler Asynchronous result handler */ public void testEnumParameters(List<String> enumHeaderStringArray, String enumHeaderString, List<String> enumQueryStringArray, String enumQueryString, Integer enumQueryInteger, Double enumQueryDouble, List<String> enumFormStringArray, String enumFormString, Handler<AsyncResult<Void>> resultHandler) { Object localVarBody = null; // create path and map variables String localVarPath = "/fake"; // query params List<Pair> localVarQueryParams = new ArrayList<>(); localVarQueryParams.addAll(apiClient.parameterToPairs("csv", "enum_query_string_array", enumQueryStringArray)); localVarQueryParams.addAll(apiClient.parameterToPairs("", "enum_query_string", enumQueryString)); localVarQueryParams.addAll(apiClient.parameterToPairs("", "enum_query_integer", enumQueryInteger)); localVarQueryParams.addAll(apiClient.parameterToPairs("", "enum_query_double", enumQueryDouble)); // header params MultiMap localVarHeaderParams = MultiMap.caseInsensitiveMultiMap(); if (enumHeaderStringArray != null) localVarHeaderParams.add("enum_header_string_array", apiClient.parameterToString(enumHeaderStringArray)); if (enumHeaderString != null) localVarHeaderParams.add("enum_header_string", apiClient.parameterToString(enumHeaderString)); // cookie params MultiMap localVarCookieParams = MultiMap.caseInsensitiveMultiMap(); // form params // TODO: sending files within multipart/form-data is not supported yet (because of vertx web-client) Map<String, Object> localVarFormParams = new HashMap<>(); if (enumFormStringArray != null) localVarFormParams.put("enum_form_string_array", enumFormStringArray); if (enumFormString != null) localVarFormParams.put("enum_form_string", enumFormString); String[] localVarAccepts = { }; String[] localVarContentTypes = { "application/x-www-form-urlencoded" }; String[] localVarAuthNames = new String[] { }; apiClient.invokeAPI(localVarPath, "GET", localVarQueryParams, localVarBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAccepts, localVarContentTypes, localVarAuthNames, null, resultHandler); }
Example 16
Source File: OpenAPI3ValidationTest.java From vertx-web with Apache License 2.0 | 5 votes |
@Test public void testFormArrayParameter() throws Exception { Operation op = testSpec.getPaths().get("/formTests/arraytest").getPost(); if(op.getParameters()==null) op.setParameters(new ArrayList<>()); OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec, refsCache); loadHandlers("/formTests/arraytest", HttpMethod.POST, false, validationHandler, (routingContext) -> { RequestParameters params = routingContext.get("parsedParameters"); List<String> result = new ArrayList<>(); for (RequestParameter r : params.formParameter("values").getArray()) result.add(r.getInteger().toString()); routingContext.response().setStatusMessage(params.formParameter("id").getString() + serializeInCSVStringArray (result)).end(); }); String id = "anId"; List<String> valuesArray = new ArrayList<>(); for (int i = 0; i < 4; i++) valuesArray.add(getSuccessSample(ParameterType.INT).getInteger().toString()); String values = serializeInCSVStringArray(valuesArray); MultiMap form = MultiMap.caseInsensitiveMultiMap(); form.add("id", id); form.add("values", values); testRequestWithForm(HttpMethod.POST, "/formTests/arraytest", FormType.FORM_URLENCODED, form, 200, id + values); }
Example 17
Source File: BridgeUtils.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
public static JsonObject createBridgeConsumer(JsonObject config, String bridgeHost, int bridgePort, String groupId, WebClient client, Map<String, String> additionalHeaders) throws InterruptedException, ExecutionException, TimeoutException { MultiMap headers = MultiMap.caseInsensitiveMultiMap() .add("Content-length", String.valueOf(config.toBuffer().length())) .add("Content-type", Constants.KAFKA_BRIDGE_JSON); for (Map.Entry<String, String> header : additionalHeaders.entrySet()) { LOGGER.info("Adding header {} -> {}", header.getKey(), header.getValue()); headers.add(header.getKey(), header.getValue()); } CompletableFuture<JsonObject> future = new CompletableFuture<>(); client.post(bridgePort, bridgeHost, "/consumers/" + groupId) .putHeaders(headers) .as(BodyCodec.jsonObject()) .sendJsonObject(config, ar -> { if (ar.succeeded()) { HttpResponse<JsonObject> response = ar.result(); JsonObject bridgeResponse = response.body(); String consumerInstanceId = bridgeResponse.getString("instance_id"); String consumerBaseUri = bridgeResponse.getString("base_uri"); LOGGER.debug("ConsumerInstanceId: {}", consumerInstanceId); LOGGER.debug("ConsumerBaseUri: {}", consumerBaseUri); future.complete(response.body()); } else { LOGGER.error("Cannot create consumer", ar.cause()); future.completeExceptionally(ar.cause()); } }); return future.get(1, TimeUnit.MINUTES); }
Example 18
Source File: OAuth.java From openapi-generator with Apache License 2.0 | 4 votes |
@Override public void applyToParams(List<Pair> queryParams, MultiMap headerParams, MultiMap cookieParams) { if (accessToken != null) { headerParams.add("Authorization", "Bearer " + accessToken); } }
Example 19
Source File: ParametersTestAPIClient.java From vertx-web with Apache License 2.0 | 4 votes |
private void renderCookieParam(String paramName, Object value, MultiMap map) { map.remove(paramName); map.add(paramName, String.valueOf(value)); }
Example 20
Source File: BufferedHttpOutputMessage.java From vertx-rest-client with Apache License 2.0 | 4 votes |
public void putAllHeaders(MultiMap headers) { for (Map.Entry<String, String> header : headers) { headers.add(header.getKey(), header.getValue()); } }