/**
   * 채널 파이프라인 설정. Netty.Server.Configuration.NettyServerConfiguration 에서 등록한 Bean 을 이용해 사용자의 통신을 처리할
   * Handler 도 등록. Netty.Server.Handler.JsonHandler 에서 실제 사용자 요청 처리.
   *
   * @param channel
   * @throws Exception
   */
  @Override
  protected void initChannel(Channel channel) throws Exception {

    ChannelPipeline channelPipeline = channel.pipeline();

    switch (transferType) {
      case "websocket":
        channelPipeline
            .addLast(new HttpServerCodec())
            .addLast(new HttpObjectAggregator(65536))
            .addLast(new WebSocketServerCompressionHandler())
            .addLast(
                new WebSocketServerProtocolHandler(
                    transferWebsocketPath,
                    transferWebsocketSubProtocol,
                    transferWebsocketAllowExtensions))
            .addLast(new LoggingHandler(LogLevel.valueOf(logLevelPipeline)))
            .addLast(websocketHandler);

      case "tcp":
      default:
        channelPipeline
            .addLast(new LineBasedFrameDecoder(Integer.MAX_VALUE))
            .addLast(STRING_DECODER)
            .addLast(STRING_ENCODER)
            .addLast(new LoggingHandler(LogLevel.valueOf(logLevelPipeline)))
            .addLast(jsonHandler);
    }
  }
 @Override
 public void initChannel(SocketChannel ch) throws Exception {
   ChannelPipeline p = ch.pipeline();
   p.addLast("encoder", new HttpResponseEncoder());
   p.addLast("decoder", new HttpRequestDecoder(4096, 8192, 8192, false));
   p.addLast("handler", new HelloServerHandler(service));
 }
Exemplo n.º 3
0
  /**
   * The lifecycle is as follow: first message ever received or transmitted is a handshake. It will
   * come from both side The handle must therefore be specialized.
   *
   * @param ch The socket chanel connected to the remote peer.
   * @throws Exception
   */
  @Override
  public void initChannel(final SocketChannel ch) throws Exception {

    ChannelPipeline pipeline = ch.pipeline();
    PeerWire peerWire = new PeerWire(ch);

    pipeline.addLast(
        "handshakeDecoder",
        new PwpHandshakeDecoder() {
          @Override
          public void channelActive(ChannelHandlerContext ctx) throws Exception {
            super.channelActive(ctx);

            // The new peerwire can only be sent to the rest of the application after the socket has
            // been connected
            // successfully
            eventBus.post(new NewPeerWireEvent(peerWire));
          }
        });

    pipeline.addLast(new ByteArrayDecoder());

    pipeline.addLast(new PwpChannelHandler(peerWire));
    pipeline.addLast(new ByteArrayEncoder());
  }
  @Override
  protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    ChannelPipeline p = ctx.pipeline();
    SocksProtocolVersion version = SocksProtocolVersion.valueOf(in.readByte());
    System.out.println(version);
    in.resetReaderIndex();
    switch (version) {
      case SOCKS4a:
        p.addLast(new Socks4CmdRequestDecoder());
        p.addLast(Socks4MessageEncoder.INSTANCE);

        break;
      case SOCKS5:
        p.addLast(new Socks5InitRequestDecoder());
        p.addLast(Socks5MessageEncoder.INSTANCE);

        break;
      case UNKNOWN:
        in.clear();
        ctx.close();
        return;
    }
    p.addLast(SocksServerHandler.INSTANCE);
    p.remove(this);
  }
 @Override
 public void initChannel(SocketChannel socketChannel) throws Exception {
   ChannelPipeline p = socketChannel.pipeline();
   p.addLast(new SocksInitRequestDecoder());
   p.addLast(socksMessageEncoder);
   p.addLast(socksServerHandler);
 }
 @Override
 protected void initChannel(SocketChannel ch) throws Exception {
   ChannelPipeline pipeline = ch.pipeline();
   pipeline.addLast("decoder", messageDecode);
   pipeline.addLast("handler", serverHandler);
   pipeline.addLast("encoder", messageEncode);
 }
