List of usage examples for io.netty.handler.ssl SslContext isClient
public abstract boolean isClient();
From source file:com.kixeye.kixmpp.client.KixmppClient.java
License:Apache License
/** * Creates a new {@link KixmppClient}./* ww w. j a v a 2 s . co m*/ * * @param eventLoopGroup * @param eventEngine * @param sslContext * @param type */ public KixmppClient(EventLoopGroup eventLoopGroup, KixmppEventEngine eventEngine, SslContext sslContext, Type type) { if (sslContext != null) { assert sslContext.isClient() : "The given SslContext must be a client context."; } if (eventLoopGroup == null) { if (OS.indexOf("nux") >= 0) { eventLoopGroup = new EpollEventLoopGroup(); } else { eventLoopGroup = new NioEventLoopGroup(); } } this.type = type; this.sslContext = sslContext; this.eventEngine = eventEngine; // set modules to be registered this.modulesToRegister.add(MucKixmppClientModule.class.getName()); this.modulesToRegister.add(PresenceKixmppClientModule.class.getName()); this.modulesToRegister.add(MessageKixmppClientModule.class.getName()); this.modulesToRegister.add(ErrorKixmppClientModule.class.getName()); if (eventLoopGroup instanceof EpollEventLoopGroup) { this.bootstrap = new Bootstrap().group(eventLoopGroup).channel(EpollSocketChannel.class) .option(ChannelOption.TCP_NODELAY, false).option(ChannelOption.SO_KEEPALIVE, true); } else { this.bootstrap = new Bootstrap().group(eventLoopGroup).channel(NioSocketChannel.class) .option(ChannelOption.TCP_NODELAY, false).option(ChannelOption.SO_KEEPALIVE, true); } switch (type) { case TCP: bootstrap.handler(new KixmppClientChannelInitializer()); break; case WEBSOCKET: bootstrap.handler(new KixmppClientWebSocketChannelInitializer()); break; } }
From source file:io.grpc.netty.NettyChannelBuilder.java
License:Apache License
/** * SSL/TLS context to use instead of the system default. It must have been configured with {@link * GrpcSslContexts}, but options could have been overridden. *//* w ww . j a v a2 s .co m*/ public NettyChannelBuilder sslContext(SslContext sslContext) { if (sslContext != null) { checkArgument(sslContext.isClient(), "Server SSL context can not be used for client channel"); GrpcSslContexts.ensureAlpnAndH2Enabled(sslContext.applicationProtocolNegotiator()); } this.sslContext = sslContext; return this; }
From source file:io.grpc.netty.NettyServerBuilderTest.java
License:Apache License
@Test public void failIfSslContextIsNotServer() { SslContext sslContext = mock(SslContext.class); when(sslContext.isClient()).thenReturn(true); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Client SSL context can not be used for server"); builder.sslContext(sslContext);//from w w w .j a v a 2 s . c o m }
From source file:io.hekate.network.netty.NettyClientFactory.java
License:Apache License
/** * Sets the SSL context that should be used to secure all network communications. * * <p>/*from w ww . j a va 2s . com*/ * This parameter is optional and if not specified then no encryption will be applied. * </p> * * <p> * <b>Note:</b> If SSL is configured for the client then it should be configured on the server side too (see {@link * NettyServerFactory#setSsl(SslContext)}). * </p> * * @param ssl SSL context. */ public void setSsl(SslContext ssl) { ArgAssert.check(ssl == null || ssl.isClient(), "SSL context must be configured in client mode."); this.ssl = ssl; }
From source file:io.hekate.network.netty.NettyClientFactoryTest.java
License:Apache License
@Test public void testSsl() { SslContext ctx = mock(SslContext.class); when(ctx.isClient()).thenReturn(true); assertNull(factory.getSsl());/*from www . j ava 2 s .c o m*/ factory.setSsl(ctx); assertSame(ctx, factory.getSsl()); factory.setSsl(null); assertNull(factory.getSsl()); assertSame(factory, factory.withSsl(ctx)); assertSame(ctx, factory.getSsl()); }
From source file:io.hekate.network.netty.NettyServerFactory.java
License:Apache License
/** * Sets the SSL context that should be used to secure all network communications. * * <p>/*from w w w .j a v a2s .c o m*/ * This parameter is optional and if not specified then no encryption will be applied. * </p> * * <p> * <b>Note:</b> If SSL is configured for the server then it should be configured on the client side too (see {@link * NettyClientFactory#setSsl(SslContext)}). * </p> * * @param ssl SSL context. */ public void setSsl(SslContext ssl) { ArgAssert.check(ssl == null || !ssl.isClient(), "SSL context must be configured in server mode."); this.ssl = ssl; }