Beispiel #1
0
 private static FilteredPipeline findAccepting(final HttpRequest request) {
   final FilteredPipeline candidate = null;
   for (final FilteredPipeline f : pipelines) {
     if (f.checkAccepts(request)) {
       return f;
     }
   }
   if (request.getHeader(HttpHeaders.Names.HOST).contains("amazonaws.com")
       || request.getHeader(HttpHeaders.Names.HOST).contains(subDomain.get())) {
     String hostHeader = request.getHeader(HttpHeaders.Names.HOST);
     LOG.debug("Trying to intercept request for " + hostHeader);
     for (final FilteredPipeline f : pipelines) {
       if (Ats.from(f).has(ComponentPart.class)) {
         Class<? extends ComponentId> compIdClass = Ats.from(f).get(ComponentPart.class).value();
         ComponentId compId = ComponentIds.lookup(compIdClass);
         if (Ats.from(compIdClass).has(PublicService.class)) {
           if (request.getHeaderNames().contains("SOAPAction")
               && f.addHandlers(Channels.pipeline()).get(SoapHandler.class) == null) {
             continue; // Skip pipeline which doesn't handle SOAP for this SOAP request
           } else if (!request.getHeaderNames().contains("SOAPAction")
               && f.addHandlers(Channels.pipeline()).get(SoapHandler.class) != null) {
             continue; // Skip pipeline which handles SOAP for this non-SOAP request
           }
           LOG.debug("Maybe intercepting: " + hostHeader + " using " + f.getClass());
           if (Ats.from(compIdClass).has(AwsServiceName.class)
               && request
                   .getHeader(HttpHeaders.Names.HOST)
                   .matches(
                       "[\\w\\.-_]*" + compId.getAwsServiceName() + "\\.\\w+\\.amazonaws.com")) {
             return f; // Return pipeline which can handle the request for
                       // ${service}.${region}.amazonaws.com
           } else if (request
               .getHeader(HttpHeaders.Names.HOST)
               .matches("[\\w\\.-_]*" + compId.name() + "\\." + subDomain.get())) {
             return f; // Return pipeline which can handle the request for
                       // ${service}.${system.dns.dnsdomain}
           }
         }
       }
     }
   }
   if (candidate == null) {
     for (final FilteredPipeline f : internalPipelines) {
       if (f.checkAccepts(request)) {
         return f;
       }
     }
   }
   return candidate;
 }
    @Override
    public ChannelPipeline getPipeline() throws Exception {
      final ChannelPipeline p = Channels.pipeline();
      p.addLast("sm", ipcMessageHandler); // upstream 6

      return p;
    }
  public ChannelPipeline getPipeline() throws Exception {
    log.debug("Creating client channel pipeline");

    ChannelPipeline pipeline = Channels.pipeline();

    SSLEngine engine = sslContext.createSSLEngine();
    engine.setUseClientMode(true);

    SslHandler sslHandler = new SslHandler(engine);
    sslHandler.setCloseOnSSLException(true);
    pipeline.addLast("ssl", sslHandler);

    pipeline.addLast("chunker", new ChunkedWriteHandler());

    pipeline.addLast(
        "framer",
        new DelimiterBasedFrameDecoder(protocol.maxHeaderLength(), protocol.headerDelimiter()));
    pipeline.addLast("stringDecoder", new StringDecoder(protocol.headerCharset()));
    pipeline.addLast("stringEncoder", new StringEncoder(protocol.headerCharset()));

    HeaderCodec headerCodec = new HeaderCodec(protocol);
    pipeline.addLast("headerDecoder", headerCodec.decoder());
    pipeline.addLast("headerEncoder", headerCodec.encoder());

    pipeline.addLast("client", new ClientHandler(store));

    return pipeline;
  }
 @Override
 public ChannelPipeline getPipeline() throws Exception {
   final ChannelPipeline p = Channels.pipeline();
   p.addLast("frameDecoder", new ProtobufVarint32FrameDecoder()); // upstream 2
   p.addLast("frameEncoder", FRAME_ENCODER); // downstream 2
   p.addLast("ipcSessionManager", ipcSessionManager); // upstream 5
   return p;
 }