Exemplo n.º 7
0
 @Override
 public void initChannel(SocketChannel ch) throws Exception {
   ChannelPipeline pipeline = ch.pipeline();
   pipeline.addLast("encoder", new HttpResponseEncoder());
   pipeline.addLast("decoder", new HttpRequestDecoder());
   pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
   pipeline.addLast("handler", new AutobahnServerHandler());
 }
 @Override
 public void initChannel(SocketChannel ch) {
   ChannelPipeline p = ch.pipeline();
   p.addLast(new HttpServerCodec());
   p.addLast(new HttpObjectAggregator(1048576));
   p.addLast(new GithubAuthHandler(githubService, appConfig));
   p.addLast(new DocProxyHandler(s3Service, appConfig));
 }
Exemplo n.º 9
0
    @Override
    public void initChannel(SocketChannel ch) throws Exception {
      ChannelPipeline pipeline = ch.pipeline();

      pipeline.addLast("http-codec", new HttpServerCodec());
      //            pipeline.addLast("log", new LoggingHandler(LogLevel.INFO));

      pipeline.addLast("handler", new RFRequestHandler());
    }
  @Override
  protected void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline p = ch.pipeline();

    // p.addLast(new LoggingHandler(LogLevel.INFO));
    p.addLast(new ObjectEncoder());
    p.addLast(new ObjectDecoder(ClassResolvers.cacheDisabled(null)));

    p.addLast(clientMtMapRequestAdapter);
  }
Exemplo n.º 11
0
 @Override
 public void initChannel(SocketChannel ch) {
   ChannelPipeline p = ch.pipeline();
   if (sslCtx != null) {
     p.addLast(sslCtx.newHandler(ch.alloc()));
   }
   p.addLast(new HttpClientCodec());
   p.addLast(new HttpContentDecompressor());
   p.addLast(handler);
 }
 @Override
 public void initChannel(SocketChannel ch) throws Exception {
   ChannelPipeline pipeline = ch.pipeline();
   if (sslCtx != null) {
     pipeline.addLast(sslCtx.newHandler(ch.alloc()));
   }
   pipeline.addLast(new HttpServerCodec());
   pipeline.addLast(new HttpObjectAggregator(65536));
   pipeline.addLast(new WebSocketServerHandler());
 }
Exemplo n.º 13
0
 protected void addHttpHandlers(ChannelHandlerContext var1) {
   ChannelPipeline var2 = var1.pipeline();
   var2.addLast((String) "httpRequestDecoder", (ChannelHandler) (new HttpRequestDecoder()));
   var2.addLast((String) "httpResponseEncoder", (ChannelHandler) (new HttpResponseEncoder()));
   var2.addLast(
       (String) "httpChunkAggregator",
       (ChannelHandler) (new HttpObjectAggregator(this.maxHttpContentLength)));
   var2.addLast(
       (String) "httpRequestHandler", (ChannelHandler) this.createHttpRequestHandlerForHttp());
 }
 @Override
 public ChannelPipeline getPipeline() throws Exception {
   // Create a default pipeline implementation.
   ChannelPipeline pipeline = pipeline();
   pipeline.addLast("decoder", new HttpRequestDecoder());
   pipeline.addLast("aggregator", new HttpChunkAggregator(65536));
   pipeline.addLast("encoder", new HttpResponseEncoder());
   pipeline.addLast("handler", new AutobahnServerHandler());
   return pipeline;
 }
Exemplo n.º 15
0
    @Override
    protected void initChannel(Channel ch) throws Exception {
      ChannelPipeline pipeline = ch.pipeline();

      pipeline.addLast(new ClientStateHandler(m_descriptor.getName()));

      for (Map.Entry<String, ChannelHandler> e : m_descriptor.getHandlers().entrySet()) {
        pipeline.addLast(e.getKey(), e.getValue());
      }
    }
