exchange.getUnitOfWork().beginTransactedBy(transactionKey); exchange.getUnitOfWork().endTransactedBy(transactionKey);
@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); } }
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() }); }
/** * 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); } }
UnitOfWork uow = exchange.getContext().getUnitOfWorkFactory().createUnitOfWork(exchange); RouteContext rc = new DefaultRouteContext(exchange.getContext()); uow.pushRouteContext(rc); exchange.setUnitOfWork(uow); uow.start(); exchange.getIn().setBody(message.getContent()); copyProperties(message.getContext(), exchange);
exchange.getUnitOfWork().addSynchronization(tidHandler);
/** * 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; }
/** * 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); } }
/** * 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().beginTransactedBy(transactionKey); } finally { exchange.getUnitOfWork().endTransactedBy(transactionKey);
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); } }
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();