Beispiel #5
0
 public ChannelPipeline getPipeline() throws Exception {
   ChannelPipeline pipeline = Channels.pipeline();
   addLengthFieldPipes(pipeline);
   BlockingReadHandler<ChannelBuffer> reader =
       new BlockingReadHandler<ChannelBuffer>(new ArrayBlockingQueue<ChannelEvent>(3, false));
   pipeline.addLast("blockingHandler", reader);
   return pipeline;
 }
 public ChannelPipeline getPipeline() throws Exception {
   ChannelPipeline pipeline = Channels.pipeline();
   pipeline.addLast("encoder", new HttpResponseEncoder());
   pipeline.addLast("JsonConverter", new JsonEncoder());
   pipeline.addLast("executionHandler", executionHandler);
   pipeline.addLast("handler", new WeightedRandomNumberGenerator(connection));
   return pipeline;
 }
 /** {@inheritDoc} */
 @Override
 public ChannelPipeline getPipeline() throws Exception {
   ChannelPipeline pipleline = Channels.pipeline();
   pipleline.addLast("encode", new SocksMessageEncoder());
   pipleline.addLast("decode", new FixedLengthFrameDecoder(fixedLength));
   pipleline.addLast("handler", new NettyServerHandler());
   return pipleline;
 }
Beispiel #8
0
 @Override
 public ChannelPipeline getPipeline() throws Exception {
   ChannelPipeline pipeline = Channels.pipeline();
   pipeline.addLast("monitor", new MonitorChannelHandler(byteCounterMonitor));
   addLengthFieldPipes(pipeline, frameLength);
   pipeline.addLast("serverHandler", this);
   return pipeline;
 }
Beispiel #9
0
 @Override
 public ChannelPipeline getPipeline() throws Exception {
   ChannelPipeline pipeline = Channels.pipeline();
   pipeline.addLast("decoder", new HttpRequestDecoder());
   pipeline.addLast("encoder", new HttpResponseEncoder());
   pipeline.addLast("handler", handler);
   return pipeline;
 }
  @Override
  public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline pipeline = Channels.pipeline();

    pipeline.addLast("requestDecoder", REQUEST_DECODER);
    pipeline.addLast("handler", new RequestHandler());

    return pipeline;
  }
  @Override
  public ChannelPipeline getPipeline() throws Exception {

    final ChannelPipeline pipeline = Channels.pipeline();

    pipeline.addLast("logger", new LoggingHandler(false));

    pipeline.addLast("matrix", new MatrixSourceHandler(matrix));

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

    pipeline.addLast("decoder", new HttpRequestDecoder());
    pipeline.addLast("aggregator", new HttpChunkAggregator(1048576));
    pipeline.addLast("encoder", new HttpResponseEncoder());
    pipeline.addLast("deflater", new HttpContentCompressor());

    // logger.debug("[Factory] New pipeline created.");
    return pipeline;
  }
  @Override
  public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline p = Channels.pipeline();
    p.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(16 * 1024 * 1024, 0, 4, 0, 4));
    p.addLast("rpcDecoder", rpcDecoder);

    p.addLast("frameEncoder", frameEncoder);
    p.addLast("rpcEncoder", rpcEncoder);

    p.addLast("handler", new RpcMessageHandler(rpcPeer));
    return p;
  }
  /**
   * Decoding process will include the following handlers: - framedecoder - packetdecoder - handler
   *
   * <p>Encoding process: - packetencoder
   *
   * <p>Please note the sequence of handlers
   */
  @Override
  public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline pipeline = Channels.pipeline();

    pipeline.addLast("framedecoder", new PacketFrameDecoder());
    pipeline.addLast("packetdecoder", new LoginPacketDecoder());
    pipeline.addLast("packetencoder", new LoginPacketEncoder());
    pipeline.addLast("executor", new ExecutionHandler(pipelineExecutor));
    pipeline.addLast("handler", new ClientChannelHandler());

    return pipeline;
  }
  public ChannelPipeline getPipeline() throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = Channels.pipeline();

    // Decoder
    pipeline.addLast("decoder", new MessageDecoder());
    // Encoder
    pipeline.addLast("encoder", new MessageEncoder());
    // business logic.
    pipeline.addLast("handler", new StormClientHandler(client));

    return pipeline;
  }
  @Override
  public ChannelPipeline getPipeline() throws Exception {

    final ChannelPipeline pipeline = Channels.pipeline();

    pipeline.addLast("logger", new LoggingHandler(false));

    pipeline.addLast("silence-detect", new ReadTimeoutHandler(timer, 30));

    pipeline.addLast("auto-reconnect", new ReconnectHandler(timer));

    return pipeline;
  }