Exemplo n.º 16
0
    @Override
    protected void initChannel(Channel channel) throws Exception {
      ChannelPipeline pipeline = channel.pipeline();

      int maxChunkSize = conf.getIntVar(TajoConf.ConfVars.SHUFFLE_FETCHER_CHUNK_MAX_SIZE);
      int readTimeout = conf.getIntVar(TajoConf.ConfVars.SHUFFLE_FETCHER_READ_TIMEOUT);

      pipeline.addLast("codec", new HttpClientCodec(4096, 8192, maxChunkSize));
      pipeline.addLast("inflater", new HttpContentDecompressor());
      pipeline.addLast("timeout", new ReadTimeoutHandler(readTimeout, TimeUnit.SECONDS));
      pipeline.addLast("handler", new HttpClientHandler(file));
    }
  @Override
  public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();

    // Add the text line codec combination first,
    pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
    pipeline.addLast(DECODER);
    pipeline.addLast(ENCODER);

    // and then business logic.
    pipeline.addLast(CLIENT_HANDLER);
  }
 protected void decode(ChannelHandlerContext context, ByteBuf buffer) throws Exception {
   ChannelPipeline pipeline = context.pipeline();
   if (detectSsl && SslHandler.isEncrypted(buffer)) {
     SSLEngine engine = SSL_SERVER_CONTEXT.getValue().createSSLEngine();
     engine.setUseClientMode(false);
     pipeline.addLast(
         new SslHandler(engine),
         new ChunkedWriteHandler(),
         new PortUnificationServerHandler(delegatingHttpRequestHandler, false, detectGzip));
   } else {
     int magic1 = buffer.getUnsignedByte(buffer.readerIndex());
     int magic2 = buffer.getUnsignedByte(buffer.readerIndex() + 1);
     if (detectGzip && magic1 == 31 && magic2 == 139) {
       pipeline.addLast(
           new JZlibEncoder(ZlibWrapper.GZIP),
           new JdkZlibDecoder(ZlibWrapper.GZIP),
           new PortUnificationServerHandler(delegatingHttpRequestHandler, detectSsl, false));
     } else if (isHttp(magic1, magic2)) {
       NettyUtil.initHttpHandlers(pipeline);
       pipeline.addLast(delegatingHttpRequestHandler);
       if (BuiltInServer.LOG.isDebugEnabled()) {
         pipeline.addLast(
             new ChannelOutboundHandlerAdapter() {
               @Override
               public void write(
                   ChannelHandlerContext context, Object message, ChannelPromise promise)
                   throws Exception {
                 if (message instanceof HttpResponse) {
                   //                BuiltInServer.LOG.debug("OUT HTTP:\n" + message);
                   HttpResponse response = (HttpResponse) message;
                   BuiltInServer.LOG.debug(
                       "OUT HTTP: "
                           + response.getStatus().code()
                           + " "
                           + response.headers().get("Content-type"));
                 }
                 super.write(context, message, promise);
               }
             });
       }
     } else if (magic1 == 'C' && magic2 == 'H') {
       buffer.skipBytes(2);
       pipeline.addLast(new CustomHandlerDelegator());
     } else {
       BuiltInServer.LOG.warn("unknown request, first two bytes " + magic1 + " " + magic2);
       context.close();
     }
   }
   // must be after new channels handlers addition (netty bug?)
   ensureThatExceptionHandlerIsLast(pipeline);
   pipeline.remove(this);
   context.fireChannelRead(buffer);
 }
Exemplo n.º 19
0
  @Override
  public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    // Add the text line codec combination first,
    pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
    pipeline.addLast("decoder", DECODER);
    pipeline.addLast("encoder", ENCODER);

    // and then business logic.
    pipeline.addLast("handler", CLIENTHANDLER);
  }
  @Override
  public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline p = ch.pipeline();
    p.addLast("frameDecoder", new ProtobufVarint32FrameDecoder());
    p.addLast(
        "protobufDecoder",
        new ProtobufDecoder(NetworkMessage.PackageInformation.getDefaultInstance()));

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

    p.addLast("handler", new ClientHandler());
  }
Exemplo n.º 21
0
  @Override
  public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    // Add the text line codec combination first,
    pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
    // the encoder and decoder are static as these are sharable
    pipeline.addLast("decoder", DECODER);
    pipeline.addLast("encoder", ENCODER);
    nhs.server = new TelnetServer();
    nhs.server.server = nhs;
    // and then business logic.
    pipeline.addLast("handler", nhs.server);
  }
