Exemple #1
0
  @Override
  public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {

    // Make sure the handshake future is notified when a connection has
    // been closed during handshake.
    synchronized (handshakeLock) {
      if (handshaking) {
        handshakeFuture.setFailure(new ClosedChannelException());
      }
    }

    try {
      super.channelDisconnected(ctx, e);
    } finally {
      unwrap(ctx, e.getChannel(), ChannelBuffers.EMPTY_BUFFER, 0, 0);
      engine.closeOutbound();
      if (!sentCloseNotify.get() && handshaken) {
        try {
          engine.closeInbound();
        } catch (SSLException ex) {
          logger.debug("Failed to clean up SSLEngine.", ex);
        }
      }
    }
  }
  public void checkPipeline(String protocol, ChannelPipeline pipeline, ChannelBuffer buf)
      throws Exception {
    Object tmp = buf.duplicate();

    // Frame decoder
    FrameDecoder frameDecoder = (FrameDecoder) pipeline.get("frameDecoder");
    if (frameDecoder != null) {
      try {
        Method method =
            frameDecoder
                .getClass()
                .getDeclaredMethod(
                    "decode", ChannelHandlerContext.class, Channel.class, ChannelBuffer.class);
        method.setAccessible(true);
        tmp = method.invoke(frameDecoder, null, null, tmp);
      } catch (NoSuchMethodException error) {
        Method method =
            frameDecoder
                .getClass()
                .getSuperclass()
                .getDeclaredMethod(
                    "decode", ChannelHandlerContext.class, Channel.class, ChannelBuffer.class);
        method.setAccessible(true);
        tmp = method.invoke(frameDecoder, null, null, tmp);
      }
    }

    // String decoder
    if (pipeline.get("stringDecoder") != null) {
      StringDecoder stringDecoder = new StringDecoder();
      if (tmp != null) {
        try {
          Method method =
              stringDecoder
                  .getClass()
                  .getDeclaredMethod(
                      "decode", ChannelHandlerContext.class, Channel.class, Object.class);
          method.setAccessible(true);
          tmp = method.invoke(stringDecoder, null, null, tmp);
        } catch (NoSuchMethodException error) {
          Method method =
              stringDecoder
                  .getClass()
                  .getSuperclass()
                  .getDeclaredMethod(
                      "decode", ChannelHandlerContext.class, Channel.class, Object.class);
          method.setAccessible(true);
          tmp = method.invoke(stringDecoder, null, null, tmp);
        }
      }
    }

    // Protocol decoder
    BaseProtocolDecoder protocolDecoder = (BaseProtocolDecoder) pipeline.get("objectDecoder");
    if (tmp != null) {
      try {
        Method method =
            protocolDecoder
                .getClass()
                .getDeclaredMethod(
                    "decode",
                    ChannelHandlerContext.class,
                    Channel.class,
                    SocketAddress.class,
                    Object.class);
        method.setAccessible(true);
        tmp = method.invoke(protocolDecoder, null, null, null, tmp);
      } catch (NoSuchMethodException error) {
        Method method =
            protocolDecoder
                .getClass()
                .getSuperclass()
                .getDeclaredMethod(
                    "decode",
                    ChannelHandlerContext.class,
                    Channel.class,
                    SocketAddress.class,
                    Object.class);
        method.setAccessible(true);
        tmp = method.invoke(protocolDecoder, null, null, null, tmp);
      }
    }

    if (tmp != null) {
      Log.info("Protocol " + protocol + " possible match");
    } else if (showFailed) {
      Log.info("Protocol " + protocol + " no match");
    }
  }