Search in sources :

Example 41 with QueryStringDecoder

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

the class DiskNettyHttpRequestHandler method requestReceived.

@Override
public void requestReceived(ChannelHandlerContext ctx, FullHttpRequest request) {
    LOG.debug("handle request[{}:{}]", request.method(), request.uri());
    MessageHandler<DiskMessage> handler = methodToOps.get(request.method());
    if (handler == null) {
        ResponseSender.sendError(ctx, HttpResponseStatus.METHOD_NOT_ALLOWED);
        return;
    }
    QueryStringDecoder decoder = new QueryStringDecoder(request.uri(), CharsetUtil.UTF_8, true);
    DiskMessage message = new DiskMessage();
    message.setFilePath(decoder.path());
    Map<String, String> params = new HashMap<String, String>();
    for (String paramName : decoder.parameters().keySet()) {
        params.put(paramName, decoder.parameters().get(paramName).get(0));
    }
    message.setParams(params);
    byte[] data = new byte[request.content().readableBytes()];
    request.content().readBytes(data);
    message.setData(data);
    handler.handle(message, new DefaultHandleResultCallback(ctx));
}
Also used : QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) DiskMessage(com.bonree.brfs.disknode.server.handler.DiskMessage) HashMap(java.util.HashMap)

Example 42 with QueryStringDecoder

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

the class StorageNameRequestHandler method requestReceived.

@Override
public void requestReceived(ChannelHandlerContext ctx, FullHttpRequest request) {
    LOG.debug("handle request[{}:{}]", request.method(), request.uri());
    MessageHandler<StorageNameMessage> handler = handlers.get(request.method().name());
    if (handler == null) {
        ResponseSender.sendError(ctx, HttpResponseStatus.METHOD_NOT_ALLOWED);
        return;
    }
    QueryStringDecoder decoder = new QueryStringDecoder(request.uri(), CharsetUtil.UTF_8, true);
    StorageNameMessage message = new StorageNameMessage();
    message.setName(parseName(decoder.path()));
    System.out.println("name----" + message.getName());
    byte[] data = new byte[request.content().readableBytes()];
    request.content().readBytes(data);
    // TODO set other properties of StorageNameMessage
    handler.handle(message, new DefaultHandleResultCallback(ctx));
}
Also used : QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder)

Example 43 with QueryStringDecoder

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

the class IXwwwformurlencodedBody method parseByNettyDecoder.

/**
 * parse the http request body using the netty query string decoder.
 */
static JSONObject parseByNettyDecoder(String body) {
    JSONObject bodyParameters = new JSONObject();
    QueryStringDecoder queryStringDecoder = new QueryStringDecoder(body, false);
    Map<String, List<String>> parameters = queryStringDecoder.parameters();
    parameters.forEach((key, values) -> {
        if (values == null || values.isEmpty()) {
            LOG.debug("空参数统一对应空字符串");
            bodyParameters.put(key, "");
        } else if (values.size() == 1)
            bodyParameters.put(key, values.get(0));
        else
            bodyParameters.put(key, values);
    });
    return bodyParameters;
}
Also used : QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) JSONObject(com.alibaba.fastjson.JSONObject) List(java.util.List)

Example 44 with QueryStringDecoder

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringDecoder in project vertx-web by vert-x3.

the class HttpRequestImpl method queryParams.

@Override
public MultiMap queryParams() {
    if (params == null) {
        params = new CaseInsensitiveHeaders();
    }
    if (params.isEmpty()) {
        int idx = uri.indexOf('?');
        if (idx >= 0) {
            QueryStringDecoder dec = new QueryStringDecoder(uri);
            dec.parameters().forEach((name, value) -> params.add(name, value));
            uri = uri.substring(0, idx);
        }
    }
    return params;
}
Also used : QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) CaseInsensitiveHeaders(io.vertx.core.http.CaseInsensitiveHeaders)

Example 45 with QueryStringDecoder

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

the class MetricQueryParser method parseQueryString.

/**
 * From the query string determine the query type, time range and related parameters.
 */
public static void parseQueryString(URI requestURI, MetricDataQueryBuilder builder) throws MetricsPathException {
    Map<String, List<String>> queryParams = new QueryStringDecoder(requestURI).parameters();
    parseTimeseries(queryParams, builder);
}
Also used : QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) ArrayList(java.util.ArrayList) 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