Search in sources :

Example 36 with QueryStringDecoder

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringDecoder in project riposte by Nike-Inc.

the class HttpServletRequestWrapperForRequestInfoTest method getQueryString_returns_null_if_no_query_string_exists.

@Test
public void getQueryString_returns_null_if_no_query_string_exists() {
    // given
    QueryStringDecoder queryStringDecoder = new QueryStringDecoder("/some/path");
    doReturn(queryStringDecoder).when(requestInfoMock).getQueryParams();
    // when
    String result = wrapper.getQueryString();
    // then
    assertThat(result).isNull();
}
Also used : QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) Test(org.junit.Test)

Example 37 with QueryStringDecoder

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringDecoder in project riposte by Nike-Inc.

the class HttpServletRequestWrapperForRequestInfoTest method getQueryString_delegates_to_requestInfo.

@Test
public void getQueryString_delegates_to_requestInfo() {
    // given
    String queryString = "foo=bar&baz=" + UUID.randomUUID().toString();
    QueryStringDecoder queryStringDecoder = new QueryStringDecoder("/some/path?" + queryString);
    doReturn(queryStringDecoder).when(requestInfoMock).getQueryParams();
    // when
    String result = wrapper.getQueryString();
    // then
    assertThat(result).isEqualTo(queryString);
}
Also used : QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) Test(org.junit.Test)

Example 38 with QueryStringDecoder

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

the class HttpParamsDecoder method decodeFromUri.

/**
 * 解析Uri中携带的Parameter信息
 *
 * @param uri
 * @return
 */
public static Map<String, String> decodeFromUri(String uri) {
    Map<String, String> params = new HashMap<String, String>();
    QueryStringDecoder decoder = new QueryStringDecoder(uri, CharsetUtil.UTF_8, true);
    Map<String, List<String>> paramMap = decoder.parameters();
    for (Map.Entry<String, List<String>> entry : paramMap.entrySet()) {
        if (entry.getValue() != null && !entry.getValue().isEmpty()) {
            params.put(entry.getKey(), entry.getValue().get(0));
        }
    }
    return params;
}
Also used : QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) HashMap(java.util.HashMap) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap)

Example 39 with QueryStringDecoder

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

the class FSImageHandler method channelRead0.

@Override
public void channelRead0(ChannelHandlerContext ctx, HttpRequest request) throws Exception {
    if (request.getMethod() != HttpMethod.GET) {
        DefaultHttpResponse resp = new DefaultHttpResponse(HTTP_1_1, METHOD_NOT_ALLOWED);
        resp.headers().set(CONNECTION, CLOSE);
        ctx.write(resp).addListener(ChannelFutureListener.CLOSE);
        return;
    }
    QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());
    final String op = getOp(decoder);
    final String content;
    String path = getPath(decoder);
    switch(op) {
        case "GETFILESTATUS":
            content = image.getFileStatus(path);
            break;
        case "LISTSTATUS":
            content = image.listStatus(path);
            break;
        case "GETACLSTATUS":
            content = image.getAclStatus(path);
            break;
        case "GETXATTRS":
            List<String> names = getXattrNames(decoder);
            String encoder = getEncoder(decoder);
            content = image.getXAttrs(path, names, encoder);
            break;
        case "LISTXATTRS":
            content = image.listXAttrs(path);
            break;
        case "GETCONTENTSUMMARY":
            content = image.getContentSummary(path);
            break;
        default:
            throw new IllegalArgumentException("Invalid value for webhdfs parameter" + " \"op\"");
    }
    LOG.info("op=" + op + " target=" + path);
    DefaultFullHttpResponse resp = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(content.getBytes(Charsets.UTF_8)));
    resp.headers().set(CONTENT_TYPE, APPLICATION_JSON_UTF8);
    resp.headers().set(CONTENT_LENGTH, resp.content().readableBytes());
    resp.headers().set(CONNECTION, CLOSE);
    ctx.write(resp).addListener(ChannelFutureListener.CLOSE);
}
Also used : QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse)

Example 40 with QueryStringDecoder

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

the class BaseRequest method create.

public static IServletRequest create(FullHttpRequest request) throws IOException {
    QueryStringDecoder decoder = new QueryStringDecoder(request.uri());
    Map<String, List<String>> param = decoder.parameters();
    return new BaseRequest(request, param);
}
Also used : QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) 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