List of usage examples for io.netty.buffer Unpooled EMPTY_BUFFER
ByteBuf EMPTY_BUFFER
To view the source code for io.netty.buffer Unpooled EMPTY_BUFFER.
Click Source Link
From source file:com.sengled.cloud.mediaserver.rtsp.codec.RtspRequestDecoder.java
License:Apache License
@Override protected HttpMessage createInvalidMessage() { return new DefaultFullHttpRequest(RtspVersions.RTSP_1_0, RtspMethods.OPTIONS, "/bad-request", Unpooled.EMPTY_BUFFER, validateHeaders); }
From source file:com.sengled.cloud.mediaserver.rtsp.codec.RtspResponseDecoder.java
License:Apache License
@Override protected HttpMessage createInvalidMessage() { return new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, UNKNOWN_STATUS, Unpooled.EMPTY_BUFFER, validateHeaders);//from w ww . j a v a 2s. co m }
From source file:com.sohu.jafka.http.HttpServerHandler.java
License:Apache License
@Override protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof HttpRequest) { HttpRequest request = this.request = (HttpRequest) msg; if (HttpHeaders.is100ContinueExpected(request)) { send100Continue(ctx);/*from ww w . j av a 2 s . c o m*/ } body = new ByteArrayOutputStream(64); args = new HashMap<String, String>(4); // if (request.getMethod() != HttpMethod.POST) { sendStatusMessage(ctx, HttpResponseStatus.METHOD_NOT_ALLOWED, "POST METHOD REQUIRED"); return; } HttpHeaders headers = request.headers(); String contentType = headers.get("Content-Type"); // ? text or octstream args.put("request_key", headers.get("request_key")); args.put("topic", headers.get("topic")); args.put("partition", headers.get("partition")); } if (msg instanceof HttpContent) { HttpContent httpContent = (HttpContent) msg; ByteBuf content = httpContent.content(); if (content.isReadable()) { //body.write(content.array()); content.readBytes(body, content.readableBytes()); //body.append(content.toString(CharsetUtil.UTF_8)); } if (msg instanceof LastHttpContent) { //process request if (server.handler != null) { server.handler.handle(args, body.toByteArray()); } if (!writeResponse(ctx)) { // If keep-alive is off, close the connection once the content is fully written. ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE); } body = null; args = null; } } }
From source file:com.springapp.mvc.netty.example.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 (HttpHeaders.is100ContinueExpected(request)) { send100Continue(ctx);/*from ww w . ja va2s .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.getProtocolVersion()).append("\r\n"); buf.append("HOSTNAME: ").append(HttpHeaders.getHost(request, "unknown")).append("\r\n"); buf.append("REQUEST_URI: ").append(request.getUri()).append("\r\n\r\n"); HttpHeaders headers = request.headers(); if (!headers.isEmpty()) { for (Entry<String, String> h : headers) { String key = h.getKey(); String value = h.getValue(); buf.append("HEADER: ").append(key).append(" = ").append(value).append("\r\n"); } buf.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) { 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 (String name : trailer.trailingHeaders().names()) { for (String 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.springapp.mvc.netty.example.proxy.HexDumpProxyBackendHandler.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) { ctx.read(); ctx.write(Unpooled.EMPTY_BUFFER); }
From source file:com.srotya.sidewinder.core.ingress.http.HTTPDataPointDecoder.java
License:Apache License
@Override protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { try {/* w w w .j a v a 2 s. c o m*/ if (msg instanceof HttpRequest) { HttpRequest request = this.request = (HttpRequest) msg; if (HttpUtil.is100ContinueExpected(request)) { send100Continue(ctx); } QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.uri()); path = queryStringDecoder.path(); Map<String, List<String>> params = queryStringDecoder.parameters(); if (!params.isEmpty()) { for (Entry<String, List<String>> p : params.entrySet()) { String key = p.getKey(); if (key.equalsIgnoreCase("db")) { dbName = p.getValue().get(0); } } } if (path != null && path.contains("query")) { Gson gson = new Gson(); JsonObject obj = new JsonObject(); JsonArray ary = new JsonArray(); ary.add(new JsonObject()); obj.add("results", ary); responseString.append(gson.toJson(obj)); } } if (msg instanceof HttpContent) { HttpContent httpContent = (HttpContent) msg; ByteBuf byteBuf = httpContent.content(); if (byteBuf.isReadable()) { requestBuffer.append(byteBuf.toString(CharsetUtil.UTF_8)); } if (msg instanceof LastHttpContent) { // LastHttpContent lastHttpContent = (LastHttpContent) msg; // if (!lastHttpContent.trailingHeaders().isEmpty()) { // } if (dbName == null) { responseString.append("Invalid database null"); logger.severe("Invalid database null"); } else { String payload = requestBuffer.toString(); logger.fine("Request:" + payload); List<DataPoint> dps = dataPointsFromString(dbName, payload); for (DataPoint dp : dps) { try { engine.writeDataPoint(dp); logger.fine("Accepted:" + dp + "\t" + new Date(dp.getTimestamp())); } catch (IOException e) { logger.fine("Dropped:" + dp + "\t" + e.getMessage()); responseString.append("Dropped:" + dp); } } } if (writeResponse(request, ctx)) { ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE); } } } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.srotya.sidewinder.core.ingress.http.HTTPDataPointDecoder.java
License:Apache License
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE); }
From source file:com.supermy.im.netty.handler.ImServerHandler.java
License:Apache License
@Override public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { // ctxWriteAndFlush() ??? ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE); }
From source file:com.tesora.dve.db.mysql.libmy.MyFieldPktResponse.java
License:Open Source License
protected void ensureNotCached() { if (state == CacheState.NOT_CACHED) return;/*from w w w . ja v a 2 s. c om*/ ensureAllFieldsAreReadable();//unpack any unread fields so we don't lose them. updateCache(Unpooled.EMPTY_BUFFER); state = CacheState.NOT_CACHED; }
From source file:com.tesora.dve.db.mysql.portal.protocol.CachedAppendBuffer.java
License:Open Source License
public ByteBuf sliceWritableData() { int writtenLength = cachedSlab.writerIndex() - appendStartedAtIndex; if (writtenLength <= 0) return Unpooled.EMPTY_BUFFER; else {/*w w w.j av a 2s .co m*/ ByteBuf sliceSinceStarted = cachedSlab.slice(appendStartedAtIndex, writtenLength).retain(); //this will be written out to netty, so inc the ref count. return sliceSinceStarted; } }