@Override public void subscribe(final Subscriber<? super IN> subscriber) { // Handle the 'Expect: 100-continue' header if necessary. // TODO: Respond with 413 Request Entity Too Large // and discard the traffic or close the connection. // No need to notify the upstream handlers - just log. // If decoding a response, just throw an exception. if (is100ContinueExpected(nettyRequest)) { tcpStream.delegate().writeAndFlush(CONTINUE).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { subscriber.onError(future.cause()); } else { tcpStream.subscribe(subscriber); } } }); } else { tcpStream.subscribe(subscriber); } }
@Override protected void doDecoded(IN in) { tcpStream.doDecoded(in); }
@Override protected void doSubscribeWriter(Publisher<? extends OUT> writer, Subscriber<? super Void> postWriter) { tcpStream.doSubscribeWriter(writer, postWriter); }
public NettyHttpChannel(NettyChannelStream<IN, OUT> tcpStream, HttpRequest request ) { super(tcpStream.getEnvironment(), tcpStream.getCapacity(), tcpStream.getDispatcher()); this.tcpStream = tcpStream; this.nettyRequest = request; this.nettyResponse = new DefaultHttpResponse(request.getProtocolVersion(), HttpResponseStatus.OK); this.headers = new NettyHttpHeaders(request); this.responseHeaders = new NettyHttpResponseHeaders(this.nettyResponse); responseHeader(ResponseHeaders.TRANSFER_ENCODING, "chunked"); }
protected void bindChannel(ReactorChannelHandler<IN, OUT, ChannelStream<IN, OUT>> handler, SocketChannel nativeChannel) { NettyChannelStream<IN ,OUT> netChannel = new NettyChannelStream<IN, OUT>( getDefaultEnvironment(), getDefaultCodec(), getDefaultPrefetchSize(), getDefaultDispatcher(), nativeChannel ); ChannelPipeline pipeline = nativeChannel.pipeline(); if(log.isDebugEnabled()){ pipeline.addLast(new LoggingHandler(NettyTcpServer.class)); } pipeline.addLast( new NettyChannelHandlerBridge<IN, OUT>(handler, netChannel) ); }
public NettyHttpWSServerHandler(String wsUrl, String protocols, NettyHttpServerHandler<IN, OUT> originalHandler) { super(originalHandler.getHandler(), originalHandler.getChannelStream()); this.request = originalHandler.request; this.plainText = originalHandler.getChannelStream().getEncoder() instanceof StringCodec.StringEncoder; // Handshake WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(wsUrl, protocols, true); handshaker = wsFactory.newHandshaker(request.getNettyRequest()); if (handshaker == null) { WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(channelStream.delegate()); } else { handshaker.handshake(channelStream.delegate(), request.getNettyRequest()); } }
private void passToConnection(ByteBuf data) { Buffer b = new Buffer(data.nioBuffer()); int start = b.position(); if (null != channelStream.getDecoder() && null != b.byteBuffer()) { IN read = channelStream.getDecoder().apply(b); if (read != null) { channelSubscription.onNext(read); } } //data.remaining() > 0; data.skipBytes(b.position() - start); }
public NettyHttpWSClientHandler( ReactorChannelHandler<IN, OUT, ChannelStream<IN, OUT>> handler, NettyChannelStream<IN, OUT> tcpStream, WebSocketClientHandshaker handshaker) { super(handler, tcpStream); this.handshaker = handshaker; this.plainText = tcpStream.getEncoder() instanceof StringCodec.StringEncoder; }
@Override @SuppressWarnings("unchecked") public SocketChannel delegate() { return (SocketChannel) tcpStream.delegate(); }
@Override public ConsumerSpec on() { return tcpStream.on(); }
protected void bindChannel(ReactorChannelHandler<IN, OUT, ChannelStream<IN, OUT>> handler, SocketChannel nativeChannel) { NettyChannelStream<IN, OUT> netChannel = new NettyChannelStream<IN, OUT>( getDefaultEnvironment(), getDefaultCodec(), getDefaultPrefetchSize(), getDefaultDispatcher(), nativeChannel ); ChannelPipeline pipeline = nativeChannel.pipeline(); if (log.isDebugEnabled()) { pipeline.addLast(new LoggingHandler(NettyTcpClient.class)); } pipeline.addLast( new NettyChannelHandlerBridge<IN, OUT>(handler, netChannel) ); }
@Override @SuppressWarnings("unchecked") public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { Class<?> messageClass = msg.getClass(); if (!handshaker.isHandshakeComplete()) { handshaker.finishHandshake(ctx.channel(), (FullHttpResponse) msg); NettyHttpWSClientHandler.super.channelActive(ctx); super.channelRead(ctx, msg); return; } if (TextWebSocketFrame.class.isAssignableFrom(messageClass)) { try { Buffer buffer = Buffer.wrap(((TextWebSocketFrame) msg).text()); if (channelStream.getDecoder() == null) { channelSubscription.onNext((IN) buffer); } else { IN d = channelStream.getDecoder().apply(buffer); if (d != null) { channelSubscription.onNext(d); } } } finally { ReferenceCountUtil.release(msg); } } else if (CloseWebSocketFrame.class.isAssignableFrom(messageClass)) { ctx.close(); } else { doRead(ctx, ((WebSocketFrame)msg).content()); } }
if (getEncoder() != null) { encodedWriter = Streams.wrap(writer).map(getEncoder()); } else { encodedWriter = writer;
protected void bindChannel(ReactorChannelHandler<IN, OUT, ChannelStream<IN, OUT>> handler, SocketChannel nativeChannel) { NettyChannelStream<IN, OUT> netChannel = new NettyChannelStream<IN, OUT>( getDefaultEnvironment(), getDefaultCodec(), getDefaultPrefetchSize(), getDefaultDispatcher(), nativeChannel ); ChannelPipeline pipeline = nativeChannel.pipeline(); if (log.isDebugEnabled()) { pipeline.addLast(new LoggingHandler(NettyHttpServer.class)); } pipeline .addLast(new HttpServerCodec()); if (hasWebsocketEndpoints()) { pipeline.addLast(new HttpObjectAggregator(65536)); } pipeline .addLast(new NettyHttpServerHandler<IN, OUT>(handler, netChannel)); } }
if (channelStream.getDecoder() == Spec.NOOP_DECODER || !ByteBuf.class.isAssignableFrom(msg.getClass())) { channelSubscription.onNext((IN) msg); return; } else if (channelStream.getDecoder() == null) { try { channelSubscription.onNext((IN) new Buffer(((ByteBuf) msg).nioBuffer()));
protected void bindChannel(ReactorChannelHandler<IN, OUT, ChannelStream<IN, OUT>> handler, Object nativeChannel) { SocketChannel ch = (SocketChannel) nativeChannel; NettyChannelStream<IN, OUT> netChannel = new NettyChannelStream<IN, OUT>( getDefaultEnvironment(), getDefaultCodec(),
protected void bindChannel(ReactorChannelHandler<IN, OUT, ChannelStream<IN,OUT>> handler, Object _ioChannel) { DatagramChannel ioChannel = (DatagramChannel) _ioChannel; NettyChannelStream<IN, OUT> netChannel = new NettyChannelStream<IN, OUT>( getDefaultEnvironment(), getDefaultCodec(),