Example usage for io.vertx.core MultiMap add

List of usage examples for io.vertx.core MultiMap add

Introduction

In this page you can find the example usage for io.vertx.core MultiMap add.

Prototype

@GenIgnore(GenIgnore.PERMITTED_TYPE)
@Fluent
MultiMap add(CharSequence name, Iterable<CharSequence> values);

Source Link

Document

Like #add(String,Iterable) but accepting CharSequence as parameters

Usage

From source file:org.eclipse.hono.devices.HonoHttpDevice.java

License:Open Source License

/**
 * Send messages to Hono HTTP adapter in a sequence.
 * <p>/*from  ww  w.  ja  va  2s .c  om*/
 * Alternate the event every 4th time to be an event.
 */
protected void sendData() {
    // Send single messages sequentially in a loop and print a summary of the message deliveries.
    System.out.println(String.format("Total number of messages: %s", messages.size()));

    messages.stream().forEachOrdered(messageType -> {
        final MultiMap headerMap = MultiMap.caseInsensitiveMultiMap();
        headerMap.add(HttpHeaders.CONTENT_TYPE, messageType.contentType);
        Optional.ofNullable(messageType.ttd).ifPresent(
                timeToDeliver -> headerMap.add(Constants.HEADER_TIME_TIL_DISCONNECT, timeToDeliver.toString()));

        System.out.println(String.format("Sending message type %s", messageType.toString()));

        final CompletableFuture<MultiMap> responseFuture = sendMessage(messageType.payload, headerMap,
                messageType.isEvent);
        try {
            final MultiMap resultMap = responseFuture.get();
            System.out.println(String.format("Got %d response keys.", resultMap.size()));
            resultMap.entries().stream().forEach(entry -> {
                System.out.println(String.format("  %s:%s", entry.getKey(), entry.getValue()));
            });
        } catch (final InterruptedException e) {
            e.printStackTrace();
        } catch (final ExecutionException e) {
            e.printStackTrace();
        }
    });

    // give some time for flushing asynchronous message buffers before shutdown
    vertx.setTimer(2000, timerId -> {
        vertx.close();
    });
}

From source file:org.entcore.common.http.request.JsonHttpServerRequest.java

License:Open Source License

@Override
public MultiMap headers() {
    MultiMap m = new CaseInsensitiveHeaders();
    JsonObject h = object.getJsonObject("headers");
    if (h != null) {
        for (String attr : h.fieldNames()) {
            m.add(attr, h.getString(attr));
        }//from www  .j a  v  a2 s .c  o  m
    }
    return m;
}

From source file:org.entcore.common.http.request.JsonHttpServerRequest.java

License:Open Source License

@Override
public MultiMap params() {
    MultiMap m = new CaseInsensitiveHeaders();
    JsonObject p = object.getJsonObject("params");
    if (p != null) {
        for (String attr : p.fieldNames()) {
            m.add(attr, p.getString(attr));
        }//from  ww w  .  j a v a 2s. co  m
    }
    return m;
}

From source file:org.entcore.directory.services.impl.HttpHeaderUtils.java

License:Open Source License

public static void addHeaderLastModified(MultiMap headers, Date modifiedDate) {
    headers.add("Last-Modified", httpDateFormat.format(modifiedDate));
    headers.add("Cache-Control", "must-revalidate, max-age=0");
}

From source file:org.etourdot.vertx.marklogic.http.impl.request.DefaultMultiPartRequest.java

License:Open Source License

private static HttpPart constructHttpPart(Document document, Buffer buffer, String mimeType) {
    HttpPart contentHttpPart = new HttpPart();
    MultiMap headers = new CaseInsensitiveHeaders();
    if (mimeType != null) {
        headers.add(HttpHeaders.CONTENT_TYPE, mimeType);
    } else {/*from  w w  w .j av a2s.c  o m*/
        headers.add(HttpHeaders.CONTENT_TYPE, Format.JSON.getDefaultMimetype());
    }
    headers.add(HttpHeaders.CONTENT_LENGTH, Integer.toString(buffer.length()));
    headers.add(HttpUtils.HEADER_CONTENT_DISPOSITION, computeContentDisposition(document, mimeType != null));
    contentHttpPart.headers(headers).buffer(buffer);
    return contentHttpPart;
}

