本文整理汇总了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());
}
示例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));
}
示例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);
}
示例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));
}
示例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;
}
示例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();
}
示例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;
}
示例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);
}
示例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));
}
示例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());
}
});
}
示例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;
}
示例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;
}
示例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());
}
示例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());
}
});
}
示例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");
}