use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler in project camel by apache.
the class HttpServerInitializerFactory method initChannel.
@Override
protected void initChannel(Channel ch) throws Exception {
// create a new pipeline
ChannelPipeline pipeline = ch.pipeline();
SslHandler sslHandler = configureServerSSLOnDemand();
if (sslHandler != null) {
//TODO must close on SSL exception
// sslHandler.setCloseOnSSLException(true);
LOG.debug("Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
pipeline.addLast("ssl", sslHandler);
}
pipeline.addLast("decoder", new HttpRequestDecoder(4096, configuration.getMaxHeaderSize(), 8192));
List<ChannelHandler> decoders = consumer.getConfiguration().getDecoders();
for (int x = 0; x < decoders.size(); x++) {
ChannelHandler decoder = decoders.get(x);
if (decoder instanceof ChannelHandlerFactory) {
// use the factory to create a new instance of the channel as it may not be shareable
decoder = ((ChannelHandlerFactory) decoder).newChannelHandler();
}
pipeline.addLast("decoder-" + x, decoder);
}
pipeline.addLast("encoder", new HttpResponseEncoder());
List<ChannelHandler> encoders = consumer.getConfiguration().getEncoders();
for (int x = 0; x < encoders.size(); x++) {
ChannelHandler encoder = encoders.get(x);
if (encoder instanceof ChannelHandlerFactory) {
// use the factory to create a new instance of the channel as it may not be shareable
encoder = ((ChannelHandlerFactory) encoder).newChannelHandler();
}
pipeline.addLast("encoder-" + x, encoder);
}
pipeline.addLast("aggregator", new HttpObjectAggregator(configuration.getChunkedMaxContentLength()));
if (supportCompressed()) {
pipeline.addLast("deflater", new HttpContentCompressor());
}
int port = consumer.getConfiguration().getPort();
ChannelHandler handler = consumer.getEndpoint().getComponent().getMultiplexChannelHandler(port).getChannelHandler();
if (consumer.getConfiguration().isUsingExecutorService()) {
EventExecutorGroup applicationExecutor = consumer.getEndpoint().getComponent().getExecutorService();
pipeline.addLast(applicationExecutor, "handler", handler);
} else {
pipeline.addLast("handler", handler);
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler in project camel by apache.
the class DefaultServerInitializerFactory method initChannel.
@Override
protected void initChannel(Channel ch) throws Exception {
// create a new pipeline
ChannelPipeline channelPipeline = ch.pipeline();
SslHandler sslHandler = configureServerSSLOnDemand();
if (sslHandler != null) {
//TODO must close on SSL exception
//sslHandler.setCloseOnSSLException(true);
LOG.debug("Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
addToPipeline("ssl", channelPipeline, sslHandler);
}
List<ChannelHandler> encoders = consumer.getConfiguration().getEncoders();
for (int x = 0; x < encoders.size(); x++) {
ChannelHandler encoder = encoders.get(x);
if (encoder instanceof ChannelHandlerFactory) {
// use the factory to create a new instance of the channel as it may not be shareable
encoder = ((ChannelHandlerFactory) encoder).newChannelHandler();
}
addToPipeline("encoder-" + x, channelPipeline, encoder);
}
List<ChannelHandler> decoders = consumer.getConfiguration().getDecoders();
for (int x = 0; x < decoders.size(); x++) {
ChannelHandler decoder = decoders.get(x);
if (decoder instanceof ChannelHandlerFactory) {
// use the factory to create a new instance of the channel as it may not be shareable
decoder = ((ChannelHandlerFactory) decoder).newChannelHandler();
}
addToPipeline("decoder-" + x, channelPipeline, decoder);
}
if (consumer.getConfiguration().isUsingExecutorService()) {
// Just use EventExecutorGroup from the Netty Component
EventExecutorGroup applicationExecutor = consumer.getEndpoint().getComponent().getExecutorService();
addToPipeline("handler", channelPipeline, applicationExecutor, new ServerChannelHandler(consumer));
} else {
// still use the worker event loop group here
addToPipeline("handler", channelPipeline, new ServerChannelHandler(consumer));
}
LOG.trace("Created ChannelPipeline: {}", channelPipeline);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler in project camel by apache.
the class NettyConfiguration method parseURI.
public void parseURI(URI uri, Map<String, Object> parameters, NettyComponent component, String... supportedProtocols) throws Exception {
protocol = uri.getScheme();
boolean found = false;
for (String supportedProtocol : supportedProtocols) {
if (protocol != null && protocol.equalsIgnoreCase(supportedProtocol)) {
found = true;
break;
}
}
if (!found) {
throw new IllegalArgumentException("Unrecognized Netty protocol: " + protocol + " for uri: " + uri);
}
setHost(uri.getHost());
if (uri.getPort() != -1) {
setPort(uri.getPort());
}
ssl = component.getAndRemoveOrResolveReferenceParameter(parameters, "ssl", boolean.class, false);
sslHandler = component.getAndRemoveOrResolveReferenceParameter(parameters, "sslHandler", SslHandler.class, sslHandler);
passphrase = component.getAndRemoveOrResolveReferenceParameter(parameters, "passphrase", String.class, passphrase);
keyStoreFormat = component.getAndRemoveOrResolveReferenceParameter(parameters, "keyStoreFormat", String.class, keyStoreFormat == null ? "JKS" : keyStoreFormat);
securityProvider = component.getAndRemoveOrResolveReferenceParameter(parameters, "securityProvider", String.class, securityProvider == null ? "SunX509" : securityProvider);
keyStoreFile = component.getAndRemoveOrResolveReferenceParameter(parameters, "keyStoreFile", File.class, keyStoreFile);
trustStoreFile = component.getAndRemoveOrResolveReferenceParameter(parameters, "trustStoreFile", File.class, trustStoreFile);
keyStoreResource = component.getAndRemoveOrResolveReferenceParameter(parameters, "keyStoreResource", String.class, keyStoreResource);
trustStoreResource = component.getAndRemoveOrResolveReferenceParameter(parameters, "trustStoreResource", String.class, trustStoreResource);
// clientPipelineFactory is @deprecated and to be removed
clientInitializerFactory = component.getAndRemoveOrResolveReferenceParameter(parameters, "clientPipelineFactory", ClientInitializerFactory.class, clientInitializerFactory);
clientInitializerFactory = component.getAndRemoveOrResolveReferenceParameter(parameters, "clientInitializerFactory", ClientInitializerFactory.class, clientInitializerFactory);
// serverPipelineFactory is @deprecated and to be removed
serverInitializerFactory = component.getAndRemoveOrResolveReferenceParameter(parameters, "serverPipelineFactory", ServerInitializerFactory.class, serverInitializerFactory);
serverInitializerFactory = component.getAndRemoveOrResolveReferenceParameter(parameters, "serverInitializerFactory", ServerInitializerFactory.class, serverInitializerFactory);
// set custom encoders and decoders first
List<ChannelHandler> referencedEncoders = component.resolveAndRemoveReferenceListParameter(parameters, "encoders", ChannelHandler.class, null);
addToHandlersList(encoders, referencedEncoders, ChannelHandler.class);
List<ChannelHandler> referencedDecoders = component.resolveAndRemoveReferenceListParameter(parameters, "decoders", ChannelHandler.class, null);
addToHandlersList(decoders, referencedDecoders, ChannelHandler.class);
// then set parameters with the help of the camel context type converters
EndpointHelper.setReferenceProperties(component.getCamelContext(), this, parameters);
EndpointHelper.setProperties(component.getCamelContext(), this, parameters);
// additional netty options, we don't want to store an empty map, so set it as null if empty
options = IntrospectionSupport.extractProperties(parameters, "option.");
if (options != null && options.isEmpty()) {
options = null;
}
// add default encoders and decoders
if (encoders.isEmpty() && decoders.isEmpty()) {
if (isAllowDefaultCodec()) {
if ("udp".equalsIgnoreCase(protocol)) {
encoders.add(ChannelHandlerFactories.newDatagramPacketEncoder());
}
// are we textline or object?
if (isTextline()) {
Charset charset = getEncoding() != null ? Charset.forName(getEncoding()) : CharsetUtil.UTF_8;
encoders.add(ChannelHandlerFactories.newStringEncoder(charset, protocol));
ByteBuf[] delimiters = delimiter == TextLineDelimiter.LINE ? Delimiters.lineDelimiter() : Delimiters.nulDelimiter();
decoders.add(ChannelHandlerFactories.newDelimiterBasedFrameDecoder(decoderMaxLineLength, delimiters, protocol));
decoders.add(ChannelHandlerFactories.newStringDecoder(charset, protocol));
if (LOG.isDebugEnabled()) {
LOG.debug("Using textline encoders and decoders with charset: {}, delimiter: {} and decoderMaxLineLength: {}", new Object[] { charset, delimiter, decoderMaxLineLength });
}
} else if ("udp".equalsIgnoreCase(protocol) && isUdpByteArrayCodec()) {
encoders.add(ChannelHandlerFactories.newByteArrayEncoder(protocol));
decoders.add(ChannelHandlerFactories.newByteArrayDecoder(protocol));
} else {
// object serializable is then used
encoders.add(ChannelHandlerFactories.newObjectEncoder(protocol));
decoders.add(ChannelHandlerFactories.newObjectDecoder(protocol));
LOG.debug("Using object encoders and decoders");
}
if ("udp".equalsIgnoreCase(protocol)) {
decoders.add(ChannelHandlerFactories.newDatagramPacketDecoder());
}
} else {
LOG.debug("No encoders and decoders will be used");
}
} else {
LOG.debug("Using configured encoders and/or decoders");
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler in project camel by apache.
the class NettyEndpoint method getSSLSession.
protected SSLSession getSSLSession(ChannelHandlerContext ctx) {
final SslHandler sslHandler = ctx.pipeline().get(SslHandler.class);
SSLSession sslSession = null;
if (sslHandler != null) {
sslSession = sslHandler.engine().getSession();
}
return sslSession;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler in project camel by apache.
the class LumberjackUtil method sendMessages.
static List<Integer> sendMessages(int port, SSLContextParameters sslContextParameters) throws InterruptedException {
NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup();
try {
// This list will hold the acknowledgment response sequence numbers
List<Integer> responses = new ArrayList<>();
// This initializer configures the SSL and an acknowledgment recorder
ChannelInitializer<Channel> initializer = new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
if (sslContextParameters != null) {
SSLEngine sslEngine = sslContextParameters.createSSLContext(null).createSSLEngine();
sslEngine.setUseClientMode(true);
pipeline.addLast(new SslHandler(sslEngine));
}
// Add the response recorder
pipeline.addLast(new SimpleChannelInboundHandler<ByteBuf>() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
assertEquals(msg.readUnsignedByte(), (short) '2');
assertEquals(msg.readUnsignedByte(), (short) 'A');
synchronized (responses) {
responses.add(msg.readInt());
}
}
});
}
};
// Connect to the server
Channel channel = //
new Bootstrap().group(//
eventLoopGroup).channel(//
NioSocketChannel.class).handler(//
initializer).connect("127.0.0.1", port).sync().channel();
// Send the 2 window frames
TimeUnit.MILLISECONDS.sleep(100);
channel.writeAndFlush(readSample("io/window10"));
TimeUnit.MILLISECONDS.sleep(100);
channel.writeAndFlush(readSample("io/window15"));
TimeUnit.MILLISECONDS.sleep(100);
channel.close();
synchronized (responses) {
return responses;
}
} finally {
eventLoopGroup.shutdownGracefully();
}
}
Aggregations