Beispiel #17
0
 @Override
 public ChannelPipeline getPipeline() throws Exception {
   ChannelPipeline pipeline = Channels.pipeline();
   pipeline.addLast("ssl", Handlers.newSslHandler());
   pipeline.addLast("decoder", Handlers.newHttpDecoder());
   pipeline.addLast("encoder", Handlers.newHttpResponseEncoder());
   pipeline.addLast("chunkedWriter", Handlers.newChunkedWriteHandler());
   pipeline.addLast("fence", Handlers.bootstrapFence());
   pipeline.addLast("pipeline-filter", Handlers.newNioServerHandler());
   if (StackConfiguration.ASYNC_PIPELINE) {
     pipeline.addLast("async-pipeline-execution-handler", Handlers.pipelineExecutionHandler());
   }
   return pipeline;
 }
 @Override
 public ChannelPipeline getPipeline() throws Exception {
   ChannelPipeline pipeline = Channels.pipeline();
   if (sslFactory != null) {
     pipeline.addLast("ssl", new SslHandler(sslFactory.createSSLEngine()));
   }
   pipeline.addLast("decoder", new HttpRequestDecoder());
   pipeline.addLast("aggregator", new HttpChunkAggregator(1 << 16));
   pipeline.addLast("encoder", new HttpResponseEncoder());
   pipeline.addLast("chunking", new ChunkedWriteHandler());
   pipeline.addLast("shuffle", PullServer);
   return pipeline;
   // TODO factor security manager into pipeline
   // TODO factor out encode/decode to permit binary shuffle
   // TODO factor out decode of index to permit alt. models
 }
  @Override
  public ChannelPipeline getPipeline() throws Exception {
    ChannelBuffer[] delimiter;

    if (config.getBoolean(SyslogTCPInput.CK_USE_NULL_DELIMITER)) {
      delimiter = Delimiters.nulDelimiter();
    } else {
      delimiter = Delimiters.lineDelimiter();
    }

    ChannelPipeline p = Channels.pipeline();
    p.addLast("connection-counter", connectionCounter);
    p.addLast("framer", new DelimiterBasedFrameDecoder(2 * 1024 * 1024, delimiter));
    p.addLast("traffic-counter", throughputCounter);
    p.addLast("handler", new SyslogDispatcher(server, config, sourceInput));
    return p;
  }
  @Override
  public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline p = Channels.pipeline();

    p.addLast("frameDecoder", new ProtobufVarint32FrameDecoder());
    p.addLast("protobufDecoder", new ProtobufDecoder(prototype));

    p.addLast("frameEncoder", new ProtobufVarint32LengthFieldPrepender());
    p.addLast("protobufEncoder", new ProtobufEncoder());

    SimpleNettyProtobufClientHandler<TSend, TReceive> handler =
        new SimpleNettyProtobufClientHandler<TSend, TReceive>(bootstrap, strategy.newInstance());
    client.setHandler(handler);

    p.addLast("handler", handler);
    return p;
  }
  @Override
  public ChannelPipeline getPipeline() throws Exception {

    ChannelPipeline pipeline = Channels.pipeline();
    pipeline.addLast("logger", new LoggingHandler(InternalLogLevel.DEBUG));
    pipeline.addLast(
        "decoder-frame",
        new DelimiterBasedFrameDecoder(
            RpcConstants.MAX_FRAME_LEN,
            ChannelBuffers.unmodifiableBuffer(
                ChannelBuffers.copiedBuffer(DELIM, RpcCodecUtils.DEF_CHARSET))));
    pipeline.addLast("decoder-response", new RpcResponseDecoder());
    pipeline.addLast("encoder", new RpcRequestEncoder());
    pipeline.addLast("handler", new RpcClientHandler());

    return pipeline;
  }
