akka.camel
Class CamelMessage

java.lang.Object
  extended by akka.camel.CamelMessage
All Implemented Interfaces:
java.io.Serializable, scala.Equals, scala.Product

public class CamelMessage
extends java.lang.Object
implements scala.Product, scala.Serializable

An immutable representation of a Camel message.

See Also:
Serialized Form

Constructor Summary
CamelMessage(java.lang.Object body, scala.collection.immutable.Map<java.lang.String,java.lang.Object> headers)
           
CamelMessage(java.lang.Object body, java.util.Map<java.lang.String,java.lang.Object> headers)
           
 
Method Summary
 java.lang.Object body()
           
<T> T
bodyAs(scala.reflect.ClassTag<T> t, org.apache.camel.CamelContext camelContext)
          Returns the body of the message converted to the type T.
static CamelMessage canonicalize(java.lang.Object msg)
          Creates a canonical form of the given message msg.
static void copyContent(CamelMessage from, org.apache.camel.Message to)
          INTERNAL API copies the content of this CamelMessage to an Apache Camel Message.
static CamelMessage from(org.apache.camel.Message camelMessage, scala.collection.immutable.Map<java.lang.String,java.lang.Object> headers)
          Creates a new CamelMessage object from the Camel message.
<T> T
getBodyAs(java.lang.Class<T> clazz, org.apache.camel.CamelContext camelContext)
          Java API: Returns the body of the message converted to the type as given by the clazz parameter.
<T> T
getHeaderAs(java.lang.String name, java.lang.Class<T> clazz, org.apache.camel.CamelContext camelContext)
          Java API: Returns the header by given name parameter.
 java.util.Map<java.lang.String,java.lang.Object> getHeaders()
          Java API: Returns all headers from this message.
 java.util.Map<java.lang.String,java.lang.Object> getHeaders(java.util.Set<java.lang.String> names)
          Java API: Returns those headers from this message whose name is contained in names.
<T> scala.util.Try<T>
headerAs(java.lang.String name, scala.reflect.ClassTag<T> t, org.apache.camel.CamelContext camelContext)
          Returns the header by given name parameter in a Try.
 scala.collection.immutable.Map<java.lang.String,java.lang.Object> headers()
           
 scala.collection.immutable.Map<java.lang.String,java.lang.Object> headers(scala.collection.immutable.Set<java.lang.String> names)
          Returns those headers from this message whose name is contained in names.
<A,B> CamelMessage
mapBody(scala.Function1<A,B> transformer)
          Returns a new CamelMessage with a transformed body using a transformer function.
<A,B> CamelMessage
mapBody(Mapper<A,B> transformer)
          Java API: Returns a new CamelMessage with a transformed body using a transformer function.
static java.lang.String MessageExchangeId()
          CamelMessage header to correlate request with response messages.
 void resetStreamCache()
          Reset StreamCache body.
 java.lang.String toString()
           
<T> CamelMessage
withBody(T body)
          Java API: Returns a new CamelMessage with a new body, while keeping the same headers.
<T> CamelMessage
withBodyAs(java.lang.Class<T> clazz, org.apache.camel.CamelContext camelContext)
          Java API: Creates a CamelMessage with current body converted to type clazz.
<T> CamelMessage
withBodyAs(scala.reflect.ClassTag<T> t, org.apache.camel.CamelContext camelContext)
          Creates a CamelMessage with current body converted to type T.
<A> CamelMessage
withHeaders(java.util.Map<java.lang.String,A> headers)
          Java API: Creates a new CamelMessage with given headers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface scala.Product
productArity, productElement, productIterator, productPrefix
 
Methods inherited from interface scala.Equals
canEqual, equals
 

Constructor Detail

CamelMessage

public CamelMessage(java.lang.Object body,
                    scala.collection.immutable.Map<java.lang.String,java.lang.Object> headers)

CamelMessage

public CamelMessage(java.lang.Object body,
                    java.util.Map<java.lang.String,java.lang.Object> headers)
Method Detail

MessageExchangeId

public static java.lang.String MessageExchangeId()
CamelMessage header to correlate request with response messages. Applications that send messages to a Producer actor may want to set this header on the request message so that it can be correlated with an asynchronous response. Messages send to Consumer actors have this header already set.

Returns:
(undocumented)

canonicalize

public static CamelMessage canonicalize(java.lang.Object msg)
Creates a canonical form of the given message msg. If msg of type CamelMessage then msg is returned, otherwise msg is set as body of a newly created CamelMessage object.

Parameters:
msg - (undocumented)
Returns:
(undocumented)

from

public static CamelMessage from(org.apache.camel.Message camelMessage,
                                scala.collection.immutable.Map<java.lang.String,java.lang.Object> headers)
Creates a new CamelMessage object from the Camel message.

Parameters:
headers - additional headers to set on the created CamelMessage in addition to those in the Camel message.
camelMessage - (undocumented)
Returns:
(undocumented)

copyContent

public static void copyContent(CamelMessage from,
                               org.apache.camel.Message to)
INTERNAL API copies the content of this CamelMessage to an Apache Camel Message.

Parameters:
from - (undocumented)
to - (undocumented)

body

public java.lang.Object body()

headers

public scala.collection.immutable.Map<java.lang.String,java.lang.Object> headers()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

