Search in sources :

Example 31 with Channel

use of org.jboss.netty.channel.Channel in project storm by apache.

the class KerberosSaslClientHandler method channelConnected.

@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent event) {
    // register the newly established channel
    Channel channel = ctx.getChannel();
    client.channelConnected(channel);
    LOG.info("Connection established from {} to {}", channel.getLocalAddress(), channel.getRemoteAddress());
    try {
        KerberosSaslNettyClient saslNettyClient = KerberosSaslNettyClientState.getKerberosSaslNettyClient.get(channel);
        if (saslNettyClient == null) {
            LOG.debug("Creating saslNettyClient now for channel: {}", channel);
            saslNettyClient = new KerberosSaslNettyClient(storm_conf, jaas_section, host);
            KerberosSaslNettyClientState.getKerberosSaslNettyClient.set(channel, saslNettyClient);
        }
        LOG.debug("Going to initiate Kerberos negotiations.");
        byte[] initialChallenge = saslNettyClient.saslResponse(new SaslMessageToken(new byte[0]));
        LOG.debug("Sending initial challenge: {}", initialChallenge);
        channel.write(new SaslMessageToken(initialChallenge));
    } catch (Exception e) {
        LOG.error("Failed to authenticate with server due to error: ", e);
    }
    return;
}
Also used : Channel(org.jboss.netty.channel.Channel) IOException(java.io.IOException)

Example 32 with Channel

use of org.jboss.netty.channel.Channel in project zookeeper by apache.

the class NettyServerCnxnFactory method reconfigure.

public void reconfigure(InetSocketAddress addr) {
    Channel oldChannel = parentChannel;
    try {
        LOG.info("binding to port {}", addr);
        parentChannel = bootstrap.bind(addr);
        localAddress = addr;
    } catch (Exception e) {
        LOG.error("Error while reconfiguring", e);
    } finally {
        oldChannel.close();
    }
}
Also used : Channel(org.jboss.netty.channel.Channel) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) X509Exception(org.apache.zookeeper.common.X509Exception) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SSLContextException(org.apache.zookeeper.common.X509Exception.SSLContextException) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException)

Example 33 with Channel

use of org.jboss.netty.channel.Channel in project storm by apache.

the class SaslStormClientHandler method channelConnected.

@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent event) {
    // register the newly established channel
    Channel channel = ctx.getChannel();
    client.channelConnected(channel);
    try {
        SaslNettyClient saslNettyClient = SaslNettyClientState.getSaslNettyClient.get(channel);
        if (saslNettyClient == null) {
            LOG.debug("Creating saslNettyClient now " + "for channel: " + channel);
            saslNettyClient = new SaslNettyClient(name, token);
            SaslNettyClientState.getSaslNettyClient.set(channel, saslNettyClient);
        }
        LOG.debug("Sending SASL_TOKEN_MESSAGE_REQUEST");
        channel.write(ControlMessage.SASL_TOKEN_MESSAGE_REQUEST);
    } catch (Exception e) {
        LOG.error("Failed to authenticate with server " + "due to error: ", e);
    }
}
Also used : Channel(org.jboss.netty.channel.Channel) IOException(java.io.IOException)

Example 34 with Channel

use of org.jboss.netty.channel.Channel in project storm by apache.

the class SaslStormServerAuthorizeHandler method messageReceived.

@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
    Object msg = e.getMessage();
    if (msg == null)
        return;
    Channel channel = ctx.getChannel();
    LOG.debug("messageReceived: Checking whether the client is authorized to send messages to the server ");
    // Authorize: client is allowed to doRequest() if and only if the client
    // has successfully authenticated with this server.
    SaslNettyServer saslNettyServer = SaslNettyServerState.getSaslNettyServer.get(channel);
    if (saslNettyServer == null) {
        LOG.warn("messageReceived: This client is *NOT* authorized to perform " + "this action since there's no saslNettyServer to " + "authenticate the client: " + "refusing to perform requested action: " + msg);
        return;
    }
    if (!saslNettyServer.isComplete()) {
        LOG.warn("messageReceived: This client is *NOT* authorized to perform " + "this action because SASL authentication did not complete: " + "refusing to perform requested action: " + msg);
        // not authorized.
        return;
    }
    LOG.debug("messageReceived: authenticated client: " + saslNettyServer.getUserName() + " is authorized to do request " + "on server.");
    // We call fireMessageReceived since the client is allowed to perform
    // this request. The client's request will now proceed to the next
    // pipeline component.
    Channels.fireMessageReceived(ctx, msg);
}
Also used : Channel(org.jboss.netty.channel.Channel)

Example 35 with Channel

use of org.jboss.netty.channel.Channel in project storm by apache.

the class PacemakerClient method send.

public HBMessage send(HBMessage m) throws PacemakerConnectionException {
    LOG.debug("Sending message: {}", m.toString());
    try {
        int next = availableMessageSlots.take();
        synchronized (m) {
            m.set_message_id(next);
            messages[next] = m;
            LOG.debug("Put message in slot: {}", Integer.toString(next));
            do {
                waitUntilReady();
                Channel channel = channelRef.get();
                if (channel != null) {
                    channel.write(m);
                    m.wait(1000);
                }
            } while (messages[next] == m);
        }
        HBMessage ret = messages[next];
        if (ret == null) {
            // This can happen if we lost the connection and subsequently reconnected or timed out.
            send(m);
        }
        messages[next] = null;
        LOG.debug("Got Response: {}", ret);
        return ret;
    } catch (InterruptedException e) {
        LOG.error("PacemakerClient send interrupted: ", e);
        throw new RuntimeException(e);
    }
}
Also used : Channel(org.jboss.netty.channel.Channel) HBMessage(org.apache.storm.generated.HBMessage)

Aggregations

Channel (org.jboss.netty.channel.Channel)187 InetSocketAddress (java.net.InetSocketAddress)57 Test (org.junit.Test)52 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)40 DefaultHttpRequest (org.jboss.netty.handler.codec.http.DefaultHttpRequest)37 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)34 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)34 SocketAddress (java.net.SocketAddress)33 ChannelFuture (org.jboss.netty.channel.ChannelFuture)33 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)30 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)27 Test (org.testng.annotations.Test)23 ConditionCheck (com.linkedin.databus2.test.ConditionCheck)22 IOException (java.io.IOException)21 SimpleObjectCaptureHandler (com.linkedin.databus2.test.container.SimpleObjectCaptureHandler)19 Logger (org.apache.log4j.Logger)19 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)17 DefaultHttpChunk (org.jboss.netty.handler.codec.http.DefaultHttpChunk)16 HttpChunk (org.jboss.netty.handler.codec.http.HttpChunk)16 ArrayList (java.util.ArrayList)14