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;
}
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;
}
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);
}
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);
}
}
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;
}
Aggregations