public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline channelPipeline = Channels.pipeline();

    SslHandler sslHandler = configureServerSSLOnDemand();
    if (sslHandler != null) {
      LOG.debug(
          "Server SSL handler configured and added as an interceptor against the ChannelPipeline");
      channelPipeline.addLast("ssl", sslHandler);
    }
    List<ChannelDownstreamHandler> encoders = consumer.getConfiguration().getEncoders();
    for (int x = 0; x < encoders.size(); x++) {
      channelPipeline.addLast("encoder-" + x, encoders.get(x));
    }

    List<ChannelUpstreamHandler> decoders = consumer.getConfiguration().getDecoders();
    for (int x = 0; x < decoders.size(); x++) {
      channelPipeline.addLast("decoder-" + x, decoders.get(x));
    }

    // our handler must be added last
    channelPipeline.addLast("handler", new ServerChannelHandler(consumer));

    return channelPipeline;
  }
  private SslHandler configureServerSSLOnDemand() throws Exception {
    if (!consumer.getConfiguration().isSsl()) {
      return null;
    }

    if (consumer.getConfiguration().getSslHandler() != null) {
      return consumer.getConfiguration().getSslHandler();
    } else {
      SSLEngineFactory sslEngineFactory =
          new SSLEngineFactory(
              consumer.getConfiguration().getKeyStoreFormat(),
              consumer.getConfiguration().getSecurityProvider(),
              consumer.getConfiguration().getKeyStoreFile(),
              consumer.getConfiguration().getTrustStoreFile(),
              consumer.getConfiguration().getPassphrase().toCharArray());
      SSLEngine sslEngine = sslEngineFactory.createServerSSLEngine();
      return new SslHandler(sslEngine);
    }
  }