Java Code Examples for io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame#content()
The following examples show how to use
io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame#content() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NewNettyAcceptor.java From cassandana with Apache License 2.0 | 5 votes |
@Override protected void decode(ChannelHandlerContext chc, BinaryWebSocketFrame frame, List<Object> out) throws Exception { // convert the frame to a ByteBuf ByteBuf bb = frame.content(); bb.retain(); out.add(bb); }
Example 2
Source File: MqttOverWebsocketProtocolHandlerPipeline.java From joyqueue with Apache License 2.0 | 5 votes |
@Override protected void decode(ChannelHandlerContext chc, BinaryWebSocketFrame frame, List<Object> out) throws Exception { // convert the frame to a ByteBuf ByteBuf bb = frame.content(); // System.out.println("WebSocketFrameToByteBufDecoder decode - " + // ByteBufUtil.hexDump(bb)); bb.retain(); out.add(bb); }
Example 3
Source File: ByteMethodArgumentResolver.java From netty-websocket-spring-boot-starter with Apache License 2.0 | 5 votes |
@Override public Object resolveArgument(MethodParameter parameter, Channel channel, Object object) throws Exception { BinaryWebSocketFrame binaryWebSocketFrame = (BinaryWebSocketFrame) object; ByteBuf content = binaryWebSocketFrame.content(); byte[] bytes = new byte[content.readableBytes()]; content.readBytes(bytes); return bytes; }
Example 4
Source File: WebSocketBinaryFrameByteBufAdapter.java From util4j with Apache License 2.0 | 5 votes |
/** * 将webSocket消息转换为bytebuf类型,以适配后面的解码器 */ @Override protected void decode(ChannelHandlerContext paramChannelHandlerContext, WebSocketFrame paramINBOUND_IN, List<Object> paramList) throws Exception { if(paramINBOUND_IN instanceof BinaryWebSocketFrame) { BinaryWebSocketFrame msg=(BinaryWebSocketFrame)paramINBOUND_IN; ByteBuf data = msg.content(); paramList.add(data); data.retain(); } }
Example 5
Source File: NettyAcceptor.java From cloud-pubsub-mqtt-proxy with Apache License 2.0 | 5 votes |
@Override protected void decode(ChannelHandlerContext chc, BinaryWebSocketFrame frame, List<Object> out) throws Exception { //convert the frame to a ByteBuf ByteBuf bb = frame.content(); //System.out.println("WebSocketFrameToByteBufDecoder decode - " + ByteBufUtil.hexDump(bb)); bb.retain(); out.add(bb); }
Example 6
Source File: WsGremlinBinaryRequestDecoder.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override protected void decode(final ChannelHandlerContext channelHandlerContext, final BinaryWebSocketFrame frame, final List<Object> objects) throws Exception { final ByteBuf messageBytes = frame.content(); final byte len = messageBytes.readByte(); if (len <= 0) { objects.add(RequestMessage.INVALID); return; } final ByteBuf contentTypeBytes = channelHandlerContext.alloc().buffer(len); try { messageBytes.readBytes(contentTypeBytes); final String contentType = contentTypeBytes.toString(UTF8); final MessageSerializer serializer = select(contentType, ServerSerializers.DEFAULT_BINARY_SERIALIZER); // it's important to re-initialize these channel attributes as they apply globally to the channel. in // other words, the next request to this channel might not come with the same configuration and mixed // state can carry through from one request to the next channelHandlerContext.channel().attr(StateKey.SESSION).set(null); channelHandlerContext.channel().attr(StateKey.SERIALIZER).set(serializer); channelHandlerContext.channel().attr(StateKey.USE_BINARY).set(true); try { objects.add(serializer.deserializeRequest(messageBytes.discardReadBytes())); } catch (SerializationException se) { objects.add(RequestMessage.INVALID); } } finally { contentTypeBytes.release(); } }
Example 7
Source File: PacketDecoder.java From ThinkMap with Apache License 2.0 | 5 votes |
@Override protected void decode(ChannelHandlerContext ctx, BinaryWebSocketFrame msg, List<Object> out) throws Exception { ByteBuf in = msg.content(); int id = in.readUnsignedByte(); Packet packet = Packets.createClientPacket(id); packet.read(new ByteBufPacketStream(in)); out.add(packet); }
Example 8
Source File: WebSocket2ByteBufDecoder.java From iot-mqtt with Apache License 2.0 | 4 votes |
@Override protected void decode(ChannelHandlerContext channelHandlerContext, BinaryWebSocketFrame binaryWebSocketFrame, List<Object> list) throws Exception { ByteBuf byteBuf = binaryWebSocketFrame.content(); byteBuf.retain(); list.add(byteBuf); }
Example 9
Source File: WebSocket2ByteBufDecoder.java From jmqtt with Apache License 2.0 | 4 votes |
@Override protected void decode(ChannelHandlerContext channelHandlerContext, BinaryWebSocketFrame binaryWebSocketFrame, List<Object> list) throws Exception { ByteBuf byteBuf = binaryWebSocketFrame.content(); byteBuf.retain(); list.add(byteBuf); }
Example 10
Source File: WebSocketClientHandler.java From karate with MIT License | 4 votes |
@Override public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { Channel ch = ctx.channel(); if (!handshaker.isHandshakeComplete()) { try { handshaker.finishHandshake(ch, (FullHttpResponse) msg); logger.debug("websocket client connected"); handshakeFuture.setSuccess(); } catch (WebSocketHandshakeException e) { logger.debug("websocket client connect failed: {}", e.getMessage()); handshakeFuture.setFailure(e); } return; } if (msg instanceof FullHttpResponse) { FullHttpResponse response = (FullHttpResponse) msg; throw new IllegalStateException( "unexpected FullHttpResponse (getStatus=" + response.status() + ", content=" + response.content().toString(CharsetUtil.UTF_8) + ')'); } WebSocketFrame frame = (WebSocketFrame) msg; if (frame instanceof TextWebSocketFrame) { if (logger.isTraceEnabled()) { logger.trace("websocket received text"); } TextWebSocketFrame textFrame = (TextWebSocketFrame) frame; listener.onMessage(textFrame.text()); } else if (frame instanceof PongWebSocketFrame) { if (logger.isTraceEnabled()) { logger.trace("websocket received pong"); } } else if (frame instanceof CloseWebSocketFrame) { logger.debug("websocket closing"); ch.close(); } else if (frame instanceof BinaryWebSocketFrame) { logger.debug("websocket received binary"); BinaryWebSocketFrame binaryFrame = (BinaryWebSocketFrame) frame; ByteBuf buf = binaryFrame.content(); byte[] bytes = new byte[buf.readableBytes()]; buf.readBytes(bytes); listener.onMessage(bytes); } }