From source file:org.sfs.nodes.compute.container.VerifyRepairAllContainersExecute.java

License:Apache License

@Override
public void handle(final SfsRequest httpServerRequest) {

    VertxContext<Server> vertxContext = httpServerRequest.vertxContext();

    Defer.aVoid().flatMap(new Authenticate(httpServerRequest))
            .flatMap(new ValidateActionAdminOrSystem(httpServerRequest)).map(aVoid -> httpServerRequest)
            .map(new ToVoid<>()).flatMap(aVoid -> {
                ClusterInfo clusterInfo = vertxContext.verticle().getClusterInfo();
                Nodes nodes = vertxContext.verticle().nodes();
                MultiMap headers = httpServerRequest.headers();

                long timeout = headers.contains(Jobs.Parameters.TIMEOUT)
                        ? Long.parseLong(headers.get(Jobs.Parameters.TIMEOUT))
                        : 100;//from  ww  w .j a va  2  s  . c o  m

                String unparsedForceRemoveVolumes = headers.contains(Jobs.Parameters.FORCE_REMOVE_VOLUMES)
                        ? headers.get(Jobs.Parameters.FORCE_REMOVE_VOLUMES)
                        : null;

                MultiMap params = MultiMap.caseInsensitiveMultiMap();
                if (unparsedForceRemoveVolumes != null) {
                    params.add(Jobs.Parameters.FORCE_REMOVE_VOLUMES, unparsedForceRemoveVolumes);
                }

                TransientServiceDef transientServiceDef = clusterInfo.getCurrentMasterNode();
                MasterNode masterNode = nodes.remoteMasterNode(vertxContext, transientServiceDef);

                httpServerRequest.startProxyKeepAlive();

                return masterNode.executeJob(Jobs.ID.VERIFY_REPAIR_ALL_CONTAINERS_OBJECTS, params, timeout,
                        TimeUnit.MILLISECONDS);
            }).single().subscribe(new ConnectionCloseTerminus<Void>(httpServerRequest) {
                @Override
                public void onNext(Void aVoid) {
                    JsonObject responseJson = new JsonObject().put("code", HTTP_OK).put("message", "Success");
                    httpServerRequest.response().write(responseJson.encode(), StandardCharsets.UTF_8.toString())
                            .write(DELIMITER_BUFFER);
                }
            });
}

From source file:org.sfs.nodes.compute.container.VerifyRepairContainerExecute.java

License:Apache License

