/** * Gets the object we want to use as the response object for sending to netty. * * @param exchange the exchange * @return the object to use as response * @throws Exception is thrown if error getting the response body */ protected Object getResponseBody(Exchange exchange) throws Exception { // if there was an exception then use that as response body boolean exception = exchange.getException() != null && !consumer.getEndpoint().getConfiguration().isTransferExchange(); if (exception) { return exchange.getException(); } if (exchange.hasOut()) { return NettyPayloadHelper.getOut(consumer.getEndpoint(), exchange); } else { return NettyPayloadHelper.getIn(consumer.getEndpoint(), exchange); } }
public NettyConsumer(NettyEndpoint nettyEndpoint, Processor processor, NettyConfiguration configuration) { super(nettyEndpoint, processor); this.context = this.getEndpoint().getCamelContext(); this.configuration = configuration; setNettyServerBootstrapFactory(configuration.getNettyServerBootstrapFactory()); setExceptionHandler(new NettyConsumerExceptionHandler(this)); }
@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); } }
EventExecutorGroup applicationExecutor = consumer.getEndpoint().getComponent().getExecutorService(); addToPipeline("handler", channelPipeline, applicationExecutor, new ServerChannelHandler(consumer));