Search in sources :

Example 6 with ByteBufHolder

use of io.netty.buffer.ByteBufHolder in project netty by netty.

the class DnsNameResolverContext method buildAliasMap.

private static Map<String, String> buildAliasMap(DnsResponse response) {
    final int answerCount = response.count(DnsSection.ANSWER);
    Map<String, String> cnames = null;
    for (int i = 0; i < answerCount; i++) {
        final DnsRecord r = response.recordAt(DnsSection.ANSWER, i);
        final DnsRecordType type = r.type();
        if (type != DnsRecordType.CNAME) {
            continue;
        }
        if (!(r instanceof DnsRawRecord)) {
            continue;
        }
        final ByteBuf recordContent = ((ByteBufHolder) r).content();
        final String domainName = decodeDomainName(recordContent);
        if (domainName == null) {
            continue;
        }
        if (cnames == null) {
            cnames = new HashMap<String, String>();
        }
        cnames.put(r.name().toLowerCase(Locale.US), domainName.toLowerCase(Locale.US));
    }
    return cnames != null ? cnames : Collections.<String, String>emptyMap();
}
Also used : DnsRawRecord(io.netty.handler.codec.dns.DnsRawRecord) ByteBufHolder(io.netty.buffer.ByteBufHolder) DnsRecordType(io.netty.handler.codec.dns.DnsRecordType) DnsRecord(io.netty.handler.codec.dns.DnsRecord) ByteBuf(io.netty.buffer.ByteBuf)

Example 7 with ByteBufHolder

use of io.netty.buffer.ByteBufHolder in project netty-socketio by mrniko.

the class WebSocketTransport method channelRead.

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg instanceof CloseWebSocketFrame) {
        ctx.channel().close();
        ReferenceCountUtil.release(msg);
    } else if (msg instanceof BinaryWebSocketFrame || msg instanceof TextWebSocketFrame) {
        ByteBufHolder frame = (ByteBufHolder) msg;
        ClientHead client = clientsBox.get(ctx.channel());
        if (client == null) {
            log.debug("Client with was already disconnected. Channel closed!");
            ctx.channel().close();
            frame.release();
            return;
        }
        ctx.pipeline().fireChannelRead(new PacketsMessage(client, frame.content(), Transport.WEBSOCKET));
        frame.release();
    } else if (msg instanceof FullHttpRequest) {
        FullHttpRequest req = (FullHttpRequest) msg;
        QueryStringDecoder queryDecoder = new QueryStringDecoder(req.uri());
        String path = queryDecoder.path();
        List<String> transport = queryDecoder.parameters().get("transport");
        List<String> sid = queryDecoder.parameters().get("sid");
        if (transport != null && NAME.equals(transport.get(0))) {
            try {
                if (!configuration.getTransports().contains(Transport.WEBSOCKET)) {
                    log.debug("{} transport not supported by configuration.", Transport.WEBSOCKET);
                    ctx.channel().close();
                    return;
                }
                if (sid != null && sid.get(0) != null) {
                    final UUID sessionId = UUID.fromString(sid.get(0));
                    handshake(ctx, sessionId, path, req);
                } else {
                    ClientHead client = ctx.channel().attr(ClientHead.CLIENT).get();
                    // first connection
                    handshake(ctx, client.getSessionId(), path, req);
                }
            } finally {
                req.release();
            }
        } else {
            ctx.fireChannelRead(msg);
        }
    } else {
        ctx.fireChannelRead(msg);
    }
}
Also used : CloseWebSocketFrame(io.netty.handler.codec.http.websocketx.CloseWebSocketFrame) QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) TextWebSocketFrame(io.netty.handler.codec.http.websocketx.TextWebSocketFrame) PacketsMessage(com.corundumstudio.socketio.messages.PacketsMessage) BinaryWebSocketFrame(io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame) ByteBufHolder(io.netty.buffer.ByteBufHolder) ClientHead(com.corundumstudio.socketio.handler.ClientHead) UUID(java.util.UUID)

Aggregations

ByteBufHolder (io.netty.buffer.ByteBufHolder)7 ByteBuf (io.netty.buffer.ByteBuf)4 DnsRawRecord (io.netty.handler.codec.dns.DnsRawRecord)2 DnsRecord (io.netty.handler.codec.dns.DnsRecord)2 Test (org.junit.Test)2 ClientHead (com.corundumstudio.socketio.handler.ClientHead)1 PacketsMessage (com.corundumstudio.socketio.messages.PacketsMessage)1 InvalidCharsetInContentTypeHeaderException (com.nike.riposte.server.error.exception.InvalidCharsetInContentTypeHeaderException)1 PathParameterMatchingException (com.nike.riposte.server.error.exception.PathParameterMatchingException)1 Endpoint (com.nike.riposte.server.http.Endpoint)1 RequestInfo (com.nike.riposte.server.http.RequestInfo)1 CompositeByteBuf (io.netty.buffer.CompositeByteBuf)1 DefaultByteBufHolder (io.netty.buffer.DefaultByteBufHolder)1 AddressedEnvelope (io.netty.channel.AddressedEnvelope)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelFutureListener (io.netty.channel.ChannelFutureListener)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 DnsRecordType (io.netty.handler.codec.dns.DnsRecordType)1 DnsResponse (io.netty.handler.codec.dns.DnsResponse)1 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)1