Example usage for io.netty.handler.codec.haproxy HAProxyProxiedProtocol TCP4

List of usage examples for io.netty.handler.codec.haproxy HAProxyProxiedProtocol TCP4

Introduction

In this page you can find the example usage for io.netty.handler.codec.haproxy HAProxyProxiedProtocol TCP4.

Prototype

HAProxyProxiedProtocol TCP4

To view the source code for io.netty.handler.codec.haproxy HAProxyProxiedProtocol TCP4.

Click Source Link

Document

The TCP4 represents a connection which was forwarded for an IPv4 client over TCP.

Usage

From source file:diskCacheV111.doors.NettyLineBasedDoor.java

License:Open Source License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg instanceof HAProxyMessage) {
        HAProxyMessage proxyMessage = (HAProxyMessage) msg;
        switch (proxyMessage.command()) {
        case LOCAL:
            ctx.close();/*from   www.  j a v  a 2  s  . c  o m*/
            return;
        case PROXY:
            String sourceAddress = proxyMessage.sourceAddress();
            String destinationAddress = proxyMessage.destinationAddress();
            InetSocketAddress localAddress = (InetSocketAddress) ctx.channel().localAddress();
            if (proxyMessage.proxiedProtocol() == HAProxyProxiedProtocol.TCP4
                    || proxyMessage.proxiedProtocol() == HAProxyProxiedProtocol.TCP6) {
                if (Objects.equals(destinationAddress, localAddress.getAddress().getHostAddress())) {
                    /* Workaround for what looks like a bug in HAProxy - health checks should
                     * generate a LOCAL command, but it appears they do actually use PROXY.
                     */
                    ctx.close();
                    return;
                } else {
                    this.proxyAddress = new InetSocketAddress(InetAddresses.forString(destinationAddress),
                            proxyMessage.destinationPort());
                    this.remoteAddress = new InetSocketAddress(InetAddresses.forString(sourceAddress),
                            proxyMessage.sourcePort());
                }
            }
            break;
        }
        start(ctx);
    } else if (msg instanceof String) {
        if (interpreter == null) {
            throw new IOException("Unexpected input: " + msg);
        }
        commandExecutor.execute(new Command((String) msg));
    }
}

From source file:org.dcache.xrootd.core.XrootdRequestHandler.java

License:Open Source License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg instanceof XrootdRequest) {
        requestReceived(ctx, (XrootdRequest) msg);
    } else if (msg instanceof HAProxyMessage) {
        HAProxyMessage proxyMessage = (HAProxyMessage) msg;
        switch (proxyMessage.command()) {
        case LOCAL:
            _isHealthCheck = true;/*  w  w w . j  av  a2s . c  o m*/
            break;
        case PROXY:
            String sourceAddress = proxyMessage.sourceAddress();
            String destinationAddress = proxyMessage.destinationAddress();
            InetSocketAddress localAddress = (InetSocketAddress) ctx.channel().localAddress();
            if (proxyMessage.proxiedProtocol() == HAProxyProxiedProtocol.TCP4
                    || proxyMessage.proxiedProtocol() == HAProxyProxiedProtocol.TCP6) {
                if (Objects.equals(destinationAddress, localAddress.getAddress().getHostAddress())) {
                    /* Workaround for what looks like a bug in HAProxy - health checks should
                     * generate a LOCAL command, but it appears they do actually use PROXY.
                     */
                    _isHealthCheck = true;
                } else {
                    _destinationAddress = new InetSocketAddress(InetAddresses.forString(destinationAddress),
                            proxyMessage.destinationPort());
                    _sourceAddress = new InetSocketAddress(InetAddresses.forString(sourceAddress),
                            proxyMessage.sourcePort());
                }
            }
            break;
        }
        ctx.fireChannelRead(msg);
    } else {
        ctx.fireChannelRead(msg);
    }
}