@Override
public void handle(final SfsRequest httpServerRequest) {

    VertxContext<Server> vertxContext = httpServerRequest.vertxContext();

    Defer.aVoid().flatMap(new Authenticate(httpServerRequest))
            .flatMap(new ValidateActionAdminOrSystem(httpServerRequest)).map(aVoid -> httpServerRequest)
            .map(new ValidateHeaderBetweenLong(Jobs.Parameters.TIMEOUT, 100, Long.MAX_VALUE))
            .map(new ToVoid<>()).map(aVoid -> ObjectPath.fromSfsRequest(httpServerRequest))
            .map(new ValidateContainerPath()).flatMap(objectPath -> {
                ClusterInfo clusterInfo = vertxContext.verticle().getClusterInfo();
                Nodes nodes = vertxContext.verticle().nodes();
                MultiMap headers = httpServerRequest.headers();

                long timeout = headers.contains(Jobs.Parameters.TIMEOUT)
                        ? Long.parseLong(headers.get(Jobs.Parameters.TIMEOUT))
                        : 100;/* w ww.  j  av  a 2  s.  c  o m*/

                String unparsedForceRemoveVolumes = headers.contains(Jobs.Parameters.FORCE_REMOVE_VOLUMES)
                        ? headers.get(Jobs.Parameters.FORCE_REMOVE_VOLUMES)
                        : null;

                MultiMap params = MultiMap.caseInsensitiveMultiMap();
                if (unparsedForceRemoveVolumes != null) {
                    params.add(Jobs.Parameters.FORCE_REMOVE_VOLUMES, unparsedForceRemoveVolumes);
                }
                params.set(Jobs.Parameters.CONTAINER_ID, objectPath.containerPath().get());

                TransientServiceDef transientServiceDef = clusterInfo.getCurrentMasterNode();
                MasterNode masterNode = nodes.remoteMasterNode(vertxContext, transientServiceDef);

                httpServerRequest.startProxyKeepAlive();

                return masterNode.executeJob(Jobs.ID.VERIFY_REPAIR_CONTAINER_OBJECTS, params, timeout,
                        TimeUnit.MILLISECONDS);
            }).single().subscribe(new ConnectionCloseTerminus<Void>(httpServerRequest) {
                @Override
                public void onNext(Void aVoid) {
                    JsonObject responseJson = new JsonObject().put("code", HTTP_OK).put("message", "Success");
                    httpServerRequest.response().write(responseJson.encode(), StandardCharsets.UTF_8.toString())
                            .write(DELIMITER_BUFFER);
                }
            });
}

From source file:org.sfs.nodes.compute.object.VerifyRepairObjectExecute.java

License:Apache License

@Override
public void handle(final SfsRequest httpServerRequest) {

    VertxContext<Server> vertxContext = httpServerRequest.vertxContext();

    Defer.aVoid().flatMap(new Authenticate(httpServerRequest))
            .flatMap(new ValidateActionAdminOrSystem(httpServerRequest)).map(aVoid -> httpServerRequest)
            .map(new ValidateHeaderBetweenLong(Jobs.Parameters.TIMEOUT, 100, Long.MAX_VALUE))
            .map(new ToVoid<>()).map(aVoid -> ObjectPath.fromSfsRequest(httpServerRequest))
            .map(new ValidateObjectPath()).flatMap(objectPath -> {
                ClusterInfo clusterInfo = vertxContext.verticle().getClusterInfo();
                Nodes nodes = vertxContext.verticle().nodes();
                MultiMap headers = httpServerRequest.headers();

                long timeout = headers.contains(Jobs.Parameters.TIMEOUT)
                        ? Long.parseLong(headers.get(Jobs.Parameters.TIMEOUT))
                        : 100;//ww w.j a  va2s  .c o m

                String unparsedForceRemoveVolumes = headers.contains(Jobs.Parameters.FORCE_REMOVE_VOLUMES)
                        ? headers.get(Jobs.Parameters.FORCE_REMOVE_VOLUMES)
                        : null;

                MultiMap params = MultiMap.caseInsensitiveMultiMap();
                if (unparsedForceRemoveVolumes != null) {
                    params.add(Jobs.Parameters.FORCE_REMOVE_VOLUMES, unparsedForceRemoveVolumes);
                }
                params.set(Jobs.Parameters.OBJECT_ID, objectPath.objectPath().get());

                TransientServiceDef transientServiceDef = clusterInfo.getCurrentMasterNode();
                MasterNode masterNode = nodes.remoteMasterNode(vertxContext, transientServiceDef);

                httpServerRequest.startProxyKeepAlive();

                return masterNode.executeJob(Jobs.ID.VERIFY_REPAIR_OBJECT, params, timeout,
                        TimeUnit.MILLISECONDS);
            }).single().subscribe(new ConnectionCloseTerminus<Void>(httpServerRequest) {
                @Override
                public void onNext(Void aVoid) {
                    JsonObject responseJson = new JsonObject().put("code", HTTP_OK).put("message", "Success");
                    httpServerRequest.response().write(responseJson.encode(), StandardCharsets.UTF_8.toString())
                            .write(DELIMITER_BUFFER);
                }
            });
}