private SslHandler configureServerSSLOnDemand() throws Exception { if (!consumer.getConfiguration().isSsl()) { return null; } if (consumer.getConfiguration().getSslHandler() != null) { return consumer.getConfiguration().getSslHandler(); } else if (sslContext != null) { SSLEngine engine = sslContext.createSSLEngine(); engine.setUseClientMode(consumer.getConfiguration().isClientMode()); engine.setNeedClientAuth(consumer.getConfiguration().isNeedClientAuth()); if (consumer.getConfiguration().getSslContextParameters() == null) { // just set the enabledProtocols if the SslContextParameter doesn't set engine.setEnabledProtocols(consumer.getConfiguration().getEnabledProtocols().split(",")); } return new SslHandler(engine); } return null; }
public NettyConsumerExceptionHandler(NettyConsumer consumer) { this.logger = new CamelLogger(LOG, consumer.getConfiguration().getServerExceptionCaughtLogLevel()); this.closedLoggingLevel = consumer.getConfiguration().getServerClosedChannelExceptionCaughtLogLevel(); }
public ServerChannelHandler(NettyConsumer consumer) { this.consumer = consumer; this.noReplyLogger = new CamelLogger(LOG, consumer.getConfiguration().getNoReplyLogLevel()); }
public DefaultServerInitializerFactory(NettyConsumer consumer) { this.consumer = consumer; try { this.sslContext = createSSLContext(consumer.getContext(), consumer.getConfiguration()); } catch (Exception e) { throw ObjectHelper.wrapRuntimeCamelException(e); } if (sslContext != null) { LOG.info("Created SslContext {}", sslContext); } }
private void sendResponse(Object message, ChannelHandlerContext ctx, Exchange exchange) throws Exception { Object body = getResponseBody(exchange); if (body == null) { noReplyLogger.log("No payload to send as reply for exchange: " + exchange); if (consumer.getConfiguration().isDisconnectOnNoReply()) { // must close session if no data to write otherwise client will never receive a response // and wait forever (if not timing out) if (LOG.isTraceEnabled()) { LOG.trace("Closing channel as no payload to send as reply at address: {}", ctx.channel().remoteAddress()); } NettyHelper.close(ctx.channel()); } } else { // if textline enabled then covert to a String which must be used for textline if (consumer.getConfiguration().isTextline()) { body = NettyHelper.getTextlineBody(body, exchange, consumer.getConfiguration().getDelimiter(), consumer.getConfiguration().isAutoAppendDelimiter()); } // we got a body to write ChannelFutureListener listener = createResponseFutureListener(consumer, exchange, ctx.channel().remoteAddress()); if (consumer.getConfiguration().isTcp()) { NettyHelper.writeBodyAsync(LOG, ctx.channel(), null, body, exchange, listener); } else { NettyHelper.writeBodyAsync(LOG, ctx.channel(), exchange.getProperty(NettyConstants.NETTY_REMOTE_ADDRESS, SocketAddress.class), body, exchange, listener); } } }
boolean disconnect = consumer.getConfiguration().isDisconnect(); if (close != null) { disconnect = close;
@Override public void done(boolean doneSync) { // send back response if the communication is synchronous try { if (consumer.getConfiguration().isSync()) { sendResponse(message, ctx, exchange); } } catch (Throwable e) { consumer.getExceptionHandler().handleException(e); } finally { consumer.doneUoW(exchange); } } });
@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); } }
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 void processSynchronously(final Exchange exchange, final ChannelHandlerContext ctx, final Object message) { try { consumer.getProcessor().process(exchange); if (consumer.getConfiguration().isSync()) { sendResponse(message, ctx, exchange); } } catch (Throwable e) { consumer.getExceptionHandler().handleException(e); } finally { consumer.doneUoW(exchange); } }