Example usage for io.netty.channel ChannelHandlerContext handler

List of usage examples for io.netty.channel ChannelHandlerContext handler

Introduction

In this page you can find the example usage for io.netty.channel ChannelHandlerContext handler.

Prototype

ChannelHandler handler();

Source Link

Document

The ChannelHandler that is bound this ChannelHandlerContext .

Usage

From source file:com.linecorp.armeria.client.http.HttpClientPipelineConfigurator.java

License:Apache License

void addBeforeSessionHandler(ChannelPipeline pipeline, ChannelHandler handler) {
    // Get the name of the HttpSessionHandler so that we can put our handlers before it.
    final ChannelHandlerContext lastContext = pipeline.lastContext();
    assert lastContext.handler().getClass() == HttpSessionHandler.class;

    pipeline.addBefore(lastContext.name(), null, handler);
}

From source file:com.phei.netty.basic.TimeServerHandlerTwo.java

License:Apache License

@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
    System.out.println("channelReadComplete === " + ctx.handler().getClass());
    ctx.flush();//www.j av  a2 s.co m
}

From source file:com.tesora.dve.db.mysql.portal.MSPCommandHandler.java

License:Open Source License

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    if (processUnhandledExceptions && ctx.channel().isActive()) {
        logger.warn(ctx.handler().toString() + " - Unexpected exception from downstream.", cause);
        Exception exc;/*from w w  w . ja va  2  s  .c  o m*/
        boolean closeChannel = false;
        if (cause instanceof Exception) {
            exc = (Exception) cause;
        } else {
            closeChannel = true;
            exc = new Exception("Unhandled Exception", cause);
        }
        ctx.write(new MyErrorResponse(exc));
        if (closeChannel)
            ctx.close();
    }
}

From source file:com.tesora.dve.db.mysql.portal.protocol.StreamValve.java

License:Open Source License

public static StreamValve locateValve(ChannelPipeline pipeline) throws NoSuchElementException {
    //TODO: this assumes only one StreamValve in a pipeline. -sgossard
    ChannelHandlerContext context = pipeline.context(StreamValve.class);

    if (context == null) //TODO: if users wind up calling this directly, it would be nice to provide a no-op version on request. -sgossard
        throw new NoSuchElementException("PauseResume not configured on the current pipeline");

    //cast shouldn't fail, we looked up the context by handler class.
    return (StreamValve) context.handler();
}

From source file:io.advantageous.conekt.net.impl.ConnectionBase.java

License:Open Source License

public X509Certificate[] getPeerCertificateChain() throws SSLPeerUnverifiedException {
    if (isSSL()) {
        ChannelHandlerContext sslHandlerContext = channel.pipeline().context("ssl");
        assert sslHandlerContext != null;
        SslHandler sslHandler = (SslHandler) sslHandlerContext.handler();
        return sslHandler.engine().getSession().getPeerCertificateChain();
    } else {/*from  www  .j ava 2s  . c  om*/
        return null;
    }
}

From source file:io.grpc.netty.NettyClientHandler.java

License:Apache License

static void writeBufferingAndRemove(Channel channel) {
    checkNotNull(channel, "channel");
    ChannelHandlerContext handlerCtx = channel.pipeline().context(WriteBufferingAndExceptionHandler.class);
    if (handlerCtx == null) {
        return;//from ww  w .j av  a2 s .  c  o  m
    }
    ((WriteBufferingAndExceptionHandler) handlerCtx.handler()).writeBufferedAndRemove(handlerCtx);
}

From source file:io.jsync.net.impl.ConnectionBase.java

License:Open Source License

public X509Certificate[] getPeerCertificateChain() throws SSLPeerUnverifiedException {
    if (isSSL()) {
        final ChannelHandlerContext sslHandlerContext = channel.pipeline().context("ssl");
        assert sslHandlerContext != null;
        final SslHandler sslHandler = (SslHandler) sslHandlerContext.handler();
        return sslHandler.engine().getSession().getPeerCertificateChain();
    } else {//from w w w .  j ava2  s .co m
        return null;
    }
}

