Class Exchanges


  • public class Exchanges
    extends Object
    Utility related to Camel Exchanges.
    Author:
    Martin Krasser
    • Constructor Summary

      Constructors 
      Constructor Description
      Exchanges()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void copyExchange​(org.apache.camel.Exchange source, org.apache.camel.Exchange target)
      Copies the source exchange to target exchange preserving the ExchangePattern of target.
      static void copyInput​(org.apache.camel.Exchange exchange)
      Copies the exchange's in-message to the out-message if the exchange pattern is ExchangePattern.InOut.
      static org.apache.camel.Exchange createExchange​(org.apache.camel.CamelContext context, org.apache.camel.ExchangePattern pattern)
      Creates a new Exchange instance using context.
      static org.apache.camel.Exchange createExchange​(org.apache.camel.Exchange source, org.apache.camel.ExchangePattern pattern)
      Creates a new Exchange instance from the given exchange.
      static Exception extractException​(org.apache.camel.Exchange exchange)
      Extracts the exception handled while processing the given exchange (if any), and marks the exchange as non-failed.
      static Exception extractException​(org.apache.camel.Exchange exchange, boolean cleanup)
      Extracts the exception handled while processing the given exchange (if any), and optionally marks the exchange as non-failed.
      static org.apache.camel.Message prepareResult​(org.apache.camel.Exchange exchange)
      Returns the message where to write results.
      static org.apache.camel.ProducerTemplate producerTemplate​(org.apache.camel.Exchange exchange)
      Creates a ProducerTemplate from the given Exchange
      static org.apache.camel.Message resultMessage​(org.apache.camel.Exchange exchange)
      Returns the message where to write results.
    • Constructor Detail

      • Exchanges

        public Exchanges()
    • Method Detail

      • producerTemplate

        public static org.apache.camel.ProducerTemplate producerTemplate​(org.apache.camel.Exchange exchange)
        Creates a ProducerTemplate from the given Exchange
        Parameters:
        exchange - message exchange.
        Returns:
        a producer template.
      • resultMessage

        public static org.apache.camel.Message resultMessage​(org.apache.camel.Exchange exchange)
        Returns the message where to write results.
        Parameters:
        exchange - message exchange.
        Returns:
        result message.
      • prepareResult

        public static org.apache.camel.Message prepareResult​(org.apache.camel.Exchange exchange)
        Returns the message where to write results. This method copies the in-message to the out-message if the exchange is out-capable.
        Parameters:
        exchange - message exchange.
        Returns:
        result message.
      • createExchange

        public static org.apache.camel.Exchange createExchange​(org.apache.camel.Exchange source,
                                                               org.apache.camel.ExchangePattern pattern)
        Creates a new Exchange instance from the given exchange. The resulting exchange's pattern is defined by pattern.
        Parameters:
        source - exchange to copy from.
        pattern - exchange pattern to set.
        Returns:
        created exchange.
      • createExchange

        public static org.apache.camel.Exchange createExchange​(org.apache.camel.CamelContext context,
                                                               org.apache.camel.ExchangePattern pattern)
        Creates a new Exchange instance using context. The resulting exchange's pattern is defined by pattern.
        Parameters:
        context - Camel context.
        pattern - exchange pattern.
        Returns:
        created exchange.
      • copyInput

        public static void copyInput​(org.apache.camel.Exchange exchange)
        Copies the exchange's in-message to the out-message if the exchange pattern is ExchangePattern.InOut.
        Parameters:
        exchange - message exchange.
      • copyExchange

        public static void copyExchange​(org.apache.camel.Exchange source,
                                        org.apache.camel.Exchange target)
        Copies the source exchange to target exchange preserving the ExchangePattern of target.
        Parameters:
        source - source exchange.
        target - target exchange.
        See Also:
        resultMessage(Exchange)
      • extractException

        public static Exception extractException​(org.apache.camel.Exchange exchange,
                                                 boolean cleanup)
        Extracts the exception handled while processing the given exchange (if any), and optionally marks the exchange as non-failed.
        Parameters:
        exchange - Camel exchange, should be not null.
        cleanup - true iff the information about the occurred exception should be removed from the given exchange.
        Returns:
        an Exception instance, or null when no exception was handled.
      • extractException

        public static Exception extractException​(org.apache.camel.Exchange exchange)
        Extracts the exception handled while processing the given exchange (if any), and marks the exchange as non-failed.

        This method corresponds to extractException(org.apache.camel.Exchange, boolean) with the second parameter set to true.

        Parameters:
        exchange - Camel exchange, should be not null.
        Returns:
        an Exception instance, or null when no exception was handled.