Search in sources :

Example 21 with QueryStringDecoder

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringDecoder in project xian by happyyangyuan.

the class RequestParser method urlParams.

/**
 * 获取url中的参数
 *
 * @return
 */
public static Map<String, String> urlParams(FullHttpRequest request) {
    Map<String, String> params = new HashMap<String, String>();
    QueryStringDecoder decoder = new QueryStringDecoder(request.uri());
    decoder.parameters().entrySet().forEach(entry -> {
        params.put(entry.getKey(), entry.getValue().get(0));
    });
    return params;
}
Also used : QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) HashMap(java.util.HashMap)

Example 22 with QueryStringDecoder

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringDecoder in project mbed-cloud-sdk-java by ARMmbed.

the class TestServer method retrieveQueryParameters.

// TODO Remove when not needed anymore
private Map<String, Object> retrieveQueryParameters(HttpServerRequest request) {
    MultiMap map = request.params();
    Map<String, Object> params = new LinkedHashMap<>();
    for (Entry<String, String> element : map.entries()) {
        if (!element.getKey().equalsIgnoreCase(PARAM_MODULE) && !element.getKey().equalsIgnoreCase(PARAM_METHOD)) {
            if (element.getKey().equalsIgnoreCase(TEST_ARGS_KEY)) {
                QueryStringDecoder queryStringDecoder = new QueryStringDecoder("/?" + element.getValue());
                Map<String, List<String>> prms = queryStringDecoder.parameters();
                if (!prms.isEmpty()) {
                    for (Map.Entry<String, List<String>> entry : prms.entrySet()) {
                        if (entry.getValue() == null || entry.getValue().isEmpty()) {
                            logger.logWarn("Argument [" + String.valueOf(entry.getKey()) + "] has no value. It will be ignored");
                        } else if (entry.getValue().size() > 1) {
                            logger.logWarn("Argument [" + String.valueOf(entry.getKey()) + "] has more than one value " + String.valueOf(entry.getValue()) + ". Only the first one will be considered i.e. " + String.valueOf(entry.getValue().get(0)));
                        } else {
                            params.put(entry.getKey(), Serializer.deserialiseString(entry.getValue().get(0)));
                        }
                    }
                }
            } else {
                params.put(element.getKey(), Serializer.deserialiseString(element.getValue()));
            }
        }
    }
    return params;
}
Also used : QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) MultiMap(io.vertx.core.MultiMap) JsonObject(io.vertx.core.json.JsonObject) List(java.util.List) MultiMap(io.vertx.core.MultiMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 23 with QueryStringDecoder

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringDecoder 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);
}
Also used : QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) List(java.util.List) MultiMap(io.vertx.reactivex.core.MultiMap) Map(java.util.Map)

Example 24 with QueryStringDecoder

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringDecoder in project gravitee-gateway by gravitee-io.

the class DefaultInvoker method selectUserDefinedEndpoint.

/**
 * Select an endpoint according to the URI passed in the execution request attribute.
 */
private TargetEndpoint selectUserDefinedEndpoint(Request serverRequest, String target, ExecutionContext executionContext) {
    QueryStringDecoder decoder = new QueryStringDecoder(target);
    Map<String, List<String>> queryParameters = decoder.parameters();
    // Merge query parameters from user target into incoming request query parameters
    for (Map.Entry<String, List<String>> param : queryParameters.entrySet()) {
        serverRequest.parameters().put(param.getKey(), param.getValue());
    }
    // Path segments must be encoded to avoid bad URI syntax
    String[] segments = decoder.path().split(URI_PATH_SEPARATOR);
    StringBuilder builder = new StringBuilder();
    for (String pathSeg : segments) {
        builder.append(UrlEscapers.urlPathSegmentEscaper().escape(pathSeg)).append(URI_PATH_SEPARATOR);
    }
    String encodedTarget = builder.substring(0, builder.length() - 1);
    // Do we have a single path or a plain URI ?
    if (encodedTarget.startsWith("/")) {
        Endpoint endpoint = nextEndpoint(serverRequest, executionContext);
        return new TargetEndpoint(endpoint, (endpoint != null) ? endpoint.target() + encodedTarget : null);
    } else {
        Endpoint endpoint = endpointManager.endpoints().stream().filter(endpointEntry -> encodedTarget.startsWith(endpointEntry.target())).findFirst().orElse(endpointManager.endpoints().iterator().next());
        return new TargetEndpoint(endpoint, encodedTarget);
    }
}
Also used : QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) Endpoint(io.gravitee.gateway.api.endpoint.Endpoint)

Example 25 with QueryStringDecoder

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringDecoder in project xian by happyyangyuan.

the class HttpUtil method parseQueryString.

/**
 * parse the given http query string
 *
 * @param queryString the standard http query string
 * @param hasPath     whether the query string contains uri
 * @return the parsed json object. if the given query string is empty then an empty json object is returned.
 */
public static JSONObject parseQueryString(String queryString, boolean hasPath) {
    JSONObject uriParameters = new JSONObject();
    if (queryString == null)
        return uriParameters;
    QueryStringDecoder queryStringDecoder = new QueryStringDecoder(queryString, hasPath);
    Map<String, List<String>> parameters = queryStringDecoder.parameters();
    parameters.forEach((key, values) -> {
        if (values == null || values.isEmpty()) {
            LOG.debug("空参数统一对应空字符串");
            uriParameters.put(key, "");
        } else if (values.size() == 1)
            uriParameters.put(key, values.get(0));
        else
            uriParameters.put(key, values);
    });
    return uriParameters;
}
Also used : QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) JSONObject(com.alibaba.fastjson.JSONObject) List(java.util.List)

Aggregations

QueryStringDecoder (io.netty.handler.codec.http.QueryStringDecoder)69 List (java.util.List)29 Test (org.junit.Test)15 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)14 Map (java.util.Map)10 HashMap (java.util.HashMap)9 IOException (java.io.IOException)8 URI (java.net.URI)7 ByteBuf (io.netty.buffer.ByteBuf)6 HttpContent (io.netty.handler.codec.http.HttpContent)6 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)6 HttpPostRequestDecoder (io.netty.handler.codec.http.multipart.HttpPostRequestDecoder)6 ArrayList (java.util.ArrayList)6 HttpMethod (io.netty.handler.codec.http.HttpMethod)5 HttpRequest (io.netty.handler.codec.http.HttpRequest)5 DeviceSession (org.traccar.DeviceSession)5 Position (org.traccar.model.Position)5 DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)4 Channel (io.netty.channel.Channel)3 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)3