Beispiel #22
0
  public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline pipeline = Channels.pipeline();
    pipeline.addLast("decoder", new TSODecoder(null));
    pipeline.addLast("encoder", new TSOEncoder());
    synchronized (this) {
      if (x == null) x = new ExecutionHandler(pipelineExecutor);
      if (bwhandler == null) bwhandler = new BandwidthMeterHandler();
      //          if (timer == null)
      //             timer = new HashedWheelTimer();
    }
    pipeline.addLast("pipelineExecutor", x);
    //      pipeline.addLast("timeout", new WriteTimeoutHandler(timer, 10));
    pipeline.addFirst("bw", bwhandler);

    pipeline.addLast("handler", handler);
    return pipeline;
  }
  @Test
  public void testNettyConfigBuilder() {
    NettyConfigBuilder configBuilder = new NettyConfigBuilder();

    configBuilder.getServerSocketChannelConfig().setReceiveBufferSize(10000);
    configBuilder.getServerSocketChannelConfig().setBacklog(1000);
    configBuilder.getServerSocketChannelConfig().setReuseAddress(true);

    ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory());
    bootstrap.setOptions(configBuilder.getOptions());
    bootstrap.setPipelineFactory(Channels.pipelineFactory(Channels.pipeline()));
    Channel serverChannel = bootstrap.bind(new InetSocketAddress(port));

    Assert.assertEquals(
        ((ServerSocketChannelConfig) serverChannel.getConfig()).getReceiveBufferSize(), 10000);
    Assert.assertEquals(((ServerSocketChannelConfig) serverChannel.getConfig()).getBacklog(), 1000);
    Assert.assertTrue(((ServerSocketChannelConfig) serverChannel.getConfig()).isReuseAddress());
  }
 @Override
 public ChannelPipeline getPipeline() throws Exception {
   final ChannelPipeline pipeline = Channels.pipeline();
   for (Map.Entry<String, ChannelHandler> e :
       Handlers.channelMonitors(TimeUnit.SECONDS, StackConfiguration.CLIENT_INTERNAL_TIMEOUT_SECS)
           .entrySet()) { // TODO:GRZE: configurable
     pipeline.addLast(e.getKey(), e.getValue());
   }
   pipeline.addLast("decoder", Handlers.newHttpResponseDecoder());
   pipeline.addLast("aggregator", Handlers.newHttpChunkAggregator());
   pipeline.addLast("encoder", Handlers.httpRequestEncoder());
   pipeline.addLast("serializer", Handlers.soapMarshalling());
   pipeline.addLast("wssec", InternalClientPipeline.wssecHandler);
   pipeline.addLast("addressing", Handlers.addressingHandler());
   pipeline.addLast("soap", Handlers.soapHandler());
   pipeline.addLast("binding", Handlers.bindingHandler("msgs_eucalyptus_com"));
   return pipeline;
 }
  @Override
  public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline pipeline = Channels.pipeline();

    pipeline.addLast("debug-client-head", new DebugHandler("CLIENT_HEAD"));
    if (this.clientContext.isSecure()) {
      SSLEngine sslEngine = this.clientContext.getSSLContext().createSSLEngine();
      sslEngine.setUseClientMode(true);
      SslHandler sslHandler = new SslHandler(sslEngine);
      sslHandler.setEnableRenegotiation(false);
      sslHandler.setIssueHandshake(true);
      pipeline.addLast("ssl", sslHandler);
      pipeline.addLast("client-post-ssl", new DebugHandler("SERVER-POST-SSL"));
    }
    if (this.handshake != null) {
      pipeline.addLast("http-encoder", new HttpRequestEncoder());
      pipeline.addLast("http-decoder", new WebSocketHttpResponseDecoder(this.handshake));
      pipeline.addLast(
          "websocket-connection-negotiator",
          new WebSocketConnectionNegotiator(
              this.clientContext.getWebSocketAddress(), this.handshake));
      pipeline.addLast("stomp-frame-decoder", new WebSocketStompFrameDecoder());
      pipeline.addLast("stomp-frame-encoder", new WebSocketStompFrameEncoder());
    } else {
      pipeline.addLast("stomp-frame-decoder", new StompFrameDecoder());
      pipeline.addLast("stomp-frame-encoder", new StompFrameEncoder());
    }

    pipeline.addLast("debug-client-mid", new DebugHandler("CLIENT_MID"));

    pipeline.addLast(
        "stomp-connection-negotiator", new StompConnectionNegotiator(clientContext, "localhost"));
    pipeline.addLast("stomp-client-receipt", new ClientReceiptHandler(clientContext));

    pipeline.addLast("stomp-message-encoder", new StompMessageEncoder());
    pipeline.addLast(
        "stomp-message-decoder",
        new StompMessageDecoder(new ClientStompMessageFactory(this.client)));

    pipeline.addLast("stomp-client-message-handler", new ClientMessageHandler(clientContext));
    pipeline.addLast("debug-client-tail", new DebugHandler("CLIENT_TAIL"));

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

    // use DebugFrameDecoder to look at the raw message
    // pipeline.addLast("frameDecoder", new DebugFrameDecoder(67108864, 0,
    // 4,0, 4));

    pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(67108864, 0, 4, 0, 4));
    pipeline.addLast(
        "protobufDecoder", new ProtobufDecoder(eye.Comm.Management.getDefaultInstance()));
    pipeline.addLast("frameEncoder", new LengthFieldPrepender(4));
    pipeline.addLast("protobufEncoder", new ProtobufEncoder());

    // our message processor
    // pipeline.addLast("handler", new MonitorHandler());
    pipeline.addLast("handler", new MonitorHandler(this.monitoredSvrConf, svr));

    return pipeline;
  }
