List of usage examples for io.netty.channel ChannelHandlerContext name
String name();
From source file:org.asterisque.netty.WireConnect.java
License:Apache License
/** * ???????????//from ww w . j ava 2 s .c o m * SSL ?????? * @param ctx */ @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { trace("channelActive(" + ctx.name() + ")"); assert (!wire.isPresent()); // SSLHandler ???????? SSLSession ? CompletableFuture<Optional<SSLSession>> future = new CompletableFuture<>(); if (sslHandler.isPresent()) { SslHandler h = sslHandler.get(); h.handshakeFuture().addListener(f -> { SSLSession session = h.engine().getSession(); if (session.isValid()) { // SSL ? future.complete(Optional.of(session)); debug("tls handshake success"); } else { // SSL ? future.completeExceptionally(new IOException("tls handshake failure: invalid session")); debug("tls handshake failure: invalid session"); } Debug.dumpSSLSession(logger, sym + "[" + id + "]", session); }); } else { // SSL ?? future.complete(Optional.empty()); } // Wire NettyWire w = new NettyWire(node, local, remote, isServer, future, ctx); wire = Optional.of(w); super.channelActive(ctx); // onWireCreate.accept(w); }
From source file:org.asterisque.netty.WireConnect.java
License:Apache License
/** * @param ctx //from www . j a va2 s .c o m */ @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { trace("channelInactive(" + ctx.name() + ")"); closeWire(); super.channelInactive(ctx); }
From source file:org.asterisque.netty.WireConnect.java
License:Apache License
/** * @param ctx /*from w ww . j a v a 2s . c o m*/ * @param msg */ @Override public void channelRead0(ChannelHandlerContext ctx, Message msg) throws Exception { trace("channelRead0(" + ctx.name() + "," + msg + ")"); // assert (wire.isPresent()); wire.ifPresent(w -> { w.receive(msg); }); // super.channelRead0(ctx, msg) ? }
From source file:org.ballerinalang.test.util.websocket.server.WebSocketHeadersHandler.java
License:Open Source License
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (msg instanceof HttpResponse) { HttpResponse response = (HttpResponse) msg; response.headers().add("X-server-header", "server-header-value"); promise.addListener(future -> ctx.pipeline().remove(ctx.name())); }/*from w w w .ja va2 s . c o m*/ super.write(ctx, msg, promise); }
From source file:org.eclipse.milo.opcua.stack.server.transport.uasc.UascServerAsymmetricHandler.java
License:Open Source License
private void sendOpenSecureChannelResponse(ChannelHandlerContext ctx, long requestId, OpenSecureChannelRequest request) { serializationQueue.encode((binaryEncoder, chunkEncoder) -> { ByteBuf messageBuffer = BufferUtil.pooledBuffer(); try {//from w ww. j a v a 2 s.c om OpenSecureChannelResponse response = openSecureChannel(ctx, request); binaryEncoder.setBuffer(messageBuffer); binaryEncoder.writeMessage(null, response); checkMessageSize(messageBuffer); chunkEncoder.encodeAsymmetric(secureChannel, requestId, messageBuffer, MessageType.OpenSecureChannel, new ChunkEncoder.Callback() { @Override public void onEncodingError(UaException ex) { logger.error("Error encoding OpenSecureChannelResponse: {}", ex.getMessage(), ex); ctx.fireExceptionCaught(ex); } @Override public void onMessageEncoded(List<ByteBuf> messageChunks, long requestId) { if (!symmetricHandlerAdded) { UascServerSymmetricHandler symmetricHandler = new UascServerSymmetricHandler( stackServer, serializationQueue, secureChannel); ctx.pipeline().addBefore(ctx.name(), null, symmetricHandler); symmetricHandlerAdded = true; } CompositeByteBuf chunkComposite = BufferUtil.compositeBuffer(); for (ByteBuf chunk : messageChunks) { chunkComposite.addComponent(chunk); chunkComposite .writerIndex(chunkComposite.writerIndex() + chunk.readableBytes()); } ctx.writeAndFlush(chunkComposite, ctx.voidPromise()); logger.debug("Sent OpenSecureChannelResponse."); } }); } catch (UaException e) { logger.error("Error installing security token: {}", e.getStatusCode(), e); ctx.close(); } catch (UaSerializationException e) { ctx.fireExceptionCaught(e); } finally { messageBuffer.release(); } }); }
From source file:org.glassfish.jersey.netty.httpserver.JerseyServerInitializer.java
License:Open Source License
/** * Configure the pipeline for a cleartext upgrade from HTTP to HTTP/2. *///from w ww. j av a 2s. co m private void configureClearText(SocketChannel ch) { final ChannelPipeline p = ch.pipeline(); final HttpServerCodec sourceCodec = new HttpServerCodec(); p.addLast(sourceCodec); p.addLast(new HttpServerUpgradeHandler(sourceCodec, new HttpServerUpgradeHandler.UpgradeCodecFactory() { @Override public HttpServerUpgradeHandler.UpgradeCodec newUpgradeCodec(CharSequence protocol) { if (AsciiString.contentEquals(Http2CodecUtil.HTTP_UPGRADE_PROTOCOL_NAME, protocol)) { return new Http2ServerUpgradeCodec( new Http2Codec(true, new JerseyHttp2ServerHandler(baseUri, container))); } else { return null; } } })); p.addLast(new SimpleChannelInboundHandler<HttpMessage>() { @Override protected void channelRead0(ChannelHandlerContext ctx, HttpMessage msg) throws Exception { // If this handler is hit then no upgrade has been attempted and the client is just talking HTTP. // "Directly talking: " + msg.protocolVersion() + " (no upgrade was attempted)"); ChannelPipeline pipeline = ctx.pipeline(); ChannelHandlerContext thisCtx = pipeline.context(this); pipeline.addAfter(thisCtx.name(), null, new JerseyServerHandler(baseUri, container)); pipeline.replace(this, null, new ChunkedWriteHandler()); ctx.fireChannelRead(msg); } }); }
From source file:org.glowroot.agent.plugin.netty.CleartextHttp2ServerUpgradeHandler.java
License:Apache License
@Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { ctx.pipeline().addBefore(ctx.name(), null, new PriorKnowledgeHandler()) .addBefore(ctx.name(), null, httpServerCodec).replace(this, null, httpServerUpgradeHandler); }
From source file:org.infinispan.server.core.transport.SaslServerHandler.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ByteBuf buf = (ByteBuf) msg;//from w w w . j a v a 2 s .c o m Channel ch = ctx.channel(); try { if (!firstPass) { readHeader(buf); } else { firstPass = false; } byte[] bytes = readBytes(buf); byte[] challenge = server.evaluateResponse(bytes); if (!server.isComplete()) { ch.writeAndFlush(newContinueMessage(ctx, Unpooled.wrappedBuffer(challenge))); } else { ch.writeAndFlush(newSuccessMessage(ctx, Unpooled.wrappedBuffer(challenge))); ChannelPipeline pipeline = ctx.pipeline(); String qop = (String) server.getNegotiatedProperty(Sasl.QOP); if (qop != null && (qop.equalsIgnoreCase(AUTH_INT) || qop.equalsIgnoreCase(AUTO_CONF))) { SaslServer server = this.server; this.server = null; // Replace this handler now with the QopHandler // This is mainly done as the QopHandler itself will not block at all and so we can // get rid of the usage of the EventExecutorGroup after the negation took place. pipeline.replace(this, ctx.name(), new QopHandler(server)); } else { // there is no need for any QOP handling so we are done now and can just remove ourself from the // pipeline pipeline.remove(this); } } } catch (SaslException e) { Object errorMsg = newErrorMessage(ctx, e); if (errorMsg != null) { ch.writeAndFlush(errorMsg).addListener(ChannelFutureListener.CLOSE); } } }
From source file:org.jfxvnc.net.rfb.codec.handshaker.RfbClientHandshaker.java
License:Apache License
public final ChannelFuture handshake(Channel channel, final ChannelPromise promise) { channel.writeAndFlush(Unpooled.wrappedBuffer(version.getBytes())).addListener((ChannelFuture future) -> { if (!future.isSuccess()) { promise.setFailure(future.cause()); return; }//from ww w .ja v a 2 s . co m ChannelPipeline p = future.channel().pipeline(); ChannelHandlerContext ctx = p.context(ProtocolHandshakeHandler.class); p.addBefore(ctx.name(), "rfb-handshake-decoder", newRfbClientDecoder()); p.addBefore(ctx.name(), "rfb-handshake-encoder", newRfbClientEncoder()); promise.setSuccess(); }); return promise; }
From source file:org.jfxvnc.net.rfb.codec.ProtocolHandler.java
License:Apache License
@Override protected void decode(final ChannelHandlerContext ctx, Object msg, List<Object> out) throws Exception { if (msg instanceof ImageRect) { render.render((ImageRect) msg, () -> { // logger.debug("render completed"); // sendFramebufferUpdateRequest(ctx, true, 0, 0, // serverInit.getFrameBufferWidth(), // serverInit.getFrameBufferHeight()); });// w w w . ja v a2 s . com return; } if (msg instanceof ServerDecoderEvent) { render.eventReceived((ServerDecoderEvent) msg); return; } if (!(msg instanceof ServerInitEvent)) { logger.error("unknown message: {}", msg); ctx.fireChannelRead(msg); return; } serverInit = (ServerInitEvent) msg; logger.debug("handshake completed with {}", serverInit); FrameDecoderHandler frameHandler = new FrameDecoderHandler(serverInit.getPixelFormat()); if (!frameHandler.isPixelFormatSupported()) { ProtocolException e = new ProtocolException(String.format("pixelformat: (%s bpp) not supported yet", serverInit.getPixelFormat().getBitPerPixel())); exceptionCaught(ctx, e); return; } ChannelPipeline cp = ctx.pipeline(); cp.addBefore(ctx.name(), "rfb-encoding-encoder", new PreferedEncodingEncoder()); PreferedEncoding prefEncodings = getPreferedEncodings(frameHandler.getSupportedEncodings()); ctx.write(prefEncodings); cp.addBefore(ctx.name(), "rfb-pixelformat-encoder", new PixelFormatEncoder()); ctx.write(serverInit.getPixelFormat()); ctx.flush(); cp.addBefore(ctx.name(), "rfb-frame-handler", frameHandler); cp.addBefore(ctx.name(), "rfb-keyevent-encoder", new KeyButtonEventEncoder()); cp.addBefore(ctx.name(), "rfb-pointerevent-encoder", new PointerEventEncoder()); cp.addBefore(ctx.name(), "rfb-cuttext-encoder", new ClientCutTextEncoder()); render.eventReceived(getConnectInfoEvent(ctx, prefEncodings)); render.registerInputEventListener(event -> ctx.writeAndFlush(event, ctx.voidPromise())); logger.debug("request full framebuffer update"); sendFramebufferUpdateRequest(ctx, false, 0, 0, serverInit.getFrameBufferWidth(), serverInit.getFrameBufferHeight()); logger.trace("channel pipeline: {}", cp.toMap().keySet()); }