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;
}
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);
}
}
}
}
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;
}
}
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);
}
}
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);
}
Aggregations