headers

public scala.collection.immutable.Map<java.lang.String,java.lang.Object> headers(scala.collection.immutable.Set<java.lang.String> names)
Returns those headers from this message whose name is contained in names.

Parameters:
names - (undocumented)
Returns:
(undocumented)

getHeaders

public java.util.Map<java.lang.String,java.lang.Object> getHeaders(java.util.Set<java.lang.String> names)
Java API: Returns those headers from this message whose name is contained in names. The returned headers map is backed up by an immutable headers map. Any attempt to modify the returned map will throw an exception.

Parameters:
names - (undocumented)
Returns:
(undocumented)

getHeaders

public java.util.Map<java.lang.String,java.lang.Object> getHeaders()
Java API: Returns all headers from this message. The returned headers map is backed up by this message's immutable headers map. Any attempt to modify the returned map will throw an exception.

Returns:
(undocumented)

withHeaders

public <A> CamelMessage withHeaders(java.util.Map<java.lang.String,A> headers)
Java API: Creates a new CamelMessage with given headers. A copy of the headers map is made.

Parameters:
headers - (undocumented)
Returns:
(undocumented)

headerAs

public <T> scala.util.Try<T> headerAs(java.lang.String name,
                                      scala.reflect.ClassTag<T> t,
                                      org.apache.camel.CamelContext camelContext)
Returns the header by given name parameter in a Try. The header is converted to type T, which is returned in a Success. If an exception occurs during the conversion to the type T or when the header cannot be found, the exception is returned in a Failure.

The CamelContext is accessible in a UntypedConsumerActor and UntypedProducerActor using the getCamelContext method, and is available on the CamelExtension.

Parameters:
name - (undocumented)
t - (undocumented)
camelContext - (undocumented)
Returns:
(undocumented)

getHeaderAs

public <T> T getHeaderAs(java.lang.String name,
                         java.lang.Class<T> clazz,
                         org.apache.camel.CamelContext camelContext)
Java API: Returns the header by given name parameter. The header is converted to type T as defined by the clazz parameter. An exception is thrown when the conversion to the type T fails or when the header cannot be found.

The CamelContext is accessible in a UntypedConsumerActor and UntypedProducerActor using the getCamelContext method, and is available on the CamelExtension.

Parameters:
name - (undocumented)
clazz - (undocumented)
camelContext - (undocumented)
Returns:
(undocumented)

mapBody

public <A,B> CamelMessage mapBody(scala.Function1<A,B> transformer)
Returns a new CamelMessage with a transformed body using a transformer function. This method will throw a ClassCastException if the body cannot be mapped to type A.

Parameters:
transformer - (undocumented)
Returns:
(undocumented)

mapBody

public <A,B> CamelMessage mapBody(Mapper<A,B> transformer)
Java API: Returns a new CamelMessage with a transformed body using a transformer function. This method will throw a ClassCastException if the body cannot be mapped to type A.

Parameters:
transformer - (undocumented)
Returns:
(undocumented)

bodyAs

public <T> T bodyAs(scala.reflect.ClassTag<T> t,
                    org.apache.camel.CamelContext camelContext)
Returns the body of the message converted to the type T. Conversion is done using Camel's type converter. The type converter is obtained from the CamelContext that is passed in. The CamelContext is accessible in a UntypedConsumerActor and UntypedProducerActor using the getCamelContext method, and is available on the CamelExtension.

Parameters:
t - (undocumented)
camelContext - (undocumented)
Returns:
(undocumented)

getBodyAs

public <T> T getBodyAs(java.lang.Class<T> clazz,
                       org.apache.camel.CamelContext camelContext)
Java API: Returns the body of the message converted to the type as given by the clazz parameter. Conversion is done using Camel's type converter. The type converter is obtained from the CamelContext that is passed in.

The CamelContext is accessible in a UntypedConsumerActor and UntypedProducerActor using the getCamelContext method, and is available on the CamelExtension.

Parameters:
clazz - (undocumented)
camelContext - (undocumented)
Returns:
(undocumented)

resetStreamCache

public void resetStreamCache()
Reset StreamCache body. Nothing is done if the body is not a StreamCache. See http://camel.apache.org/stream-caching.html


withBody

public <T> CamelMessage withBody(T body)
Java API: Returns a new CamelMessage with a new body, while keeping the same headers.

Parameters:
body - (undocumented)
Returns:
(undocumented)

withBodyAs

public <T> CamelMessage withBodyAs(scala.reflect.ClassTag<T> t,
                                   org.apache.camel.CamelContext camelContext)
Creates a CamelMessage with current body converted to type T. The CamelContext is accessible in a UntypedConsumerActor and UntypedProducerActor using the getCamelContext method, and is available on the CamelExtension.

Parameters:
t - (undocumented)
camelContext - (undocumented)
Returns:
(undocumented)

withBodyAs

public <T> CamelMessage withBodyAs(java.lang.Class<T> clazz,
                                   org.apache.camel.CamelContext camelContext)
Java API: Creates a CamelMessage with current body converted to type clazz.

The CamelContext is accessible in a UntypedConsumerActor and UntypedProducerActor using the getCamelContext method, and is available on the CamelExtension.

Parameters:
clazz - (undocumented)
camelContext - (undocumented)
Returns:
(undocumented)