/** * Gets the Camel {@link Message} to use as the message to be set on the current {@link Exchange} when * we have received a reply message. * <p/> * * @param exchange the current exchange * @param ctx the channel handler context * @param message the incoming event which has the response message from Netty. * @return the Camel {@link Message} to set on the current {@link Exchange} as the response message. * @throws Exception is thrown if error getting the response message */ protected Message getResponseMessage(Exchange exchange, ChannelHandlerContext ctx, Object message) throws Exception { Object body = message; if (LOG.isDebugEnabled()) { LOG.debug("Channel: {} received body: {}", ctx.channel(), body); } // if textline enabled then covert to a String which must be used for textline if (producer.getConfiguration().isTextline()) { body = producer.getContext().getTypeConverter().mandatoryConvertTo(String.class, exchange, message); } // set the result on either IN or OUT on the original exchange depending on its pattern if (ExchangeHelper.isOutCapable(exchange)) { NettyPayloadHelper.setOut(exchange, body); return exchange.getOut(); } else { NettyPayloadHelper.setIn(exchange, body); return exchange.getIn(); } }
/** * 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 Exchange createExchange(ChannelHandlerContext ctx, Object message) throws Exception { Exchange exchange = createExchange(); updateMessageHeader(exchange.getIn(), ctx); NettyPayloadHelper.setIn(exchange, message); return exchange; }
/** * Gets the object we want to use as the request object for sending to netty. * * @param exchange the exchange * @return the object to use as request * @throws Exception is thrown if error getting the request body */ protected Object getRequestBody(Exchange exchange) throws Exception { Object body = NettyPayloadHelper.getIn(getEndpoint(), exchange); if (body == null) { return null; } // if textline enabled then covert to a String which must be used for textline if (getConfiguration().isTextline()) { body = NettyHelper.getTextlineBody(body, exchange, getConfiguration().getDelimiter(), getConfiguration().isAutoAppendDelimiter()); } return body; }