當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。