Example usage for io.vertx.core MultiMap get

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

Introduction

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

Prototype

@Nullable
String get(String name);

Source Link

Document

Returns the value of with the specified name.

Usage

From source file:org.sfs.SfsRequest.java

License:Apache License

public SfsRequest startProxyKeepAlive() {
    MultiMap headers = httpServerRequest.headers();
    long keepAliveTimeout = Long.parseLong(
            headers.contains(X_SFS_KEEP_ALIVE_TIMEOUT) ? headers.get(X_SFS_KEEP_ALIVE_TIMEOUT) : "10000");
    startProxyKeepAlive(keepAliveTimeout, MILLISECONDS);
    return this;
}

From source file:org.sfs.util.SfsHttpUtil.java

License:Apache License

public static String getRemoteServiceUrl(HttpServerRequest httpServerRequest) {
    try {/*from  w w  w.j  a  va  2s  .  c  om*/
        URI absoluteRequestURI = new URI(httpServerRequest.absoluteURI());
        MultiMap headers = httpServerRequest.headers();

        String host = getFirstHeader(httpServerRequest, "X-Forwarded-Host");
        String contextRoot = getFirstHeader(httpServerRequest, SfsHttpHeaders.X_CONTEXT_ROOT);
        if (host == null)
            host = getFirstHeader(httpServerRequest, HttpHeaders.HOST);
        if (host == null)
            host = absoluteRequestURI.getHost();
        String proto = headers.get(HttpHeaders.X_FORWARDED_PROTO);
        if (proto == null)
            proto = absoluteRequestURI.getScheme();

        String serviceUrl;
        if (contextRoot != null) {
            serviceUrl = String.format("%s://%s/%s", proto, host, contextRoot);
        } else {
            serviceUrl = String.format("%s://%s", proto, host);
        }
        return serviceUrl;
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.sfs.validate.ValidateActionAdminOrSystem.java

License:Apache License

@Override
public Observable<Void> call(Void aVoid) {
    Server verticle = sfsRequest.vertxContext().verticle();
    AuthProviderService authProvider = verticle.authProviderService();
    return authProvider.canAdmin(sfsRequest).map(canDo -> {
        if (!canDo) {
            MultiMap headers = sfsRequest.headers();
            if (headers.contains(X_SFS_REMOTE_NODE_TOKEN)) {
                byte[] actualToken = null;
                try {
                    actualToken = base64().decode(headers.get(X_SFS_REMOTE_NODE_TOKEN));
                } catch (Throwable ignore) {
                }/*  w  w  w.j a v  a 2s.  c  om*/
                byte[] expectedToken = verticle.getRemoteNodeSecret();
                if (Arrays.equals(expectedToken, actualToken)) {
                    // autenticated
                    return null;
                }
            }
            JsonObject jsonObject = new JsonObject().put("message", "Admin and System Action Forbidden");
            throw new HttpRequestValidationException(HTTP_FORBIDDEN, jsonObject);
        }
        return null;
    });
}

From source file:org.sfs.validate.ValidateHeaderBetweenInteger.java

License:Apache License

@Override
public SfsRequest call(SfsRequest httpServerRequest) {
    MultiMap headers = httpServerRequest.headers();

    String value = headers.get(headerName);
    if (value != null) {
        Integer parsed = tryParse(value);
        if (parsed == null || parsed < min || parsed > max) {
            JsonObject jsonObject = new JsonObject().put("message",
                    format("%s must be between %d and %d", headerName, min, max));

            throw new HttpRequestValidationException(HTTP_BAD_REQUEST, jsonObject);
        }/*from  w w w. ja  v  a2  s.co  m*/
    }
    return httpServerRequest;
}

From source file:org.sfs.validate.ValidateHeaderBetweenLong.java

License:Apache License

@Override
public SfsRequest call(SfsRequest httpServerRequest) {
    MultiMap headers = httpServerRequest.headers();

    String value = headers.get(headerName);
    if (value != null) {
        Long parsed = tryParse(value);
        if (parsed == null || parsed < min || parsed > max) {
            JsonObject jsonObject = new JsonObject().put("message",
                    format("%s must be between %d and %d", headerName, min, max));

            throw new HttpRequestValidationException(HTTP_BAD_REQUEST, jsonObject);
        }//ww  w  .ja  v a  2  s .  co  m
    }
    return httpServerRequest;
}

From source file:org.sfs.validate.ValidateHeaderExists.java

License:Apache License

@Override
public SfsRequest call(SfsRequest httpServerRequest) {
    MultiMap headers = httpServerRequest.headers();

    String value = headers.get(headerName);
    if (value == null) {
        JsonObject jsonObject = new JsonObject().put("message", format("%s is required", headerName));

        throw new HttpRequestValidationException(HTTP_BAD_REQUEST, jsonObject);
    }/*from w w  w .  jav a2  s .  c  o  m*/
    return httpServerRequest;
}

From source file:org.sfs.validate.ValidateHeaderIsBase16LowercaseEncoded.java

License:Apache License

@Override
public SfsRequest call(SfsRequest httpServerRequest) {
    MultiMap headers = httpServerRequest.headers();

    String value = headers.get(headerName);
    if (value != null) {
        boolean failed = false;
        BaseEncoding baseEncoding = base16().lowerCase();
        try {//  w  w  w . j a v  a2  s .  c  o  m
            byte[] decoded = baseEncoding.decode(value);
            if (decoded == null) {
                failed = true;
            } else {
                String encoded = baseEncoding.encode(decoded);
                if (!value.equals(encoded)) {
                    failed = true;
                }
            }
        } catch (Throwable e) {
            // do nothing
        }
        if (failed) {
            JsonObject jsonObject = new JsonObject().put("message",
                    format("%s must be Base16 lowercase encoded", headerName));

            throw new HttpRequestValidationException(HTTP_BAD_REQUEST, jsonObject);
        }
    }
    return httpServerRequest;
}

From source file:org.sfs.validate.ValidateHeaderIsBase64Encoded.java

License:Apache License

@Override
public SfsRequest call(SfsRequest httpServerRequest) {
    MultiMap headers = httpServerRequest.headers();

    String value = headers.get(headerName);
    if (value != null) {
        boolean failed = false;
        BaseEncoding baseEncoding = base64();
        try {/*from ww  w .  j  av  a 2  s.c  o  m*/
            byte[] decoded = baseEncoding.decode(value);
            if (decoded == null || !value.equals(baseEncoding.encode(decoded))) {
                failed = true;
            }
        } catch (Throwable e) {
            // do nothing
        }
        if (failed) {
            JsonObject jsonObject = new JsonObject().put("message",
                    format("%s must be Base64 encoded", headerName));

            throw new HttpRequestValidationException(HTTP_BAD_REQUEST, jsonObject);
        }
    }
    return httpServerRequest;
}

From source file:org.sfs.validate.ValidateHeaderIsBoolean.java

License:Apache License

@Override
public SfsRequest call(SfsRequest httpServerRequest) {
    MultiMap headers = httpServerRequest.headers();

    String value = headers.get(headerName);
    if (value != null) {
        if (!"true".equalsIgnoreCase(value) && !"false".equalsIgnoreCase(value)) {
            JsonObject jsonObject = new JsonObject().put("message",
                    format("%s must \"true\" or \"false\"", headerName));

            throw new HttpRequestValidationException(HTTP_BAD_REQUEST, jsonObject);
        }/*from   w  w w  .  j av  a2s  . co m*/
    }
    return httpServerRequest;
}

From source file:org.sfs.validate.ValidateHeaderNotExists.java

License:Apache License

@Override
public SfsRequest call(SfsRequest httpServerRequest) {
    MultiMap headers = httpServerRequest.headers();

    String value = headers.get(headerName);
    if (value != null) {
        JsonObject jsonObject = new JsonObject().put("message", format("%s  is not supported", headerName));

        throw new HttpRequestValidationException(HTTP_BAD_REQUEST, jsonObject);
    }//w ww.  jav a2  s  . com
    return httpServerRequest;
}