当前位置: 首页>>代码示例>>Java>>正文


Java SslHandler类代码示例

本文整理汇总了Java中io.netty.handler.ssl.SslHandler的典型用法代码示例。如果您正苦于以下问题:Java SslHandler类的具体用法?Java SslHandler怎么用?Java SslHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SslHandler类属于io.netty.handler.ssl包,在下文中一共展示了SslHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initChannel

import io.netty.handler.ssl.SslHandler; //导入依赖的package包/类
@Override
protected void initChannel(Channel ch) throws Exception {
    // create a new pipeline
    ChannelPipeline pipeline = ch.pipeline();

    SslHandler sslHandler = configureServerSSLOnDemand();
    if (sslHandler != null) {
        LOG.debug("Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
        pipeline.addLast("ssl", sslHandler);
    }

    pipeline.addLast("decoder", new HttpRequestDecoder(409, configuration.getMaxHeaderSize(), 8192));
    pipeline.addLast("encoder", new HttpResponseEncoder());
    if (configuration.isChunked()) {
        pipeline.addLast("aggregator", new HttpObjectAggregator(configuration.getChunkedMaxContentLength()));
    }
    if (configuration.isCompression()) {
        pipeline.addLast("deflater", new HttpContentCompressor());
    }

    pipeline.addLast("handler", channelFactory.getChannelHandler());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:HttpServerSharedInitializerFactory.java

示例2: initChannel

import io.netty.handler.ssl.SslHandler; //导入依赖的package包/类
/**
 * Adds pipelines to channel.
 * 
 *  @param ch channel to be operated on
 */
protected void initChannel(SocketChannel ch) throws Exception {
  ChannelPipeline pipe = ch.pipeline();

  if (ssl) {
    // HTTPs connection
    SSLEngine sslEng = getSsl(null);
    sslEng.setUseClientMode(true);
    pipe.addLast("SSL", new SslHandler(sslEng, false));
  }

  pipe.addFirst("Timer", new ReadTimeoutHandler(30));
  pipe.addLast("Codec", new HttpClientCodec());
  pipe.addLast("Inflater", new HttpContentDecompressor());
  pipe.addLast("Handler", new HTTPMessageHandler(builder));
}
 
开发者ID:didclab,项目名称:onedatashare,代码行数:21,代码来源:HTTPInitializer.java

示例3: initChannel

import io.netty.handler.ssl.SslHandler; //导入依赖的package包/类
@Override
  public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();
    SslHandler sslHandler = null;
    if (sslHandlerProvider != null) {
      sslHandler = sslHandlerProvider.getSslHandler();
      pipeline.addLast(sslHandler);
    }
    pipeline.addLast("decoder", new MqttDecoder(MAX_PAYLOAD_SIZE));
    pipeline.addLast("encoder", MqttEncoder.INSTANCE);

    MqttTransportHandler handler = new MqttTransportHandler(msgProducer, deviceService, authService, assetService,
        assetAuthService, relationService, sslHandler);
    pipeline.addLast(handler);

//    ch.closeFuture().addListener(handler);

  }
 
开发者ID:osswangxining,项目名称:iothub,代码行数:19,代码来源:MqttTransportServerInitializer.java

示例4: initChannel

import io.netty.handler.ssl.SslHandler; //导入依赖的package包/类
@Override
	protected void initChannel(SocketChannel ch) throws Exception {
		ChannelPipeline p = ch.pipeline();
		if(sslCtx!=null)
		{
			p.addLast(new SslHandler(sslCtx.newEngine(ch.alloc())));
		}
		p.addLast(new HttpResponseEncoder());//必须放在最前面,如果decoder途中需要回复消息,则decoder前面需要encoder
		p.addLast(new HttpRequestDecoder());
		p.addLast(new HttpObjectAggregator(65536));//限制contentLength
		//大文件传输处理
//		p.addLast(new ChunkedWriteHandler());
//		p.addLast(new HttpContentCompressor());
		//跨域配置
		CorsConfig corsConfig = CorsConfigBuilder.forAnyOrigin().allowNullOrigin().allowCredentials().build();
		p.addLast(new CorsHandler(corsConfig));
		p.addLast(new DefaultListenerHandler<HttpRequest>(listener));
	}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:19,代码来源:HttpServerInitHandler.java

示例5: performTlsHandshake

import io.netty.handler.ssl.SslHandler; //导入依赖的package包/类
private CompletionStage<SmtpClientResponse> performTlsHandshake(SmtpClientResponse r) {
  CompletableFuture<SmtpClientResponse> ourFuture = new CompletableFuture<>();

  SslHandler sslHandler = new SslHandler(sslEngineSupplier.get());
  channel.pipeline().addFirst(sslHandler);

  sslHandler.handshakeFuture().addListener(nettyFuture -> {
    if (nettyFuture.isSuccess()) {
      ourFuture.complete(r);
    } else {
      ourFuture.completeExceptionally(nettyFuture.cause());
      close();
    }
  });

  return ourFuture;
}
 
开发者ID:HubSpot,项目名称:NioSmtpClient,代码行数:18,代码来源:SmtpSession.java

示例6: itReturnsTheStartTlsResponseIfTheTlsHandshakeSucceeds

import io.netty.handler.ssl.SslHandler; //导入依赖的package包/类
@Test
public void itReturnsTheStartTlsResponseIfTheTlsHandshakeSucceeds() throws Exception {
  CompletableFuture<SmtpClientResponse> f = session.startTls();
  responseFuture.complete(Lists.newArrayList(OK_RESPONSE));

  // respond to the ehlo sent after starttls
  secondResponseFuture.complete(Lists.newArrayList(new DefaultSmtpResponse(250,
      "smtp.example.com Hello client.example.com",
      "AUTH PLAIN LOGIN",
      "PIPELINING")));

  // the handshake succeeds
  SslHandler sslHandler = getSslHandler();
  ((DefaultPromise<Channel>) sslHandler.handshakeFuture()).setSuccess(channel);

  assertThat(f.isDone()).isTrue();
  assertThat(f.get().getResponses().get(0).code()).isEqualTo(OK_RESPONSE.code());

  // check EHLO is parsed again
  assertThat(session.getEhloResponse().isSupported(Extension.PIPELINING)).isTrue();
  assertThat(session.getEhloResponse().isSupported(Extension.STARTTLS)).isFalse();
}
 
开发者ID:HubSpot,项目名称:NioSmtpClient,代码行数:23,代码来源:SmtpSessionTest.java

示例7: getSslHandler

import io.netty.handler.ssl.SslHandler; //导入依赖的package包/类
private SslHandler getSslHandler() throws Exception {
  // get SslHandler if it was added to the pipeline
  ArgumentCaptor<ChannelHandler> captor = ArgumentCaptor.forClass(ChannelHandler.class);
  verify(pipeline).addFirst(captor.capture());
  SslHandler sslHandler = (SslHandler) captor.getValue();

  // mock and store the context so we can get the handshake future
  ChannelHandlerContext context = mock(ChannelHandlerContext.class);
  when(context.executor()).thenReturn(ImmediateEventExecutor.INSTANCE);
  when(context.channel()).thenReturn(mock(Channel.class, Answers.RETURNS_MOCKS.get()));

  // add the handler but prevent the handshake from running automatically
  when(channel.isActive()).thenReturn(false);
  sslHandler.handlerAdded(context);

  return sslHandler;
}
 
开发者ID:HubSpot,项目名称:NioSmtpClient,代码行数:18,代码来源:SmtpSessionTest.java

示例8: channelCreated

import io.netty.handler.ssl.SslHandler; //导入依赖的package包/类
@Override
public void channelCreated(Channel ch) throws Exception {
    ChannelPipeline p = ch.pipeline();

    if (sslContext != null) {
        SslHandler handler = sslContext.newHandler(ch.alloc());
        p.addLast(handler);
        handler.handshakeFuture().addListener(future -> {
            if (!future.isSuccess()) {
                log.error(() -> "SSL handshake failed.", future.cause());
            }
        });
    }

    p.addLast(new HttpClientCodec());
    p.addLast(handlers);
    // Disabling auto-read is needed for backpressure to work
    ch.config().setOption(ChannelOption.AUTO_READ, false);
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:20,代码来源:ChannelPipelineInitializer.java

示例9: initChannel_adds_sslCtx_handler_first_if_available_and_no_utility_handlers

import io.netty.handler.ssl.SslHandler; //导入依赖的package包/类
@Test
public void initChannel_adds_sslCtx_handler_first_if_available_and_no_utility_handlers() throws SSLException {
    // given
    SslContext sslCtx = new JdkSslClientContext();
    HttpChannelInitializer hci = basicHttpChannelInitializer(sslCtx, 0, 100, false, mock(RequestValidator.class),
                                                             createRequestAndResponseFilterMock());

    // when
    hci.initChannel(socketChannelMock);

    // then
    ArgumentCaptor<ChannelHandler> channelHandlerArgumentCaptor = ArgumentCaptor.forClass(ChannelHandler.class);
    verify(channelPipelineMock, atLeastOnce()).addLast(anyString(), channelHandlerArgumentCaptor.capture());
    List<ChannelHandler> handlers = channelHandlerArgumentCaptor.getAllValues();
    assertThat(handlers.get(0), instanceOf(SslHandler.class));
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:17,代码来源:HttpChannelInitializerTest.java

示例10: channelActive

import io.netty.handler.ssl.SslHandler; //导入依赖的package包/类
@Override
public void channelActive(final ChannelHandlerContext ctx) throws Exception {
    // Once session is secured, send a greeting and register the channel to
    // the global channel
    // list so the channel received the messages from others.
    ctx.pipeline().get(SslHandler.class).handshakeFuture()
            .addListener(new GenericFutureListener<Future<Channel>>() {
                @Override
                public void operationComplete(Future<Channel> future)
                        throws Exception {
                    ctx.writeAndFlush("Welcome to "
                            + InetAddress.getLocalHost().getHostName()
                            + " secure chat service!\n");
                    ctx.writeAndFlush("Your session is protected by "
                            + ctx.pipeline().get(SslHandler.class).engine()
                            .getSession().getCipherSuite()
                            + " cipher suite.\n");

                    channels.add(ctx.channel());
                }
            });
}
 
开发者ID:TFdream,项目名称:netty-tutorials,代码行数:23,代码来源:SecureChatServerHandler.java

示例11: addSslHandler

import io.netty.handler.ssl.SslHandler; //导入依赖的package包/类
public SslHandler addSslHandler(ChannelPipeline pipeline, Uri uri, String virtualHost) {
    String peerHost;
    int peerPort;

    if (virtualHost != null) {
        int i = virtualHost.indexOf(':');
        if (i == -1) {
            peerHost = virtualHost;
            peerPort = uri.getSchemeDefaultPort();
        } else {
            peerHost = virtualHost.substring(0, i);
            peerPort = Integer.valueOf(virtualHost.substring(i + 1));
        }

    } else {
        peerHost = uri.getHost();
        peerPort = uri.getExplicitPort();
    }

    SslHandler sslHandler = createSslHandler(peerHost, peerPort);
    pipeline.addFirst(ChannelManager.SSL_HANDLER, sslHandler);
    return sslHandler;
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:24,代码来源:ChannelManager.java

示例12: getSslHandler

import io.netty.handler.ssl.SslHandler; //导入依赖的package包/类
/**
 * Return a new eventual {@link SslHandler}, optionally with SNI activated
 *
 * @param allocator {@link ByteBufAllocator} to allocate for packet storage
 * @param sniInfo {@link Tuple2} with hostname and port for SNI (any null will skip SNI).
 * @return a new eventual {@link SslHandler} with SNI activated
 */
public final SslHandler getSslHandler(ByteBufAllocator allocator,
		Tuple2<String, Integer> sniInfo) {
	SslContext sslContext =
			this.sslContext == null ? defaultSslContext() : this.sslContext;

	if (sslContext == null) {
		return null;
	}

	Objects.requireNonNull(allocator, "allocator");
	SslHandler sslHandler;
	if (sniInfo != null && sniInfo.getT1() != null && sniInfo.getT2() != null) {
		sslHandler = sslContext.newHandler(allocator, sniInfo.getT1(), sniInfo.getT2());
	}
	else {
		sslHandler = sslContext.newHandler(allocator);
	}
	sslHandler.setHandshakeTimeoutMillis(sslHandshakeTimeoutMillis);
	sslHandler.setCloseNotifyFlushTimeoutMillis(sslCloseNotifyFlushTimeoutMillis);
	sslHandler.setCloseNotifyReadTimeoutMillis(sslCloseNotifyReadTimeoutMillis);
	return sslHandler;
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:30,代码来源:NettyOptions.java

示例13: initChannel

import io.netty.handler.ssl.SslHandler; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
  ChannelPipeline pipeline = ch.pipeline();

  SSLEngine engine = context.createSSLEngine();
  engine.setUseClientMode(true);
  SslHandler sslHandler = new SslHandler(engine);
  //pipeline.addLast(sslHandler);
  pipeline.addLast(new SimpleChannelInboundHandler<Object>() {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
      System.out.println(msg);
    }
  });
  //pipeline.addLast(new HttpRequestDecoder());
  //pipeline.addLast(new HttpResponseEncoder());
  //pipeline.addLast(new HttpContentCompressor());
  //pipeline.addLast(new HTTPClientHandler());
}
 
开发者ID:elastic,项目名称:tealess,代码行数:21,代码来源:HTTPSInitializer.java

示例14: channelActive

import io.netty.handler.ssl.SslHandler; //导入依赖的package包/类
@Override
public void channelActive(final ChannelHandlerContext ctx) {
    // Once session is secured, send a greeting and register the channel to the global channel
    // list so the channel received the messages from others.
    ctx.pipeline().get(SslHandler.class).handshakeFuture().addListener(
            new GenericFutureListener<Future<Channel>>() {
                @Override
                public void operationComplete(Future<Channel> future) throws Exception {
                    ctx.writeAndFlush(
                            "Welcome to " + InetAddress.getLocalHost().getHostName() + " secure chat service!\n");
                    ctx.writeAndFlush(
                            "Your session is protected by " +
                                    ctx.pipeline().get(SslHandler.class).engine().getSession().getCipherSuite() +
                                    " cipher suite.\n");

                    channels.add(ctx.channel());
                }
    });
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:20,代码来源:SecureChatServerHandler.java

示例15: channelRead0

import io.netty.handler.ssl.SslHandler; //导入依赖的package包/类
@Override
public void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
    RandomAccessFile raf = null;
    long length = -1;
    try {
        raf = new RandomAccessFile(msg, "r");
        length = raf.length();
    } catch (Exception e) {
        ctx.writeAndFlush("ERR: " + e.getClass().getSimpleName() + ": " + e.getMessage() + '\n');
        return;
    } finally {
        if (length < 0 && raf != null) {
            raf.close();
        }
    }

    ctx.write("OK: " + raf.length() + '\n');
    if (ctx.pipeline().get(SslHandler.class) == null) {
        // SSL not enabled - can use zero-copy file transfer.
        ctx.write(new DefaultFileRegion(raf.getChannel(), 0, length));
    } else {
        // SSL enabled - cannot use zero-copy file transfer.
        ctx.write(new ChunkedFile(raf));
    }
    ctx.writeAndFlush("\n");
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:27,代码来源:FileServerHandler.java


注:本文中的io.netty.handler.ssl.SslHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。