List of usage examples for io.netty.handler.codec.http QueryStringDecoder parameters
public Map<String, List<String>> parameters()
From source file:com.corundumstudio.socketio.transport.XHRPollingTransport.java
License:Apache License
private void handleMessage(FullHttpRequest req, QueryStringDecoder queryDecoder, ChannelHandlerContext ctx) throws IOException { String[] parts = queryDecoder.path().split("/"); if (parts.length > 3) { UUID sessionId = UUID.fromString(parts[4]); String origin = req.headers().get(HttpHeaders.Names.ORIGIN); if (queryDecoder.parameters().containsKey("disconnect")) { MainBaseClient client = sessionId2Client.get(sessionId); client.onChannelDisconnect(); ctx.channel().writeAndFlush(new XHROutMessage(origin, sessionId)); } else if (HttpMethod.POST.equals(req.getMethod())) { onPost(sessionId, ctx, origin, req.content()); } else if (HttpMethod.GET.equals(req.getMethod())) { onGet(sessionId, ctx, origin); }/*w ww .j a v a 2 s . com*/ } else { log.warn("Wrong {} method request path: {}, from ip: {}. Channel closed!", req.getMethod(), path, ctx.channel().remoteAddress()); ctx.channel().close(); } }
From source file:com.dlc.server.DLCHttpServerHandler.java
private void handleHttpRequest(ChannelHandlerContext ctx, HttpRequest req) { QueryStringDecoder uri = new QueryStringDecoder(req.uri()); Map<String, List<String>> params = uri.parameters(); switch (uri.path()) { case "/search": this.doSearch(ctx, req, params); break;/*from w w w . j a v a 2 s. co m*/ case "/index": this.doIndex(ctx, req, params); break; case "/files": this.getAllFiles(ctx, req, params); break; } }
From source file:com.dwarf.netty.guide.http.snoop.HttpSnoopServerHandler.java
License:Apache License
@Override protected void messageReceived(ChannelHandlerContext ctx, Object msg) { if (msg instanceof HttpRequest) { HttpRequest request = this.request = (HttpRequest) msg; if (HttpHeaderUtil.is100ContinueExpected(request)) { send100Continue(ctx);//from w w w.j a v a 2 s. c o m } buf.setLength(0); buf.append("WELCOME TO THE WILD WILD WEB SERVER\r\n"); buf.append("===================================\r\n"); buf.append("VERSION: ").append(request.protocolVersion()).append("\r\n"); buf.append("HOSTNAME: ").append(request.headers().get(HOST, "unknown")).append("\r\n"); buf.append("REQUEST_URI: ").append(request.uri()).append("\r\n\r\n"); HttpHeaders headers = request.headers(); if (!headers.isEmpty()) { for (Map.Entry<CharSequence, CharSequence> h : headers) { CharSequence key = h.getKey(); CharSequence value = h.getValue(); buf.append("HEADER: ").append(key).append(" = ").append(value).append("\r\n"); } buf.append("\r\n"); } QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.uri()); Map<String, List<String>> params = queryStringDecoder.parameters(); if (!params.isEmpty()) { for (Entry<String, List<String>> p : params.entrySet()) { String key = p.getKey(); List<String> vals = p.getValue(); for (String val : vals) { buf.append("PARAM: ").append(key).append(" = ").append(val).append("\r\n"); } } buf.append("\r\n"); } appendDecoderResult(buf, request); } if (msg instanceof HttpContent) { HttpContent httpContent = (HttpContent) msg; ByteBuf content = httpContent.content(); if (content.isReadable()) { buf.append("CONTENT: "); buf.append(content.toString(CharsetUtil.UTF_8)); buf.append("\r\n"); appendDecoderResult(buf, request); } if (msg instanceof LastHttpContent) { buf.append("END OF CONTENT\r\n"); LastHttpContent trailer = (LastHttpContent) msg; if (!trailer.trailingHeaders().isEmpty()) { buf.append("\r\n"); for (CharSequence name : trailer.trailingHeaders().names()) { for (CharSequence value : trailer.trailingHeaders().getAll(name)) { buf.append("TRAILING HEADER: "); buf.append(name).append(" = ").append(value).append("\r\n"); } } buf.append("\r\n"); } if (!writeResponse(trailer, ctx)) { // If keep-alive is off, close the connection once the content is fully written. ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE); } } } }
From source file:com.ebay.jetstream.http.netty.server.HttpRequestHandler.java
License:MIT License
private void debugHeadersAndCookies(HttpRequest request) { StringBuilder headersandaccokies = new StringBuilder(); // echo the header for now for (Map.Entry<String, String> h : request.headers()) { headersandaccokies.append("HEADER: " + h.getKey() + " = " + h.getValue() + "\r\n"); }//w w w.ja v a 2 s. c o m headersandaccokies.append("\r\n"); QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.getUri()); Map<String, List<String>> params = queryStringDecoder.parameters(); if (!params.isEmpty()) { for (Entry<String, List<String>> p : params.entrySet()) { String key = p.getKey(); List<String> vals = p.getValue(); for (String val : vals) { headersandaccokies.append("PARAM: " + key + " = " + val + "\r\n"); } } headersandaccokies.append("\r\n"); } debug(headersandaccokies.toString()); }
From source file:com.englishtown.vertx.jersey.impl.DefaultJerseyHandler.java
License:Open Source License
protected URI getAbsoluteURI(HttpServerRequest vertxRequest) { URI absoluteUri;/*from w w w. j a va 2 s . c o m*/ String hostAndPort = vertxRequest.headers().get(HttpHeaders.HOST); try { absoluteUri = URI.create(vertxRequest.absoluteURI()); if (hostAndPort != null && !hostAndPort.isEmpty()) { String[] parts = hostAndPort.split(":"); String host = parts[0]; int port = (parts.length > 1 ? Integer.valueOf(parts[1]) : -1); if (!host.equalsIgnoreCase(absoluteUri.getHost()) || port != absoluteUri.getPort()) { absoluteUri = UriBuilder.fromUri(absoluteUri).host(host).port(port).build(); } } return absoluteUri; } catch (IllegalArgumentException e) { String uri = vertxRequest.uri(); if (!uri.contains("?")) { throw e; } try { logger.warn("Invalid URI: " + uri + ". Attempting to parse query string.", e); QueryStringDecoder decoder = new QueryStringDecoder(uri); StringBuilder sb = new StringBuilder(decoder.path() + "?"); for (Map.Entry<String, List<String>> p : decoder.parameters().entrySet()) { for (String value : p.getValue()) { sb.append(p.getKey()).append("=").append(URLEncoder.encode(value, "UTF-8")); } } return URI.create(sb.toString()); } catch (Exception e1) { throw new RuntimeException(e1); } } }
From source file:com.fire.login.http.HttpInboundHandler.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof HttpRequest) { HttpRequest req = (HttpRequest) msg; URI uri = URI.create(req.getUri()); ctx.channel().attr(KEY_PATH).set(uri.getPath()); if (req.getMethod().equals(HttpMethod.GET)) { QueryStringDecoder decoder = new QueryStringDecoder(URI.create(req.getUri())); Map<String, List<String>> parameter = decoder.parameters(); dispatch(ctx.channel(), parameter); return; }/* w w w.j a va2 s . com*/ decoder = new HttpPostRequestDecoder(factory, req); } if (decoder != null) { if (msg instanceof HttpContent) { HttpContent chunk = (HttpContent) msg; decoder.offer(chunk); List<InterfaceHttpData> list = decoder.getBodyHttpDatas(); Map<String, List<String>> parameter = new HashMap<>(); for (InterfaceHttpData data : list) { if (data.getHttpDataType() == HttpDataType.Attribute) { Attribute attribute = (Attribute) data; addParameter(attribute.getName(), attribute.getValue(), parameter); } } if (chunk instanceof LastHttpContent) { reset(); dispatch(ctx.channel(), parameter); } } } }
From source file:com.flysoloing.learning.network.netty.http.snoop.HttpSnoopServerHandler.java
License:Apache License
@Override protected void channelRead0(ChannelHandlerContext ctx, Object msg) { if (msg instanceof HttpRequest) { HttpRequest request = this.request = (HttpRequest) msg; if (HttpUtil.is100ContinueExpected(request)) { send100Continue(ctx);/*w ww . j av a 2 s.com*/ } buf.setLength(0); buf.append("WELCOME TO THE WILD WILD WEB SERVER\r\n"); buf.append("===================================\r\n"); buf.append("VERSION: ").append(request.protocolVersion()).append("\r\n"); buf.append("HOSTNAME: ").append(request.headers().get(HttpHeaderNames.HOST, "unknown")).append("\r\n"); buf.append("REQUEST_URI: ").append(request.uri()).append("\r\n\r\n"); HttpHeaders headers = request.headers(); if (!headers.isEmpty()) { for (Entry<String, String> h : headers) { CharSequence key = h.getKey(); CharSequence value = h.getValue(); buf.append("HEADER: ").append(key).append(" = ").append(value).append("\r\n"); } buf.append("\r\n"); } QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.uri()); Map<String, List<String>> params = queryStringDecoder.parameters(); if (!params.isEmpty()) { for (Entry<String, List<String>> p : params.entrySet()) { String key = p.getKey(); List<String> vals = p.getValue(); for (String val : vals) { buf.append("PARAM: ").append(key).append(" = ").append(val).append("\r\n"); } } buf.append("\r\n"); } appendDecoderResult(buf, request); } if (msg instanceof HttpContent) { HttpContent httpContent = (HttpContent) msg; ByteBuf content = httpContent.content(); if (content.isReadable()) { buf.append("CONTENT: "); buf.append(content.toString(CharsetUtil.UTF_8)); buf.append("\r\n"); appendDecoderResult(buf, request); } if (msg instanceof LastHttpContent) { buf.append("END OF CONTENT\r\n"); LastHttpContent trailer = (LastHttpContent) msg; if (!trailer.trailingHeaders().isEmpty()) { buf.append("\r\n"); for (CharSequence name : trailer.trailingHeaders().names()) { for (CharSequence value : trailer.trailingHeaders().getAll(name)) { buf.append("TRAILING HEADER: "); buf.append(name).append(" = ").append(value).append("\r\n"); } } buf.append("\r\n"); } if (!writeResponse(trailer, ctx)) { // If keep-alive is off, close the connection once the content is fully written. ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE); } } } }
From source file:com.flysoloing.learning.network.netty.http2.Http2ExampleUtil.java
License:Apache License
/** * @param query the decoder of query string * @param key the key to lookup//from w ww . j a v a 2 s .c om * @return the first occurrence of that key in the string parameters */ public static String firstValue(QueryStringDecoder query, String key) { checkNotNull(query, "Query can't be null!"); List<String> values = query.parameters().get(key); if (values == null || values.isEmpty()) { return null; } return values.get(0); }
From source file:com.friz.audio.network.listeners.AudioRequestEventListener.java
License:Open Source License
@Override public void onEvent(AudioRequestEvent event, AudioSessionContext context) { int type = -1, file = -1, crc = -1, version = -1; QueryStringDecoder query = new QueryStringDecoder(event.getRequest().getUri()); for (String key : query.parameters().keySet()) { if (key.equals("a")) type = Integer.valueOf(query.parameters().get(key).get(0)); else if (key.equals("g")) file = Integer.valueOf(query.parameters().get(key).get(0)); else if (key.equals("c")) crc = Integer.valueOf(query.parameters().get(key).get(0)); else if (key.equals("v")) version = Integer.valueOf(query.parameters().get(key).get(0)); }//from w w w.j av a2 s . c o m if (type == -1 || file == -1) return; Deque<FileRequestEvent> queue = context.getFileQueue(); synchronized (queue) { queue.add(new FileRequestEvent(type, file, crc, version, event.getRequest().getProtocolVersion())); if (context.isIdle()) { context.addContextToService(); context.setIdle(false); } } }
From source file:com.github.jonbonazza.puni.core.requests.HttpRequest.java
License:Apache License
protected void parseFormData(String queryParamSection) { QueryStringDecoder decoder = new QueryStringDecoder(getUri()); formData = decoder.parameters(); }