コード例 #1
0
  @SuppressWarnings("unchecked")
  @Override
  public SMTPClientFuture<FutureResult<me.normanmaurer.niosmtp.transport.FutureResult.Void>>
      startTLS() {
    if (!isEncrypted()) {
      final SMTPClientFutureImpl<FutureResult<me.normanmaurer.niosmtp.transport.FutureResult.Void>>
          future =
              new SMTPClientFutureImpl<
                  FutureResult<me.normanmaurer.niosmtp.transport.FutureResult.Void>>(false);

      SslHandler sslHandler = new SslHandler(engine, false);
      channel.getPipeline().addFirst(SSL_HANDLER_KEY, sslHandler);
      sslHandler
          .handshake()
          .addListener(
              new ChannelFutureListener() {

                @Override
                public void operationComplete(ChannelFuture cfuture) throws Exception {
                  if (cfuture.isSuccess()) {
                    future.setResult(FutureResult.createVoid());
                  } else {
                    future.setResult(FutureResult.create(cfuture.getCause()));
                  }
                }
              });

      return future;
    } else {
      return new ReadySMTPClientFuture<
          FutureResult<me.normanmaurer.niosmtp.transport.FutureResult.Void>>(
          this, FutureResult.create(STARTTLS_EXCEPTION));
    }
  }
コード例 #2
0
 @SuppressWarnings("unchecked")
 @Override
 public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
   ctx.getPipeline().remove(this);
   future.setResult(FutureResult.create(e.getCause()));
 }
コード例 #3
0
 @Override
 public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
   closeFuture.setResult(FutureResult.createVoid());
   super.channelClosed(ctx, e);
 }