Search in sources :

Example 16 with QueryStringEncoder

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringEncoder in project jocean-http by isdom.

the class MessageUtil method addQueryParam.

public static Action1<Object> addQueryParam(final String... nvs) {
    return new Action1<Object>() {

        @Override
        public void call(final Object obj) {
            if (obj instanceof HttpRequest) {
                final HttpRequest request = (HttpRequest) obj;
                if (nvs.length > 0) {
                    final QueryStringEncoder encoder = new QueryStringEncoder(request.uri());
                    int idx = 0;
                    while (idx + 1 < nvs.length) {
                        encoder.addParam(nvs[idx], nvs[idx + 1]);
                        idx += 2;
                    }
                    request.setUri(encoder.toString());
                }
            }
        }
    };
}
Also used : DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) Action1(rx.functions.Action1) HttpObject(io.netty.handler.codec.http.HttpObject) QueryStringEncoder(io.netty.handler.codec.http.QueryStringEncoder)

Example 17 with QueryStringEncoder

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringEncoder in project moco by dreamhead.

the class DefaultHttpRequest method toFullHttpRequest.

public FullHttpRequest toFullHttpRequest() {
    ByteBuf buffer = Unpooled.buffer();
    MessageContent content = getContent();
    if (content != null) {
        buffer.writeBytes(content.getContent());
    }
    QueryStringEncoder encoder = new QueryStringEncoder(uri);
    for (Map.Entry<String, String[]> entry : queries.entrySet()) {
        String[] values = entry.getValue();
        for (String value : values) {
            encoder.addParam(entry.getKey(), value);
        }
    }
    FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.valueOf(getVersion().text()), io.netty.handler.codec.http.HttpMethod.valueOf(method.name()), encoder.toString(), buffer);
    for (Map.Entry<String, String[]> entry : getHeaders().entrySet()) {
        String key = entry.getKey();
        for (String value : entry.getValue()) {
            request.headers().add(key, value);
        }
    }
    return request;
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) ByteBuf(io.netty.buffer.ByteBuf) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) QueryStringEncoder(io.netty.handler.codec.http.QueryStringEncoder)

Example 18 with QueryStringEncoder

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringEncoder in project traccar by tananaev.

the class OrbcommProtocolPoller method sendRequest.

@Override
protected void sendRequest(Channel channel, SocketAddress remoteAddress) {
    QueryStringEncoder encoder = new QueryStringEncoder("/GLGW/2/RestMessages.svc/JSON/get_return_messages/");
    encoder.addParam("access_id", accessId);
    encoder.addParam("password", password);
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    encoder.addParam("start_utc", dateFormat.format(startTime));
    HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, encoder.toString(), Unpooled.buffer());
    request.headers().add(HttpHeaderNames.HOST, host);
    request.headers().add(HttpHeaderNames.CONTENT_LENGTH, 0);
    channel.writeAndFlush(request);
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) QueryStringEncoder(io.netty.handler.codec.http.QueryStringEncoder)

Example 19 with QueryStringEncoder

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringEncoder in project zipkin by openzipkin.

the class BulkCallBuilder method build.

/**
 * Creates a bulk request when there is more than one object to store
 */
public HttpCall<Void> build() {
    QueryStringEncoder urlBuilder = new QueryStringEncoder("/_bulk");
    if (pipeline != null)
        urlBuilder.addParam("pipeline", pipeline);
    if (waitForRefresh)
        urlBuilder.addParam("refresh", "wait_for");
    ByteBufAllocator alloc = RequestContext.mapCurrent(RequestContext::alloc, () -> PooledByteBufAllocator.DEFAULT);
    HttpCall.RequestSupplier request = new BulkRequestSupplier(entries, shouldAddType, RequestHeaders.of(HttpMethod.POST, urlBuilder.toString(), HttpHeaderNames.CONTENT_TYPE, MediaType.JSON_UTF_8), alloc);
    return http.newCall(request, CHECK_FOR_ERRORS, tag);
}
Also used : ByteBufAllocator(io.netty.buffer.ByteBufAllocator) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator) HttpCall(zipkin2.elasticsearch.internal.client.HttpCall) RequestContext(com.linecorp.armeria.common.RequestContext) QueryStringEncoder(io.netty.handler.codec.http.QueryStringEncoder)

Aggregations

QueryStringEncoder (io.netty.handler.codec.http.QueryStringEncoder)18 MultiMap (io.vertx.core.MultiMap)6 ByteBuf (io.netty.buffer.ByteBuf)4 HttpRequest (io.netty.handler.codec.http.HttpRequest)4 HttpMethod (io.vertx.core.http.HttpMethod)4 RequestParameters (io.vertx.ext.web.api.RequestParameters)4 BodyHandler (io.vertx.ext.web.handler.BodyHandler)4 URLEncoder (java.net.URLEncoder)4 Test (org.junit.Test)4 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)3 RequestContext (com.linecorp.armeria.common.RequestContext)2 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)2 PooledByteBufAllocator (io.netty.buffer.PooledByteBufAllocator)2 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)2 HttpObject (io.netty.handler.codec.http.HttpObject)2 HttpClientRequest (io.vertx.core.http.HttpClientRequest)2 IOException (java.io.IOException)2 Field (java.lang.reflect.Field)2 URI (java.net.URI)2 QueryParam (javax.ws.rs.QueryParam)2