Search in sources :

Example 81 with MultiMap

use of io.vertx.core.MultiMap in project vert.x by eclipse.

the class HttpUtils method params.

static MultiMap params(String uri) {
    QueryStringDecoder queryStringDecoder = new QueryStringDecoder(uri);
    Map<String, List<String>> prms = queryStringDecoder.parameters();
    MultiMap params = new CaseInsensitiveHeaders();
    if (!prms.isEmpty()) {
        for (Map.Entry<String, List<String>> entry : prms.entrySet()) {
            params.add(entry.getKey(), entry.getValue());
        }
    }
    return params;
}
Also used : QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) MultiMap(io.vertx.core.MultiMap) CaseInsensitiveHeaders(io.vertx.core.http.CaseInsensitiveHeaders) List(java.util.List) MultiMap(io.vertx.core.MultiMap) Map(java.util.Map)

Example 82 with MultiMap

use of io.vertx.core.MultiMap in project vert.x by eclipse.

the class VertxHttp2Stream method checkNextTick.

/**
   * Check if paused buffers must be handled to the reader, this must be called from event loop.
   */
private void checkNextTick(Void v) {
    synchronized (conn) {
        if (!paused) {
            Object msg = pending.poll();
            if (msg instanceof Buffer) {
                Buffer buf = (Buffer) msg;
                conn.handler.consume(stream, buf.length());
                handleData(buf);
                if (pending.size() > 0) {
                    vertx.runOnContext(this::checkNextTick);
                }
            } else if (msg == END) {
                handleEnd(null);
            } else if (msg instanceof MultiMap) {
                handleEnd((MultiMap) msg);
            }
        }
    }
}
Also used : Buffer(io.vertx.core.buffer.Buffer) MultiMap(io.vertx.core.MultiMap)

Example 83 with MultiMap

use of io.vertx.core.MultiMap in project vert.x by eclipse.

the class HttpClientResponseImpl method doResume.

private void doResume() {
    if (hasPausedEnd) {
        final Buffer theChunk = pausedLastChunk;
        final MultiMap theTrailer = pausedTrailers;
        stream.getContext().runOnContext(v -> handleEnd(theChunk, theTrailer));
        hasPausedEnd = false;
        pausedTrailers = null;
        pausedLastChunk = null;
    }
}
Also used : Buffer(io.vertx.core.buffer.Buffer) MultiMap(io.vertx.core.MultiMap)

Example 84 with MultiMap

use of io.vertx.core.MultiMap in project vert.x by eclipse.

the class ClientConnection method toWebSocket.

synchronized void toWebSocket(String requestURI, MultiMap headers, WebsocketVersion vers, String subProtocols, int maxWebSocketFrameSize, Handler<WebSocket> wsConnect) {
    if (ws != null) {
        throw new IllegalStateException("Already websocket");
    }
    try {
        URI wsuri = new URI(requestURI);
        if (!wsuri.isAbsolute()) {
            // Netty requires an absolute url
            wsuri = new URI((ssl ? "https:" : "http:") + "//" + host + ":" + port + requestURI);
        }
        WebSocketVersion version = WebSocketVersion.valueOf((vers == null ? WebSocketVersion.V13 : vers).toString());
        HttpHeaders nettyHeaders;
        if (headers != null) {
            nettyHeaders = new DefaultHttpHeaders();
            for (Map.Entry<String, String> entry : headers) {
                nettyHeaders.add(entry.getKey(), entry.getValue());
            }
        } else {
            nettyHeaders = null;
        }
        handshaker = WebSocketClientHandshakerFactory.newHandshaker(wsuri, version, subProtocols, false, nettyHeaders, maxWebSocketFrameSize, !client.getOptions().isSendUnmaskedFrames(), false);
        ChannelPipeline p = channel.pipeline();
        p.addBefore("handler", "handshakeCompleter", new HandshakeInboundHandler(wsConnect, version != WebSocketVersion.V00));
        handshaker.handshake(channel).addListener(future -> {
            Handler<Throwable> handler = exceptionHandler();
            if (!future.isSuccess() && handler != null) {
                handler.handle(future.cause());
            }
        });
    } catch (Exception e) {
        handleException(e);
    }
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) URI(java.net.URI) VertxException(io.vertx.core.VertxException) MultiMap(io.vertx.core.MultiMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 85 with MultiMap

use of io.vertx.core.MultiMap in project java-chassis by ServiceComb.

the class TestRestVertxHttpRequest method testGetQueryParams.

@Test
public void testGetQueryParams() {
    boolean status = true;
    try {
        HttpServerRequest httpServerRequest = Mockito.mock(HttpServerRequest.class);
        Deencapsulation.setField(instance, "request", httpServerRequest);
        MultiMap multiMap = Mockito.mock(MultiMap.class);
        Mockito.when(httpServerRequest.params()).thenReturn(multiMap);
        List<String> stringList = new ArrayList<String>();
        stringList.add("sters");
        Set<String> stringSet = new HashSet<String>();
        stringSet.add("sters");
        Mockito.when(multiMap.names()).thenReturn(stringSet);
        Mockito.when(multiMap.getAll("key")).thenReturn(stringList);
        Assert.assertNotNull(instance.getQueryParams());
    } catch (Exception ex) {
        status = false;
    }
    Assert.assertTrue(status);
}
Also used : MultiMap(io.vertx.core.MultiMap) HttpServerRequest(io.vertx.core.http.HttpServerRequest) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

MultiMap (io.vertx.core.MultiMap)89 Test (org.junit.Test)77 CaseInsensitiveHeaders (io.vertx.core.http.CaseInsensitiveHeaders)61 HashMap (java.util.HashMap)21 ArrayList (java.util.ArrayList)19 Map (java.util.Map)12 Buffer (io.vertx.core.buffer.Buffer)9 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)8 Handler (io.vertx.core.Handler)8 VertxException (io.vertx.core.VertxException)8 HttpClientRequest (io.vertx.core.http.HttpClientRequest)8 HttpMethod (io.vertx.core.http.HttpMethod)8 HttpServerResponse (io.vertx.core.http.HttpServerResponse)8 HeadersAdaptor (io.vertx.core.http.impl.HeadersAdaptor)8 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)7 InternalLoggerFactory (io.netty.util.internal.logging.InternalLoggerFactory)7 Nullable (io.vertx.codegen.annotations.Nullable)7 AbstractVerticle (io.vertx.core.AbstractVerticle)7 AsyncResult (io.vertx.core.AsyncResult)7 Context (io.vertx.core.Context)7