use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project pravega by pravega.
the class ConnectionFactoryImplTest method setUp.
@Before
public void setUp() throws Exception {
// Configure SSL.
port = TestUtils.getAvailableListenPort();
if (ssl) {
try {
sslCtx = SslContextBuilder.forServer(new File(SecurityConfigDefaults.TLS_SERVER_CERT_PATH), new File(SecurityConfigDefaults.TLS_SERVER_PRIVATE_KEY_PATH)).build();
} catch (SSLException e) {
throw new RuntimeException(e);
}
} else {
sslCtx = null;
}
boolean nio = false;
try {
bossGroup = new EpollEventLoopGroup(1);
workerGroup = new EpollEventLoopGroup();
} catch (ExceptionInInitializerError | UnsatisfiedLinkError | NoClassDefFoundError e) {
nio = true;
bossGroup = new NioEventLoopGroup(1);
workerGroup = new NioEventLoopGroup();
}
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup).channel(nio ? NioServerSocketChannel.class : EpollServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
if (sslCtx != null) {
SslHandler handler = sslCtx.newHandler(ch.alloc());
SSLEngine sslEngine = handler.engine();
SSLParameters sslParameters = sslEngine.getSSLParameters();
sslParameters.setEndpointIdentificationAlgorithm("LDAPS");
sslEngine.setSSLParameters(sslParameters);
p.addLast(handler);
}
}
});
// Start the server.
serverChannel = b.bind("localhost", port).awaitUninterruptibly().channel();
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project openflowplugin by opendaylight.
the class SimpleClientInitializer method initChannel.
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
if (secured) {
SSLEngine engine = ClientSslContextFactory.getClientContext().createSSLEngine();
engine.setUseClientMode(true);
pipeline.addLast("ssl", new SslHandler(engine));
}
SimpleClientHandler simpleClientHandler = new SimpleClientHandler(isOnlineFuture, scenarioHandler);
simpleClientHandler.setScenario(scenarioHandler);
pipeline.addLast("framer", new SimpleClientFramer());
pipeline.addLast("handler", simpleClientHandler);
isOnlineFuture = null;
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project nuls by nuls-io.
the class NulsChannelInitializer method initChannel.
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
ChannelPipeline p = socketChannel.pipeline();
p.addLast("decoder", new LengthFieldBasedFrameDecoder(10 * 1024 * 1024, 0, 8, 0, 8));
p.addLast("encoder0", new LengthFieldPrepender(8, false));
p.addLast(t);
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project ballerina by ballerina-lang.
the class WebSocketClient method handhshake.
/**
* @return true if the handshake is done properly.
* @throws URISyntaxException throws if there is an error in the URI syntax.
* @throws InterruptedException throws if the connecting the server is interrupted.
*/
public boolean handhshake() throws InterruptedException, URISyntaxException, SSLException {
boolean isDone = false;
URI uri = new URI(url);
String scheme = uri.getScheme() == null ? "ws" : uri.getScheme();
final String host = uri.getHost() == null ? "127.0.0.1" : uri.getHost();
final int port;
if (uri.getPort() == -1) {
if ("ws".equalsIgnoreCase(scheme)) {
port = 80;
} else if ("wss".equalsIgnoreCase(scheme)) {
port = 443;
} else {
port = -1;
}
} else {
port = uri.getPort();
}
if (!"ws".equalsIgnoreCase(scheme) && !"wss".equalsIgnoreCase(scheme)) {
logger.error("Only WS(S) is supported.");
return false;
}
final boolean ssl = "wss".equalsIgnoreCase(scheme);
final SslContext sslCtx;
if (ssl) {
sslCtx = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
} else {
sslCtx = null;
}
group = new NioEventLoopGroup();
DefaultHttpHeaders httpHeaders = new DefaultHttpHeaders();
headers.entrySet().forEach(header -> {
httpHeaders.add(header.getKey(), header.getValue());
});
try {
// Connect with V13 (RFC 6455 aka HyBi-17). You can change it to V08 or V00.
// If you change it to V00, ping is not supported and remember to change
// HttpResponseDecoder to WebSocketHttpResponseDecoder in the pipeline.
handler = new WebSocketClientHandler(WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, null, true, httpHeaders));
Bootstrap b = new Bootstrap();
b.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) {
ChannelPipeline p = ch.pipeline();
if (sslCtx != null) {
p.addLast(sslCtx.newHandler(ch.alloc(), host, port));
}
p.addLast(new HttpClientCodec(), new HttpObjectAggregator(8192), WebSocketClientCompressionHandler.INSTANCE, handler);
}
});
channel = b.connect(uri.getHost(), port).sync().channel();
isDone = handler.handshakeFuture().sync().isSuccess();
} catch (Exception e) {
logger.error("Handshake unsuccessful : " + e.getMessage(), e);
return false;
}
logger.info("WebSocket Handshake successful : " + isDone);
return isDone;
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project ballerina by ballerina-lang.
the class WebSocketRemoteServerInitializer method initChannel.
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
if (sslCtx != null) {
pipeline.addLast(sslCtx.newHandler(ch.alloc()));
}
pipeline.addLast(new HttpServerCodec());
pipeline.addLast(new HttpObjectAggregator(65536));
pipeline.addLast(new WebSocketServerCompressionHandler());
pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));
WebSocketRemoteServerFrameHandler frameHandler = new WebSocketRemoteServerFrameHandler();
FRAME_HANDLERS.add(frameHandler);
pipeline.addLast(frameHandler);
}
Aggregations