From source file:org.ebayopensource.scc.debug.DebugManager.java

License:Apache License

/**
 * Issue a debug request when debugging is enabled.
 *
 * @param httpObject      Http request of client
 * @param m_ctx           Netty context/*from   ww  w .ja  v  a 2 s  .c o m*/
 * @param fromDebugFilter Indicator shows if the request require to be forwarded
 * @return An indicator showing if debug manager consumes the request. If true, the caller needs to stop handling request.
 */
public void issueDebugRequest(FullHttpRequest httpObject, final ChannelHandlerContext m_ctx,
        boolean fromDebugFilter) {
    if (debugEnabled()) {
        final FullHttpRequest request = httpObject.copy();
        if (fromDebugFilter) {
            try {
                if (ssl(request)) {
                    Field field = ClientToProxyConnection.class.getDeclaredField("mitming");
                    field.setAccessible(true);
                    field.set(m_ctx.handler(), true);
                }
            } catch (Exception e) {
                LOGGER.error(e.getMessage());
            }
            String key = m_policyManager.generateCacheKey(request);
            FullHttpResponse cacheResponse = m_policyManager.getCacheManager().get(key);
            CacheResultVerifier verifier = new CacheResultVerifier(key, request, cacheResponse);
            Attribute<CacheResultVerifier> debugging = m_ctx.attr(DEBUG_RESULT);
            debugging.set(verifier);
        } else {
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    forwardDebugRequest(request);
                }
            });
        }
    }
}

From source file:org.ebayopensource.scc.debug.DebugManagerTest.java

License:Apache License

@Test
@SuppressWarnings("unchecked")
public void testIssueDebugRequest_sslFromDebugFilter() {
    Mockito.when(m_appConfiguration.getBoolean("debugManager.debugEnabled")).thenReturn(true);
    FullHttpRequest request = Mockito.mock(FullHttpRequest.class);
    FullHttpResponse cacheResponse = Mockito.mock(FullHttpResponse.class);
    ChannelHandlerContext ctx = Mockito.mock(ChannelHandlerContext.class);
    Mockito.when(ctx.handler()).thenReturn(clientToProxyConnection);
    Mockito.when(request.copy()).thenReturn(request);
    String key = "https://serverHostAndPort=www.ebay.com:443";
    Mockito.when(m_cacheManager.get(key)).thenReturn(cacheResponse);
    Mockito.when(m_policyManager.generateCacheKey(request)).thenReturn(key);

    Attribute<CacheResultVerifier> debugging = Mockito.mock(Attribute.class);
    Mockito.when(ctx.attr(DebugManager.DEBUG_RESULT)).thenReturn(debugging);
    debugManager.issueDebugRequest(request, ctx, true);
    Assert.assertTrue((Boolean) readField(clientToProxyConnection, "mitming"));
    CacheResultVerifier verifier = new CacheResultVerifier(key, request, cacheResponse);
    Mockito.verify(debugging, Mockito.times(1)).set(Mockito.refEq(verifier));
}

From source file:org.telegram.core.Router.java

License:Open Source License

public void Route(int user_id, TLObject msg, boolean rpc_response) {
    for (Object sess : activeSessions.values(new SqlPredicate("user_id = " + user_id)).toArray()) {
        //for now all sessions are on the same server
        ChannelHandlerContext ctx = channelHandlers.get(((ActiveSession) sess).session_id);
        long msg_id = ((TelegramServerHandler) ctx.handler()).generateMessageId(rpc_response);

        ctx.writeAndFlush(encryptRpc(msg, ((TelegramServerHandler) ctx.handler()).getMessageSeqNo(true), msg_id,
                ((ActiveSession) sess).session_id, ((ActiveSession) sess).auth_key_id));
    }//from w  ww.j a  v a 2 s . com
}