@Metadata(description = "To configure security using SSLContextParameters", label = "security") public void setSslContextParameters(final SSLContextParameters sslContextParameters) { if (configuration == null) { configuration = new NettyConfiguration(); } configuration.setSslContextParameters(sslContextParameters); }
if (!configuration.isSync()) { try { boolean disconnect = getConfiguration().isDisconnect(); if (close != null) { disconnect = close; if (!configuration.isReuseChannel() && disconnect) { if (LOG.isTraceEnabled()) { LOG.trace("Closing channel when complete at address: {}", getEndpoint().getConfiguration().getAddress());
if (configuration.isNativeTransport()) { clientBootstrap.channel(EpollSocketChannel.class); } else { clientBootstrap.option(ChannelOption.SO_KEEPALIVE, configuration.isKeepAlive()); clientBootstrap.option(ChannelOption.TCP_NODELAY, configuration.isTcpNoDelay()); clientBootstrap.option(ChannelOption.SO_REUSEADDR, configuration.isReuseAddress()); clientBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, configuration.getConnectTimeout()); answer = clientBootstrap.connect(new InetSocketAddress(configuration.getHost(), configuration.getPort())); if (LOG.isDebugEnabled()) { LOG.debug("Created new TCP client bootstrap connecting to {}:{} with options: {}", new Object[]{configuration.getHost(), configuration.getPort(), clientBootstrap}); if (configuration.isNativeTransport()) { connectionlessClientBootstrap.channel(EpollDatagramChannel.class); } else { connectionlessClientBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, configuration.getConnectTimeout()); connectionlessClientBootstrap.option(ChannelOption.SO_BROADCAST, configuration.isBroadcast()); connectionlessClientBootstrap.option(ChannelOption.SO_SNDBUF, configuration.getSendBufferSize()); connectionlessClientBootstrap.option(ChannelOption.SO_RCVBUF, configuration.getReceiveBufferSize()); if (!configuration.isUdpConnectionlessSending()) { answer = connectionlessClientBootstrap.connect(new InetSocketAddress(configuration.getHost(), configuration.getPort())); } else { new Object[]{configuration.getHost(), configuration.getPort(), connectionlessClientBootstrap});
@Override protected void doStart() throws Exception { if (configuration == null) { configuration = new NettyConfiguration(); } //Only setup the executorService if it is needed if (configuration.isUsingExecutorService() && executorService == null) { executorService = createExecutorService(); } super.doStart(); }
if (configuration.getCorrelationManager() != null) { correlationManager = configuration.getCorrelationManager(); } else { correlationManager = new DefaultNettyCamelStateCorrelationManager(); if (configuration.getWorkerGroup() == null) { .withNativeTransport(configuration.isNativeTransport()) .withWorkerCount(configuration.getWorkerCount()) .withName("NettyClientTCPWorker").build(); if (configuration.isProducerPoolEnabled()) { config.maxActive = configuration.getProducerPoolMaxActive(); config.minIdle = configuration.getProducerPoolMinIdle(); config.maxIdle = configuration.getProducerPoolMaxIdle(); config.minEvictableIdleTimeMillis = configuration.getProducerPoolMinEvictableIdle(); config.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL; pool = new GenericObjectPool<>(new NettyProducerPoolableObjectFactory(), config); ClientInitializerFactory factory = configuration.getClientInitializerFactory(); if (factory != null) { pipelineFactory = factory.createPipelineFactory(this); if (configuration.getChannelGroup() == null) { allChannels = new DefaultChannelGroup("NettyProducer", ImmediateEventExecutor.INSTANCE); } else { allChannels = configuration.getChannelGroup();
setHost(uri.getHost()); if (uri.getPort() != -1) { setPort(uri.getPort()); addToHandlersList(encoders, referencedEncoders, ChannelHandler.class); List<ChannelHandler> referencedDecoders = component.resolveAndRemoveReferenceListParameter(parameters, "decoders", ChannelHandler.class, null); addToHandlersList(decoders, referencedDecoders, ChannelHandler.class); if (isAllowDefaultCodec()) { if ("udp".equalsIgnoreCase(protocol)) { encoders.add(ChannelHandlerFactories.newDatagramPacketEncoder()); 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(); new Object[]{charset, delimiter, decoderMaxLineLength}); } else if ("udp".equalsIgnoreCase(protocol) && isUdpByteArrayCodec()) { encoders.add(ChannelHandlerFactories.newByteArrayEncoder(protocol)); decoders.add(ChannelHandlerFactories.newByteArrayDecoder(protocol));
@Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { NettyConfiguration config; if (configuration != null) { config = configuration.copy(); } else { config = new NettyConfiguration(); } config = parseConfiguration(config, remaining, parameters); // merge any custom bootstrap configuration on the config NettyServerBootstrapConfiguration bootstrapConfiguration = resolveAndRemoveReferenceParameter(parameters, "bootstrapConfiguration", NettyServerBootstrapConfiguration.class); if (bootstrapConfiguration != null) { Map<String, Object> options = new HashMap<>(); if (IntrospectionSupport.getProperties(bootstrapConfiguration, options, null, false)) { IntrospectionSupport.setProperties(getCamelContext().getTypeConverter(), config, options); } } if (config.getSslContextParameters() == null) { config.setSslContextParameters(retrieveGlobalSslContextParameters()); } // validate config config.validateConfiguration(); NettyEndpoint nettyEndpoint = new NettyEndpoint(remaining, this, config); setProperties(nettyEndpoint.getConfiguration(), parameters); return nettyEndpoint; }
@Override protected void doStart() throws Exception { super.doStart(); LOG.debug("Netty consumer binding to: {}", configuration.getAddress()); if (nettyServerBootstrapFactory == null) { // setup pipeline factory ServerInitializerFactory pipelineFactory; ServerInitializerFactory factory = configuration.getServerInitializerFactory(); if (factory != null) { pipelineFactory = factory.createPipelineFactory(this); } else { pipelineFactory = new DefaultServerInitializerFactory(this); } if (isTcp()) { if (configuration.isClientMode()) { nettyServerBootstrapFactory = new ClientModeTCPNettyServerBootstrapFactory(); } else { nettyServerBootstrapFactory = new SingleTCPNettyServerBootstrapFactory(); } } else { nettyServerBootstrapFactory = new SingleUDPNettyServerBootstrapFactory(); } nettyServerBootstrapFactory.init(context, configuration, pipelineFactory); } ServiceHelper.startServices(nettyServerBootstrapFactory); LOG.info("Netty consumer bound to: {}", configuration.getAddress()); }
List<ChannelHandler> decoders = producer.getConfiguration().getDecoders(); for (int x = 0; x < decoders.size(); x++) { ChannelHandler decoder = decoders.get(x); List<ChannelHandler> encoders = producer.getConfiguration().getEncoders(); for (int x = 0; x < encoders.size(); x++) { ChannelHandler encoder = encoders.get(x); if (producer.getConfiguration().getRequestTimeout() > 0) { if (LOG.isTraceEnabled()) { LOG.trace("Using request timeout {} millis", producer.getConfiguration().getRequestTimeout()); ChannelHandler timeout = new ReadTimeoutHandler(producer.getConfiguration().getRequestTimeout(), TimeUnit.MILLISECONDS); addToPipeline("timeout", channelPipeline, timeout);
@Override protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { Object in = msg; if (LOG.isDebugEnabled()) { LOG.debug("Channel: {} received body: {}", ctx.channel(), in); } // create Exchange and let the consumer process it final Exchange exchange = consumer.getEndpoint().createExchange(ctx, msg); if (consumer.getConfiguration().isSync()) { exchange.setPattern(ExchangePattern.InOut); } // set the exchange charset property for converting if (consumer.getConfiguration().getCharsetName() != null) { exchange.setProperty(Exchange.CHARSET_NAME, IOHelper.normalizeCharset(consumer.getConfiguration().getCharsetName())); } if (consumer.getConfiguration().isReuseChannel()) { exchange.setProperty(NettyConstants.NETTY_CHANNEL, ctx.channel()); } // we want to handle the UoW consumer.createUoW(exchange); beforeProcess(exchange, ctx, msg); // process accordingly to endpoint configuration if (consumer.getEndpoint().isSynchronous()) { processSynchronously(exchange, ctx, msg); } else { processAsynchronously(exchange, ctx, msg); } }
if (configuration.isSync() && !doneUoW && !messageReceived && !exceptionHandled) { String address = configuration.getAddress(); if (LOG.isDebugEnabled()) { LOG.debug("Channel is inactive but no message received from address: {}", address); if (!configuration.isDisconnect()) { exchange.setException(new CamelExchangeException("No response received from remote server: " + address, exchange));
boolean disconnect = producer.getConfiguration().isDisconnect(); if (close != null) { disconnect = close; if (!producer.getConfiguration().isReuseChannel() && disconnect) { if (LOG.isTraceEnabled()) { LOG.trace("Closing channel when complete at address: {}", producer.getConfiguration().getAddress());
List<ChannelHandler> encoders = consumer.getConfiguration().getEncoders(); for (int x = 0; x < encoders.size(); x++) { ChannelHandler encoder = encoders.get(x); List<ChannelHandler> decoders = consumer.getConfiguration().getDecoders(); for (int x = 0; x < decoders.size(); x++) { ChannelHandler decoder = decoders.get(x); if (consumer.getConfiguration().isUsingExecutorService()) {
private boolean processWithBody(final Exchange exchange, Object body, BodyReleaseCallback callback) { if (getConfiguration().getCharsetName() != null) { exchange.setProperty(Exchange.CHARSET_NAME, IOHelper.normalizeCharset(getConfiguration().getCharsetName())); Channel channel = null; try { if (getConfiguration().isReuseChannel()) { channel = exchange.getProperty(NettyConstants.NETTY_CHANNEL, Channel.class);
@Override protected void doStop() throws Exception { LOG.debug("Netty consumer unbinding from: {}", configuration.getAddress()); ServiceHelper.stopService(nettyServerBootstrapFactory); LOG.info("Netty consumer unbound from: {}", configuration.getAddress()); super.doStop(); }
protected void notifyChannelOpen(ChannelFuture channelFuture) throws Exception { // blocking for channel to be done if (LOG.isTraceEnabled()) { LOG.trace("Channel open finished with {}", channelFuture); } if (channelFuture.isSuccess()) { Channel answer = channelFuture.channel(); // to keep track of all channels in use allChannels.add(answer); if (LOG.isDebugEnabled()) { LOG.debug("Creating connector to address: {}", configuration.getAddress()); } } }
@Override protected void doStop() throws Exception { LOG.debug("Stopping producer at address: {}", configuration.getAddress()); // close all channels LOG.trace("Closing {} channels", allChannels.size()); ChannelGroupFuture future = allChannels.close(); future.awaitUninterruptibly(); // and then shutdown the thread pools if (workerGroup != null) { workerGroup.shutdownGracefully(); workerGroup = null; } if (pool != null) { if (LOG.isDebugEnabled()) { LOG.debug("Stopping producer with channel pool[active={}, idle={}]", pool.getNumActive(), pool.getNumIdle()); } pool.close(); pool = null; } ServiceHelper.stopService(correlationManager); super.doStop(); }
@Override public void operationComplete(ChannelFuture future) { if (!future.isDone() || !future.isSuccess()) { ConnectException cause = new ConnectException("Cannot connect to " + configuration.getAddress()); if (future.cause() != null) { cause.initCause(future.cause()); } exchange.setException(cause); callback.done(false); releaseChannel(future); return; } try { processWithConnectedChannel(exchange, callback, future, body); } catch (Throwable e) { exchange.setException(e); callback.done(false); } } }