org.apache.camel.util
Class MessageHelper

java.lang.Object
  extended by org.apache.camel.util.MessageHelper

public final class MessageHelper
extends Object

Some helper methods when working with Message.

Version:

Method Summary
static void copyHeaders(Message source, Message target, boolean override)
          Copies the headers from the source to the target message.
static String dumpAsXml(Message message)
          Dumps the message as a generic XML structure.
static String dumpAsXml(Message message, boolean includeBody)
          Dumps the message as a generic XML structure.
static String extractBodyAsString(Message message)
          Extracts the given body and returns it as a String, that can be used for logging etc.
static String extractBodyForLogging(Message message)
          Extracts the body for logging purpose.
static String extractBodyForLogging(Message message, String prepend)
          Extracts the body for logging purpose.
static String extractBodyForLogging(Message message, String prepend, boolean allowStreams, boolean allowFiles, int maxChars)
          Extracts the body for logging purpose.
static String getBodyTypeName(Message message)
          Gets the given body class type name as a String.
static String getContentEncoding(Message message)
          Returns the MIME content encoding on the message or null if none defined
static String getContentType(Message message)
          Returns the MIME content type on the message or null if none defined
static void resetStreamCache(Message message)
          If the message body contains a StreamCache instance, reset the cache to enable reading from it again.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

extractBodyAsString

public static String extractBodyAsString(Message message)
Extracts the given body and returns it as a String, that can be used for logging etc.

Will handle stream based bodies wrapped in StreamCache.

Parameters:
message - the message with the body
Returns:
the body as String, can return null if no body

getBodyTypeName

public static String getBodyTypeName(Message message)
Gets the given body class type name as a String.

Will skip java.lang. for the build in Java types.

Parameters:
message - the message with the body
Returns:
the body typename as String, can return null if no body

resetStreamCache

public static void resetStreamCache(Message message)
If the message body contains a StreamCache instance, reset the cache to enable reading from it again.

Parameters:
message - the message for which to reset the body

getContentType

public static String getContentType(Message message)
Returns the MIME content type on the message or null if none defined


getContentEncoding

public static String getContentEncoding(Message message)
Returns the MIME content encoding on the message or null if none defined


extractBodyForLogging

public static String extractBodyForLogging(Message message)
Extracts the body for logging purpose.

Will clip the body if its too big for logging. Will prepend the message with Message:

Parameters:
message - the message
Returns:
the logging message
See Also:
Exchange.LOG_DEBUG_BODY_STREAMS, Exchange.LOG_DEBUG_BODY_MAX_CHARS

extractBodyForLogging

public static String extractBodyForLogging(Message message,
                                           String prepend)
Extracts the body for logging purpose.

Will clip the body if its too big for logging.

Parameters:
message - the message
prepend - a message to prepend
Returns:
the logging message
See Also:
Exchange.LOG_DEBUG_BODY_STREAMS, Exchange.LOG_DEBUG_BODY_MAX_CHARS

extractBodyForLogging

public static String extractBodyForLogging(Message message,
                                           String prepend,
                                           boolean allowStreams,
                                           boolean allowFiles,
                                           int maxChars)
Extracts the body for logging purpose.

Will clip the body if its too big for logging.

Parameters:
message - the message
prepend - a message to prepend
allowStreams - whether or not streams is allowed
allowFiles - whether or not files is allowed
maxChars - limit to maximum number of chars. Use 0 or negative value to not limit at all.
Returns:
the logging message
See Also:
Exchange.LOG_DEBUG_BODY_MAX_CHARS

dumpAsXml

public static String dumpAsXml(Message message)
Dumps the message as a generic XML structure.

Parameters:
message - the message
Returns:
the XML

dumpAsXml

public static String dumpAsXml(Message message,
                               boolean includeBody)
Dumps the message as a generic XML structure.

Parameters:
message - the message
includeBody - whether or not to include the message body
Returns:
the XML

copyHeaders

public static void copyHeaders(Message source,
                               Message target,
                               boolean override)
Copies the headers from the source to the target message.

Parameters:
source - the source message
target - the target message
override - whether to override existing headers


Apache CAMEL