Exemplo n.º 22
0
  @Override
  protected void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    // 以("\n")为结尾分割的 解码器
    pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));

    // 字符串解码 和 编码
    pipeline.addLast("decoder", new StringDecoder());
    pipeline.addLast("encoder", new StringEncoder());

    // 自己的逻辑Handler
    pipeline.addLast("handler", new HelloServerHandler());
  }
  @Override
  protected void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();
    engine.setUseClientMode(false);

    pipeline.addLast("ssl", new SslHandler(engine));

    pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
    pipeline.addLast("decoder", new StringDecoder());
    pipeline.addLast("encoder", new StringEncoder());

    // and then business logic.
    pipeline.addLast("handler", new SecureChatServerHandler());
  }
  @Override
  public void initChannel(SocketChannel channel) throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = channel.pipeline();

    // Uncomment the following line if you want HTTPS
    // SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();
    // engine.setUseClientMode(false);
    // pipeline.addLast("ssl", new SslHandler(engine));

    pipeline.addLast("decoder", new HttpRequestDecoder());
    pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
    pipeline.addLast("encoder", new HttpResponseEncoder());
    pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
    pipeline.addLast("handler", new ServletNettyHandler(this.dispatcherServlet));
  }
  @Override
  public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    // Enable stream compression (you can remove these two if unnecessary)
    pipeline.addLast("deflater", new ZlibEncoder(ZlibWrapper.GZIP));
    pipeline.addLast("inflater", new ZlibDecoder(ZlibWrapper.GZIP));

    // Add the number codec first,
    pipeline.addLast("decoder", new BigIntegerDecoder());
    pipeline.addLast("encoder", new NumberEncoder());

    // and then business logic.
    // Please note we create a handler for every new channel
    // because it has stateful properties.
    pipeline.addLast("handler", new FactorialServerHandler());
  }
  @Override
  public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();

    if (sslCtx != null) {
      pipeline.addLast("ssl", sslCtx.newHandler(ch.alloc()));
    }

    pipeline.addLast("codec", new HttpClientCodec());

    // Remove the following line if you don't want automatic content decompression.
    pipeline.addLast("inflater", new HttpContentDecompressor());

    // to be used since huge file transfer
    pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());

    pipeline.addLast("handler", new HttpUploadClientHandler());
  }
  private static void ensureThatExceptionHandlerIsLast(ChannelPipeline pipeline) {
    ChannelInboundHandler exceptionHandler = ChannelExceptionHandler.getInstance();
    if (pipeline.last() != exceptionHandler || pipeline.context(exceptionHandler) == null) {
      return;
    }

    pipeline.remove(exceptionHandler);
    pipeline.addLast(exceptionHandler);
  }
Exemplo n.º 28
0
  @Override
  protected final void initChannel(SocketChannel socketChannel) {
    final Session session = this.sessionManager.getSession(socketChannel);

    ChannelPipeline pl = socketChannel.pipeline();

    pl.addLast("encryption", new NoopHandler());

    pl.addLast("frame_decoder", new FrameDecoder());
    pl.addLast("frame_encoder", new FrameEncoder());

    pl.addLast("decoder", new PacketDecoder());
    pl.addLast("encoder", new PacketEncoder(this.sessionManager, this.packetRegistry));

    pl.addLast(
        "handler",
        new PacketHandler(this.logger, session, this.packetRegistry, this.handlerRegistry));
  }
 public static void modifyPipeline() {
   ChannelPipeline pipeline = null;
   // Creates a FirstHandler instance
   FirstHandler firstHandler = new FirstHandler();
   // Adds this instance to the ChannelPipeline as “handler1”
   pipeline.addLast("handler1", firstHandler);
   // Adds an instance of a SecondHandler to the ChannelPipeline in the first slot,
   // as “handler2”. It will be placed before the existing “handler1”.
   pipeline.addFirst("handler2", new SecondHandler());
   // Adds a ThirdHandler instance to the ChannelPipeline in the last slot as “handler3”.
   pipeline.addLast("handler3", new ThirdHandler());
   // Removes “handler3” by name.
   pipeline.remove("handler3");
   // Removes the FirstHandler by reference (it’s unique, so its name is not needed).
   pipeline.remove(firstHandler);
   // Replaces the SecondHandler (“handler2”) with a FourthHandler: “handler4”.
   pipeline.replace("handler2", "handler4", new FourthHandler());
 }
  @Override
  protected void initChannel(SocketChannel ch) throws Exception {

    if (mservice.getConfiguration().getConnectTimeoutMillis() > 0) {
      ch.config().setConnectTimeoutMillis(mservice.getConfiguration().getConnectTimeoutMillis());
    }

    ChannelPipeline p = ch.pipeline();

    // decoder
    p.addLast("decoder", new KineticDecoder());
    // encoder
    p.addLast("encoder", new KineticEncoder());

    p.addLast("handler", new NioMessageServiceHandler(mservice));

    logger.info("nio channel initialized ...");
  }