@Override public void process(Exchange exchange) throws Exception { // we have to run this synchronously as Spring Transaction does *not* support // using multiple threads to span a transaction if (transactionTemplate.getPropagationBehavior() != TransactionDefinition.PROPAGATION_REQUIRES_NEW && exchange.getUnitOfWork() != null && exchange.getUnitOfWork().isTransactedBy(transactionKey)) { // already transacted by this transaction template // so lets just let the error handler process it processByErrorHandler(exchange); } else { // not yet wrapped in transaction so lets do that // and then have it invoke the error handler from within that transaction processInTransaction(exchange); } }
if (exchange.getUnitOfWork() != null) { exchange.getUnitOfWork().beginTransactedBy(transactionKey); } finally { if (exchange.getUnitOfWork() != null) { exchange.getUnitOfWork().endTransactedBy(transactionKey);
.process(new Processor() { @Override public void process(Exchange exchange) throws Exception { Message originalMessage = (Message) exchange.getUnitOfWork().getOriginalInMessage(); (do something...) } })
/** * Ensures that an SAP stateful session for <code>destination</code> has begun * and is handled in the <code>exchange</code>. * * @param exchange * - the associated exchange. * @param destination * the associated destination. */ public static void ensureSapStatefulSessionHasBegunAndIsHandled(Exchange exchange, JCoDestination destination) { DestinationSapStatefulSessionHandler sessionHandler = new DestinationSapStatefulSessionHandler(destination); if (!exchange.getUnitOfWork().containsSynchronization(sessionHandler)) { // Begin SAP stateful session. sessionHandler.begin(); // Add transaction to UOW: SAP Transaction committed/rolledback // at end of exchange. exchange.getUnitOfWork().addSynchronization(sessionHandler); } }
/** * Ensures that an SAP transaction for <code>destination</code> has begun * and is handled in the <code>exchange</code>. * * @param exchange * - the associated exchange. * @param destination * the associated destination. */ public static void ensureSapTransactionHasBegunAndIsHandled(Exchange exchange, JCoDestination destination) { DestinationSapTransactionHandler transaction = new DestinationSapTransactionHandler(destination); if (!exchange.getUnitOfWork().containsSynchronization(transaction)) { // Begin SAP Transaction. transaction.begin(); // Add transaction to UOW: SAP Transaction committed/rolledback // at end of exchange. exchange.getUnitOfWork().addSynchronization(transaction); } }
public void process(Exchange exchange) throws Exception { // we have to run this synchronously as a JTA Transaction does *not* // support using multiple threads to span a transaction if (exchange.getUnitOfWork().isTransactedBy(transactionKey)) { // already transacted by this transaction template // so lets just let the error handler process it processByErrorHandler(exchange); } else { // not yet wrapped in transaction so lets do that // and then have it invoke the error handler from within that // transaction processInTransaction(exchange); } }
public static void closeCamelUnitOfWork(Message message) { Exchange cxfExchange = null; if ((cxfExchange = message.getExchange()) != null) { org.apache.camel.Exchange exchange = cxfExchange.get(org.apache.camel.Exchange.class); if (exchange != null) { UnitOfWorkHelper.doneUow(exchange.getUnitOfWork(), exchange); } } } }
private void logRouteStart(Exchange exchange) { //UnitOfWork -> getRouteContext -> Route -> Id. String routeId = exchange.getUnitOfWork().getRouteContext().getRoute().getId(); WonMessage message = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER); if (message == null){ logger.debug("starting route {}: [no WoNMessage]", routeId); return; } logger.debug("starting route {}: {} type:{}, dir:{}, resp:{}, rem: {}", new String[]{ routeId, message.getMessageURI().toString(), message.getMessageType().toString(), message.getEnvelopeType().toString(), message.getIsResponseToMessageURI() == null ? "[not a response]" : message.getIsResponseToMessageURI().toString(), message.getCorrespondingRemoteMessageURI() == null ? "[no remote message uri]" : message.getCorrespondingRemoteMessageURI().toString() }); }
/** * Find and configure an unmarshaller for the specified data format. */ private synchronized MarshalProcessor resolveMarshaller( Exchange exchange, String dataFormatId) throws Exception { if (marshaller == null) { DataFormat dataFormat = DataFormatDefinition.getDataFormat( exchange.getUnitOfWork().getRouteContext(), null, dataFormatId); if (dataFormat == null) { throw new Exception("Unable to resolve data format for marshalling: " + dataFormatId); } // Wrap the data format in a processor and start/configure it. // Stop/shutdown is handled when the corresponding methods are // called on this producer. marshaller = new MarshalProcessor(dataFormat); marshaller.setCamelContext(exchange.getContext()); marshaller.start(); } return marshaller; }
this.currentRouteId = (source.getUnitOfWork() == null || source.getUnitOfWork().getRouteContext() == null) ? null : source.getUnitOfWork().getRouteContext().getRoute().getId(); this.breadCrumbId = getBreadCrumbId(source); this.exception = source.getException() == null ? source.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class) : source.getException();
/** * Find and configure an unmarshaller for the specified data format. */ private synchronized UnmarshalProcessor resolveUnmarshaller( Exchange exchange, String dataFormatId) throws Exception { if (unmarshaller == null) { DataFormat dataFormat = DataFormatDefinition.getDataFormat( exchange.getUnitOfWork().getRouteContext(), null, dataFormatId); if (dataFormat == null) { throw new Exception("Unable to resolve data format for unmarshalling: " + dataFormatId); } // Wrap the data format in a processor and start/configure it. // Stop/shutdown is handled when the corresponding methods are // called on this producer. unmarshaller = new UnmarshalProcessor(dataFormat); unmarshaller.setCamelContext(exchange.getContext()); unmarshaller.start(); } return unmarshaller; }
exchange.getUnitOfWork().addSynchronization(tidHandler);
boolean doneUoW = exchange.getUnitOfWork() == null;
exchange.getUnitOfWork().beginTransactedBy(transactionKey); } finally { exchange.getUnitOfWork().endTransactedBy(transactionKey);
@Override public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { if (LOG.isTraceEnabled()) { LOG.trace("Channel closed: {}", ctx.getChannel()); } Exchange exchange = getExchange(ctx); AsyncCallback callback = getAsyncCallback(ctx); // remove state producer.removeState(ctx.getChannel()); // to keep track of open sockets producer.getAllChannels().remove(ctx.getChannel()); // this channel is maybe closing graceful and the exchange is already done // and if so we should not trigger an exception boolean doneUoW = exchange.getUnitOfWork() == null; if (producer.getConfiguration().isSync() && !doneUoW && !messageReceived && !exceptionHandled) { // To avoid call the callback.done twice exceptionHandled = true; // session was closed but no message received. This could be because the remote server had an internal error // and could not return a response. We should count down to stop waiting for a response if (LOG.isDebugEnabled()) { LOG.debug("Channel closed but no message received from address: {}", producer.getConfiguration().getAddress()); } exchange.setException(new CamelExchangeException("No response received from remote server: " + producer.getConfiguration().getAddress(), exchange)); // signal callback callback.done(false); } // make sure the event can be processed by other handlers super.channelClosed(ctx, e); }