Java Code Examples for org.jboss.netty.channel.ChannelPipeline.addFirst()

The following are Jave code examples for showing how to use addFirst() of the org.jboss.netty.channel.ChannelPipeline class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: flume-release-1.7.0   File: RpcTestUtils.java   Source Code and License Vote up 5 votes
@Override
public ChannelPipeline getPipeline() throws Exception {
  ChannelPipeline pipeline = Channels.pipeline();
  ZlibEncoder encoder = new ZlibEncoder(6);
  pipeline.addFirst("deflater", encoder);
  pipeline.addFirst("inflater", new ZlibDecoder());
  return pipeline;
}
 
Example 2
Project: flume-release-1.7.0   File: AvroSource.java   Source Code and License Vote up 5 votes
@Override
public ChannelPipeline getPipeline() throws Exception {
  ChannelPipeline pipeline = Channels.pipeline();
  if (enableCompression) {
    ZlibEncoder encoder = new ZlibEncoder(6);
    pipeline.addFirst("deflater", encoder);
    pipeline.addFirst("inflater", new ZlibDecoder());
  }

  if (enableSsl) {
    SSLEngine sslEngine = createServerSSLContext().createSSLEngine();
    sslEngine.setUseClientMode(false);
    List<String> enabledProtocols = new ArrayList<String>();
    for (String protocol : sslEngine.getEnabledProtocols()) {
      if (!excludeProtocols.contains(protocol)) {
        enabledProtocols.add(protocol);
      }
    }
    sslEngine.setEnabledProtocols(enabledProtocols.toArray(new String[0]));
    logger.info("SSLEngine protocols enabled: " +
        Arrays.asList(sslEngine.getEnabledProtocols()));
    // addFirst() will make SSL handling the first stage of decoding
    // and the last stage of encoding this must be added after
    // adding compression handling above
    pipeline.addFirst("ssl", new SslHandler(sslEngine));
  }

  if (enableIpFilter) {

    logger.info("Setting up ipFilter with the following rule definition: " +
                patternRuleConfigDefinition);
    IpFilterRuleHandler ipFilterHandler = new IpFilterRuleHandler();
    ipFilterHandler.addAll(rules);
    logger.info("Adding ipFilter with " + ipFilterHandler.size() + " rules");

    pipeline.addFirst("ipFilter", ipFilterHandler);
  }

  return pipeline;
}
 
Example 3
Project: flume-release-1.7.0   File: TestAvroSource.java   Source Code and License Vote up 5 votes
@Override
public SocketChannel newChannel(ChannelPipeline pipeline) {
  try {

    ZlibEncoder encoder = new ZlibEncoder(compressionLevel);
    pipeline.addFirst("deflater", encoder);
    pipeline.addFirst("inflater", new ZlibDecoder());
    return super.newChannel(pipeline);
  } catch (Exception ex) {
    throw new RuntimeException("Cannot create Compression channel", ex);
  }
}
 
Example 4
Project: flume-release-1.7.0   File: TestAvroSource.java   Source Code and License Vote up 5 votes
@Override
public SocketChannel newChannel(ChannelPipeline pipeline) {
  try {
    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(null, new TrustManager[]{new PermissiveTrustManager()},
                    null);
    SSLEngine sslEngine = sslContext.createSSLEngine();
    sslEngine.setUseClientMode(true);
    // addFirst() will make SSL handling the first stage of decoding
    // and the last stage of encoding
    pipeline.addFirst("ssl", new SslHandler(sslEngine));
    return super.newChannel(pipeline);
  } catch (Exception ex) {
    throw new RuntimeException("Cannot create SSL channel", ex);
  }
}
 
Example 5
Project: easyssl   File: SSLTransport.java   Source Code and License Vote up 5 votes
@Override
public ChannelPipeline getPipeline() throws Exception {
   	 ChannelPipeline pipeline = super.getPipeline();
   	 SslHandler handler = serverContext.newHandler();
   	 pipeline.addFirst("ssl handler", handler);
   	 return pipeline;
   }
 
Example 6
Project: flume-release-1.7.0   File: NettyAvroRpcClient.java   Source Code and License Vote up 4 votes
@Override
public SocketChannel newChannel(ChannelPipeline pipeline) {
  TrustManager[] managers;
  try {
    if (enableCompression) {
      ZlibEncoder encoder = new ZlibEncoder(compressionLevel);
      pipeline.addFirst("deflater", encoder);
      pipeline.addFirst("inflater", new ZlibDecoder());
    }
    if (enableSsl) {
      if (trustAllCerts) {
        logger.warn("No truststore configured, setting TrustManager to accept"
            + " all server certificates");
        managers = new TrustManager[] { new PermissiveTrustManager() };
      } else {
        KeyStore keystore = null;

        if (truststore != null) {
          if (truststorePassword == null) {
            throw new NullPointerException("truststore password is null");
          }
          InputStream truststoreStream = new FileInputStream(truststore);
          keystore = KeyStore.getInstance(truststoreType);
          keystore.load(truststoreStream, truststorePassword.toCharArray());
        }

        TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
        // null keystore is OK, with SunX509 it defaults to system CA Certs
        // see http://docs.oracle.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html#X509TrustManager
        tmf.init(keystore);
        managers = tmf.getTrustManagers();
      }

      SSLContext sslContext = SSLContext.getInstance("TLS");
      sslContext.init(null, managers, null);
      SSLEngine sslEngine = sslContext.createSSLEngine();
      sslEngine.setUseClientMode(true);
      List<String> enabledProtocols = new ArrayList<String>();
      for (String protocol : sslEngine.getEnabledProtocols()) {
        if (!excludeProtocols.contains(protocol)) {
          enabledProtocols.add(protocol);
        }
      }
      sslEngine.setEnabledProtocols(enabledProtocols.toArray(new String[0]));
      logger.info("SSLEngine protocols enabled: " +
          Arrays.asList(sslEngine.getEnabledProtocols()));
      // addFirst() will make SSL handling the first stage of decoding
      // and the last stage of encoding this must be added after
      // adding compression handling above
      pipeline.addFirst("ssl", new SslHandler(sslEngine));
    }

    return super.newChannel(pipeline);
  } catch (Exception ex) {
    logger.error("Cannot create SSL channel", ex);
    throw new RuntimeException("Cannot create SSL channel", ex);
  }
}
 
Example 7
Project: easyssl   File: HttpsServerTransport.java   Source Code and License Vote up 4 votes
@Override
public ChannelPipeline getPipeline() throws Exception {
   	ChannelPipeline pipeline = super.getPipeline();	 
       pipeline.addFirst("ssl.handler", serverContext.newHandler());
       return pipeline;
   }
 
Example 8
Project: easyssl   File: SSLTransport.java   Source Code and License Vote up 4 votes
@Override
public ChannelPipeline getPipeline() throws Exception {
   	ChannelPipeline pipeline = super.getPipeline();
   	pipeline.addFirst("ssl handler", clientContext.newHandler());
   	return pipeline;
   }