Search in sources :

Example 1 with SpdyFrameCodec

use of io.netty.handler.codec.spdy.SpdyFrameCodec in project netty by netty.

the class SpdyOrHttpHandler method configureSpdy.

private static void configureSpdy(ChannelHandlerContext ctx, SpdyVersion version) throws Exception {
    ChannelPipeline p = ctx.pipeline();
    p.addLast(new SpdyFrameCodec(version));
    p.addLast(new SpdySessionHandler(version, true));
    p.addLast(new SpdyHttpEncoder(version));
    p.addLast(new SpdyHttpDecoder(version, MAX_CONTENT_LENGTH));
    p.addLast(new SpdyHttpResponseStreamIdHandler());
    p.addLast(new SpdyServerHandler());
}
Also used : SpdyHttpDecoder(io.netty.handler.codec.spdy.SpdyHttpDecoder) SpdyFrameCodec(io.netty.handler.codec.spdy.SpdyFrameCodec) SpdySessionHandler(io.netty.handler.codec.spdy.SpdySessionHandler) SpdyHttpEncoder(io.netty.handler.codec.spdy.SpdyHttpEncoder) SpdyHttpResponseStreamIdHandler(io.netty.handler.codec.spdy.SpdyHttpResponseStreamIdHandler) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 2 with SpdyFrameCodec

use of io.netty.handler.codec.spdy.SpdyFrameCodec in project netty by netty.

the class SocketSpdyEchoTest method testSpdyEcho.

private static void testSpdyEcho(ServerBootstrap sb, Bootstrap cb, final SpdyVersion version, boolean autoRead) throws Throwable {
    ByteBuf frames;
    switch(version) {
        case SPDY_3_1:
            frames = createFrames(3);
            break;
        default:
            throw new IllegalArgumentException("unknown version");
    }
    sb.childOption(ChannelOption.AUTO_READ, autoRead);
    cb.option(ChannelOption.AUTO_READ, autoRead);
    final SpdyEchoTestServerHandler sh = new SpdyEchoTestServerHandler(autoRead);
    final SpdyEchoTestClientHandler ch = new SpdyEchoTestClientHandler(frames.copy(), autoRead);
    sb.childHandler(new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel channel) throws Exception {
            channel.pipeline().addLast(new SpdyFrameCodec(version), sh);
        }
    });
    cb.handler(ch);
    Channel sc = sb.localAddress(0).bind().sync().channel();
    int port = ((InetSocketAddress) sc.localAddress()).getPort();
    Channel cc = cb.remoteAddress(NetUtil.LOCALHOST, port).connect().sync().channel();
    cc.writeAndFlush(frames);
    while (ch.counter < frames.writerIndex() - ignoredBytes) {
        if (sh.exception.get() != null) {
            break;
        }
        if (ch.exception.get() != null) {
            break;
        }
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
        // Ignore.
        }
    }
    if (sh.exception.get() != null && !(sh.exception.get() instanceof IOException)) {
        throw sh.exception.get();
    }
    if (ch.exception.get() != null && !(ch.exception.get() instanceof IOException)) {
        throw ch.exception.get();
    }
    if (sh.exception.get() != null) {
        throw sh.exception.get();
    }
    if (ch.exception.get() != null) {
        throw ch.exception.get();
    }
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) SpdyFrameCodec(io.netty.handler.codec.spdy.SpdyFrameCodec) InetSocketAddress(java.net.InetSocketAddress) Channel(io.netty.channel.Channel) SocketChannel(io.netty.channel.socket.SocketChannel) IOException(java.io.IOException) ByteBuf(io.netty.buffer.ByteBuf) IOException(java.io.IOException)

Example 3 with SpdyFrameCodec

use of io.netty.handler.codec.spdy.SpdyFrameCodec in project netty by netty.

the class SpdyClientInitializer method initChannel.

@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();
    pipeline.addLast("ssl", sslCtx.newHandler(ch.alloc()));
    pipeline.addLast("spdyFrameCodec", new SpdyFrameCodec(SPDY_3_1));
    pipeline.addLast("spdyFrameLogger", new SpdyFrameLogger(INFO));
    pipeline.addLast("spdySessionHandler", new SpdySessionHandler(SPDY_3_1, false));
    pipeline.addLast("spdyHttpEncoder", new SpdyHttpEncoder(SPDY_3_1));
    pipeline.addLast("spdyHttpDecoder", new SpdyHttpDecoder(SPDY_3_1, MAX_SPDY_CONTENT_LENGTH));
    pipeline.addLast("spdyStreamIdHandler", new SpdyClientStreamIdHandler());
    pipeline.addLast("httpHandler", httpResponseHandler);
}
Also used : SpdyHttpDecoder(io.netty.handler.codec.spdy.SpdyHttpDecoder) SpdyFrameCodec(io.netty.handler.codec.spdy.SpdyFrameCodec) SpdySessionHandler(io.netty.handler.codec.spdy.SpdySessionHandler) SpdyHttpEncoder(io.netty.handler.codec.spdy.SpdyHttpEncoder) ChannelPipeline(io.netty.channel.ChannelPipeline)

Aggregations

SpdyFrameCodec (io.netty.handler.codec.spdy.SpdyFrameCodec)3 ChannelPipeline (io.netty.channel.ChannelPipeline)2 SpdyHttpDecoder (io.netty.handler.codec.spdy.SpdyHttpDecoder)2 SpdyHttpEncoder (io.netty.handler.codec.spdy.SpdyHttpEncoder)2 SpdySessionHandler (io.netty.handler.codec.spdy.SpdySessionHandler)2 ByteBuf (io.netty.buffer.ByteBuf)1 Channel (io.netty.channel.Channel)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 SpdyHttpResponseStreamIdHandler (io.netty.handler.codec.spdy.SpdyHttpResponseStreamIdHandler)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1