use of io.netty.handler.codec.http.QueryStringDecoder in project java-chassis by ServiceComb.
the class CseClientHttpRequest method execute.
@Override
public ClientHttpResponse execute() {
path = findUriPath(uri);
requestMeta = createRequestMeta(method.name(), uri);
QueryStringDecoder queryStringDecoder = new QueryStringDecoder(uri.getRawSchemeSpecificPart());
queryParams = queryStringDecoder.parameters();
Map<String, Object> swaggerArguments = this.collectArguments();
// 异常流程,直接抛异常出去
return this.invoke(swaggerArguments);
}
use of io.netty.handler.codec.http.QueryStringDecoder in project vertx-web by vert-x3.
the class BaseValidationHandler method validateCookieParams.
private Map<String, RequestParameter> validateCookieParams(RoutingContext routingContext) throws ValidationException {
// Validation process validate only params that are registered in the validation -> extra params are allowed
if (!routingContext.request().headers().contains("Cookie"))
return new HashMap<>();
// Some hack to reuse this object
QueryStringDecoder decoder = new QueryStringDecoder("/?" + routingContext.request().getHeader("Cookie"));
Map<String, List<String>> cookies = new HashMap<>();
for (Map.Entry<String, List<String>> e : decoder.parameters().entrySet()) {
String key = e.getKey().trim();
if (cookies.containsKey(key))
cookies.get(key).addAll(e.getValue());
else
cookies.put(key, e.getValue());
}
Map<String, RequestParameter> parsedParams = new HashMap<>();
for (ParameterValidationRule rule : cookieParamsRules.values()) {
String name = rule.getName().trim();
if (cookies.containsKey(name)) {
List<String> p = cookies.remove(name);
if (p.size() != 0) {
RequestParameter parsedParam = rule.validateArrayParam(p);
if (parsedParams.containsKey(parsedParam.getName()))
parsedParam = parsedParam.merge(parsedParams.get(parsedParam.getName()));
parsedParams.put(parsedParam.getName(), parsedParam);
} else {
throw ValidationException.ValidationExceptionFactory.generateNotMatchValidationException(name + " can't be empty");
}
} else {
if (rule.parameterTypeValidator().getDefault() != null) {
RequestParameter parsedParam = new RequestParameterImpl(name, rule.parameterTypeValidator().getDefault());
if (parsedParams.containsKey(parsedParam.getName()))
parsedParam = parsedParam.merge(parsedParams.get(parsedParam.getName()));
parsedParams.put(parsedParam.getName(), parsedParam);
} else if (!rule.isOptional())
throw ValidationException.ValidationExceptionFactory.generateNotFoundValidationException(name, ParameterLocation.COOKIE);
}
}
if (cookieAdditionalPropertiesValidator != null) {
for (Map.Entry<String, List<String>> e : cookies.entrySet()) {
try {
Map<String, RequestParameter> r = new HashMap<>();
r.put(e.getKey(), cookieAdditionalPropertiesValidator.isValidCollection(e.getValue()));
RequestParameter parsedParam = new RequestParameterImpl(cookieAdditionalPropertiesObjectPropertyName, r);
if (parsedParams.containsKey(cookieAdditionalPropertiesObjectPropertyName))
parsedParam = parsedParam.merge(parsedParams.get(cookieAdditionalPropertiesObjectPropertyName));
parsedParams.put(parsedParam.getName(), parsedParam);
} catch (ValidationException ex) {
ex.setParameterName(cookieAdditionalPropertiesObjectPropertyName);
e.setValue(e.getValue());
throw ex;
}
}
}
return parsedParams;
}
use of 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;
}
use of io.netty.handler.codec.http.QueryStringDecoder in project vertx-web by vert-x3.
the class HttpServerRequestWrapper method params.
@Override
public MultiMap params() {
if (!modified) {
return delegate.params();
}
if (params == null) {
params = MultiMap.caseInsensitiveMultiMap();
// if there is no query it's not really needed to parse it
if (query != null) {
QueryStringDecoder queryStringDecoder = new QueryStringDecoder(uri);
Map<String, List<String>> prms = queryStringDecoder.parameters();
if (!prms.isEmpty()) {
for (Map.Entry<String, List<String>> entry : prms.entrySet()) {
params.add(entry.getKey(), entry.getValue());
}
}
}
}
return params;
}
use of io.netty.handler.codec.http.QueryStringDecoder in project xian by happyyangyuan.
the class URIBean method checkUri.
/**
* Check the uri is xian pattern or not.
* xian pattern uri must starts with /${group}/${unit}
* TODO combine URI checking with UriBean creation. And use UriBean reference instead of URI string later on for performance consideration.
*
* @param uri the URI to be checked
* @return true if it is xian pattern false other wise.
*/
public static boolean checkUri(String uri) {
QueryStringDecoder queryStringDecoder = new QueryStringDecoder(uri, true);
String path = queryStringDecoder.path();
int groupIndex = path.indexOf('/') + 1, unitIndex = path.indexOf('/', groupIndex) + 1;
if (groupIndex == 0 || unitIndex == 0) {
LOG.warn("URI is illegal: " + uri);
return false;
}
return true;
}
Aggregations