Beispiel #27
0
  private <In, Out> Channel listen(int port, NetworkEndpointFactory<In, Out> endpointFactory) {
    ServerBootstrap bootstrap = new ServerBootstrap(channelFactory);

    bootstrap.setPipelineFactory(
        () ->
            Channels.pipeline(
                new ObjectEncoder(),
                new ObjectDecoder(ClassResolvers.softCachingResolver(getClass().getClassLoader())),
                new LoggingHandler(NettyNetworkServer.class, logLevel),
                new NettyNetworkEndpointAdapter<>(endpointFactory.createEndpoint()),
                new AddToChannelGroupHandler(allChannels)));

    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("child.keepAlive", true);

    Channel channel = bootstrap.bind(new InetSocketAddress(port));
    allChannels.add(channel);
    return channel;
  }
Beispiel #28
0
  @Override
  public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline pipeline = Channels.pipeline();
    pipeline.addLast("decoder", new CodecDecoder());
    pipeline.addLast("encoder", new CodecEncoder());
    pipeline.addLast("handler", new ConnectionHandler());
    pipeline.addLast(
        "pipelineExecutor",
        new ExecutionHandler(
            new OrderedMemoryAwareThreadPoolExecutor(
                200,
                1048576,
                1073741824,
                100,
                TimeUnit.MILLISECONDS,
                Executors.defaultThreadFactory())));

    return pipeline;
  }
  @Override
  public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline pipeline = Channels.pipeline();

    pipeline.addLast("decoder", new HttpRequestDecoder());
    pipeline.addLast("encoder", new HttpResponseEncoder());
    pipeline.addLast("chunkWriter", new ChunkedWriteHandler());
    pipeline.addLast("inflater", new HttpContentDecompressor());
    pipeline.addLast("deflater", new HttpContentCompressor());

    if (executionHandler != null) {
      pipeline.addLast("executionHandler", executionHandler);
    }

    for (ChannelHandler handler : requestHandlers) {
      pipeline.addLast(handler.getClass().getSimpleName(), handler);
    }

    return pipeline;
  }
Beispiel #30
0
  private <K, V, T extends RedisAsyncConnection<K, V>> T connect(
      CommandHandler<K, V> handler, T connection) {
    try {
      ConnectionWatchdog watchdog = new ConnectionWatchdog(bootstrap, channels, timer);
      ChannelPipeline pipeline = Channels.pipeline(watchdog, handler, connection);
      Channel channel = bootstrap.getFactory().newChannel(pipeline);

      ChannelFuture future = channel.connect((SocketAddress) bootstrap.getOption("remoteAddress"));
      future.await();

      if (!future.isSuccess()) {
        throw future.getCause();
      }

      watchdog.setReconnect(true);

      return connection;
    } catch (Throwable e) {
      throw new RedisException("Unable to connect", e);
    }
  }