List of usage examples for io.vertx.core MultiMap names
Set<String> names();
From source file:co.runrightfast.core.utils.VertxUtils.java
License:Apache License
static JsonObject toJsonObject(@NonNull final MultiMap map) { if (map.isEmpty()) { return EMPTY_OBJECT; }/*from w ww .j a va 2 s. co m*/ final JsonObjectBuilder json = Json.createObjectBuilder(); map.names().stream().forEach(name -> { final List<String> values = map.getAll(name); if (values.size() == 1) { json.add(name, values.get(0)); } else { json.add(name, JsonUtils.toJsonArray(values)); } }); return json.build(); }
From source file:io.nitor.api.backend.proxy.SimpleLogProxyTracer.java
License:Apache License
String dumpHeaders(MultiMap h, String indent) { StringBuilder sb = new StringBuilder(); for (String name : h.names()) { sb.append("\n").append(indent).append(name).append(": ").append(h.getAll(name).stream() .reduce((partial, element) -> partial + "\n" + indent + " " + element).orElse("")); }// w w w. j a va 2s.com return sb.toString(); }
From source file:io.servicecomb.foundation.vertx.http.VertxServerRequestToHttpServletRequest.java
License:Apache License
@Override public Map<String, String[]> getParameterMap() { Map<String, String[]> paramMap = new HashMap<>(); MultiMap map = this.vertxRequest.params(); for (String name : map.names()) { List<String> valueList = map.getAll(name); paramMap.put(name, (String[]) map.getAll(name).toArray(new String[valueList.size()])); }// ww w . j a v a 2 s. co m return paramMap; }
From source file:org.apache.servicecomb.foundation.vertx.http.VertxServerRequestToHttpServletRequest.java
License:Apache License
@Override public Map<String, String[]> getParameterMap() { if (parameterMap == null) { Map<String, String[]> paramMap = new HashMap<>(); MultiMap map = this.vertxRequest.params(); for (String name : map.names()) { List<String> valueList = map.getAll(name); paramMap.put(name, map.getAll(name).toArray(new String[valueList.size()])); }/* w w w. j a va2 s.c om*/ parameterMap = paramMap; } return parameterMap; }
From source file:org.hawkular.alerts.handlers.util.ResponseUtil.java
License:Apache License
public static void checkForUnknownQueryParams(MultiMap params, final Set<String> expected) { if (params.contains(PARAM_IGNORE_UNKNOWN_QUERY_PARAMS)) { return;/*w ww. j ava 2 s . c o m*/ } Set<String> unknown = params.names().stream().filter(p -> !expected.contains(p)) .collect(Collectors.toSet()); if (!unknown.isEmpty()) { String message = "Unknown Query Parameter(s): " + unknown.toString(); throw new IllegalArgumentException(message); } }
From source file:org.sfs.filesystem.volume.DigestBlob.java
License:Apache License
public DigestBlob(HttpClientResponse httpClientResponse) { super(httpClientResponse); digests = new HashMap<>(); BaseEncoding baseEncoding = base64(); MultiMap headers = httpClientResponse.headers(); for (String headerName : headers.names()) { Matcher matcher = COMPUTED_DIGEST.matcher(headerName); if (matcher.find()) { String digestName = matcher.group(1); Optional<MessageDigestFactory> oMessageDigestFactory = fromValueIfExists(digestName); if (oMessageDigestFactory.isPresent()) { MessageDigestFactory messageDigestFactory = oMessageDigestFactory.get(); withDigest(messageDigestFactory, baseEncoding.decode(headers.get(headerName))); }//from www. j a v a2s . c o m } } }
From source file:org.sfs.metadata.Metadata.java
License:Apache License
public Metadata withHttpHeaders(MultiMap headers) { Set<String> processed = new HashSet<>(); // adds first for (String headerName : headers.names()) { Matcher matcher = addParser.matcher(headerName); if (matcher.find()) { List<String> values = headers.getAll(headerName); if (values != null && !values.isEmpty()) { String metaName = matcher.group(1); removeAll(metaName);// w ww . ja va2s . c o m for (String value : values) { for (String split : on(',').omitEmptyStrings().trimResults().split(value)) { processed.add(metaName); put(metaName, split); } } } } } // then deletes for (String headerName : headers.names()) { Matcher matcher0 = addParser.matcher(headerName); if (matcher0.find()) { String metaName = matcher0.group(1); if (processed.add(metaName)) { List<String> values = headers.getAll(headerName); boolean hasData = false; if (values != null) { for (String value : values) { if (value != null) { value = value.trim(); if (!value.isEmpty()) { hasData = true; break; } } } } if (!hasData) { removeAll(metaName); } } } Matcher matcher1 = removeParser.matcher(headerName); if (matcher1.find()) { String metaName = matcher1.group(1); if (processed.add(metaName)) { removeAll(metaName); } } } return this; }
From source file:org.sfs.nodes.data.ChecksumBlob.java
License:Apache License
@Override public void handle(final SfsRequest httpServerRequest) { VertxContext<Server> vertxContext = httpServerRequest.vertxContext(); aVoid().flatMap(new Authenticate(httpServerRequest)) .flatMap(new ValidateActionAdminOrSystem(httpServerRequest)) .map(new ValidateNodeIsDataNode<>(vertxContext)).map(aVoid -> httpServerRequest) .map(new ValidateParamExists(VOLUME)).map(new ValidateParamExists(POSITION)) .map(new ValidateParamBetweenLong(POSITION, 0, MAX_VALUE)) .map(new ValidateParamBetweenLong(LENGTH, 0, MAX_VALUE)) .map(new ValidateParamBetweenLong(OFFSET, 0, MAX_VALUE)).map(new ValidateParamComputedDigest()) .flatMap(httpServerRequest1 -> { MultiMap params = httpServerRequest1.params(); final Iterable<MessageDigestFactory> iterable = from(params.names()) .transform(new Function<String, Optional<MessageDigestFactory>>() { @Override public Optional<MessageDigestFactory> apply(String param) { Matcher matcher = COMPUTED_DIGEST.matcher(param); if (matcher.matches()) { String digestName = matcher.group(1); return fromValueIfExists(digestName); }/* w w w .ja v a2 s. c o m*/ return absent(); } }).filter(Optional::isPresent).transform(input -> input.get()); MultiMap queryParams = httpServerRequest1.params(); String volumeId = queryParams.get(VOLUME); long position = parseLong(queryParams.get(POSITION)); Optional<Long> oOffset; if (queryParams.contains(OFFSET)) { oOffset = of(parseLong(queryParams.get(OFFSET))); } else { oOffset = absent(); } Optional<Long> oLength; if (queryParams.contains(LENGTH)) { oLength = of(parseLong(queryParams.get(LENGTH))); } else { oLength = absent(); } // let the client know we're alive by sending pings on the response stream httpServerRequest1.startProxyKeepAlive(); LocalNode localNode = new LocalNode(vertxContext, vertxContext.verticle().nodes().volumeManager()); return localNode .checksum(volumeId, position, oOffset, oLength, toArray(iterable, MessageDigestFactory.class)) .map(digestBlobOptional -> new Holder2<>(httpServerRequest1, digestBlobOptional)); }).flatMap(holder -> httpServerRequest.stopKeepAlive().map(aVoid -> holder)) .onErrorResumeNext(throwable -> httpServerRequest.stopKeepAlive() .flatMap(aVoid -> Observable.<Holder2<SfsRequest, Optional<DigestBlob>>>error(throwable))) .single().onErrorResumeNext(new HandleServerToBusy<>()) .subscribe(new Terminus<Holder2<SfsRequest, Optional<DigestBlob>>>(httpServerRequest) { @Override public void onNext(Holder2<SfsRequest, Optional<DigestBlob>> holder) { Optional<DigestBlob> oJsonDigestBlob = holder.value1(); JsonObject jsonResponse = new JsonObject(); if (oJsonDigestBlob.isPresent()) { jsonResponse.put("code", HTTP_OK).put("blob", oJsonDigestBlob.get().toJsonObject()); } else { jsonResponse.put("code", HTTP_NOT_FOUND); } HttpServerResponse httpResponse = holder.value0().response(); httpResponse.write(jsonResponse.encode(), UTF_8.toString()).write(DELIMITER_BUFFER); } }); }
From source file:org.sfs.nodes.data.PutBlob.java
License:Apache License
@Override public void handle(final SfsRequest httpServerRequest) { httpServerRequest.pause();/*w w w . ja v a 2 s . c o m*/ VertxContext<Server> vertxContext = httpServerRequest.vertxContext(); aVoid().flatMap(new Authenticate(httpServerRequest)) .flatMap(new ValidateActionAdminOrSystem(httpServerRequest)) .map(new ValidateNodeIsDataNode<>(vertxContext)).map(aVoid -> httpServerRequest) .map(new ValidateParamExists(VOLUME)).map(new ValidateHeaderExists(CONTENT_LENGTH)) .map(new ValidateHeaderBetweenLong(CONTENT_LENGTH, 0, MAX_VALUE)) .map(new ValidateParamComputedDigest()).map(new ToVoid<>()).map(aVoid -> httpServerRequest) .flatMap(httpServerRequest1 -> { MultiMap headers = httpServerRequest1.headers(); MultiMap params = httpServerRequest1.params(); String volumeId = params.get(VOLUME); final Iterable<MessageDigestFactory> iterable = from(params.names()) .transform(new Function<String, Optional<MessageDigestFactory>>() { @Override public Optional<MessageDigestFactory> apply(String param) { Matcher matcher = COMPUTED_DIGEST.matcher(param); if (matcher.find()) { String digestName = matcher.group(1); return fromValueIfExists(digestName); } return absent(); } }).filter(Optional::isPresent).transform(input -> input.get()); VolumeManager volumeManager = vertxContext.verticle().nodes().volumeManager(); if (!volumeManager.isOpen()) { throw new HttpStatusCodeException("VolumeManager not open", HTTP_UNAVAILABLE); } Volume volume = volumeManager.get(volumeId).orNull(); if (volume == null) { throw new HttpStatusCodeException(String.format("Volume %s not found", volumeId), HTTP_UNAVAILABLE); } if (!Volume.Status.STARTED.equals(volume.status())) { throw new HttpStatusCodeException(String.format("Volume %s not started", volumeId), HTTP_UNAVAILABLE); } long length = parseLong(headers.get(CONTENT_LENGTH)); httpServerRequest1.startProxyKeepAlive(); return volume.putDataStream(httpServerRequest1.vertxContext().vertx(), length) .flatMap(writeStreamBlob -> { DigestReadStream digestReadStream = new DigestReadStream(httpServerRequest1, toArray(iterable, MessageDigestFactory.class)); CountingReadStream countingReadStream = new CountingReadStream(digestReadStream); return writeStreamBlob.consume(countingReadStream).map(aVoid1 -> { DigestBlob digestBlob = new DigestBlob(writeStreamBlob.getVolume(), writeStreamBlob.getPosition(), countingReadStream.count()); for (Holder2<MessageDigestFactory, byte[]> digest : digestReadStream .digests()) { digestBlob.withDigest(digest.value0(), digest.value1()); } return new Holder2<>(httpServerRequest1, of(digestBlob)); }); }); }).single().onErrorResumeNext(new HandleServerToBusy<>()) .subscribe(new Terminus<Holder2<SfsRequest, Optional<DigestBlob>>>(httpServerRequest) { @Override public void onNext(Holder2<SfsRequest, Optional<DigestBlob>> holder) { Optional<DigestBlob> oJsonDigestBlob = holder.value1(); JsonObject jsonResponse = new JsonObject(); if (oJsonDigestBlob.isPresent()) { jsonResponse.put("code", HTTP_OK).put("blob", oJsonDigestBlob.get().toJsonObject()); } else { jsonResponse.put("code", HTTP_INTERNAL_ERROR); } HttpServerResponse httpResponse = holder.value0().response(); httpResponse.write(jsonResponse.encode(), UTF_8.toString()).write(DELIMITER_BUFFER); } }); }
From source file:org.sfs.util.HttpClientResponseHeaderLogger.java
License:Apache License
@Override public HttpClientResponse call(HttpClientResponse httpClientResponse) { if (LOGGER.isDebugEnabled()) { StringBuilder sb = new StringBuilder(); sb.append("\r\nHttp Header Dump >>>>>\r\n\r\n"); sb.append(format("HTTP/1.1 %d %s\r\n", httpClientResponse.statusCode(), httpClientResponse.statusMessage())); MultiMap headers = httpClientResponse.headers(); for (String headerName : headers.names()) { List<String> values = headers.getAll(headerName); sb.append(format("%s: %s\r\n", headerName, on(',').join(values))); }/* w ww.j a va 2s. co m*/ sb.append("\r\n"); sb.append("Http Header Dump <<<<<\r\n"); LOGGER.debug(sb.toString()); } return httpClientResponse; }