Class AdaptrisMessageImp
- java.lang.Object
-
- com.adaptris.core.AdaptrisMessageImp
-
- All Implemented Interfaces:
AdaptrisMessage
,InterlokMessage
,java.lang.Cloneable
- Direct Known Subclasses:
DefaultAdaptrisMessageImp
,MultiPayloadAdaptrisMessageImp
public abstract class AdaptrisMessageImp extends java.lang.Object implements AdaptrisMessage, java.lang.Cloneable
Standard implementation of
AdaptrisMessage
interface.When referring to metadata items by key you can use a form of indirection by specifying a prefix to your key ("$$").
Using this prefix on any metadata key will not perform an action (retrieve, add etc) to that metadata item but instead will look up the value of that metadata key and use the value as the metadata item key to be performed on.
Example:
Calling addMetadata("myKey", "myValue");
Will create a new metadata item with the key "myKey" and the value "myValue".
However calling addMetadata("$$myKey", "myValue") will lookup the value of the metadata key named "myKey" and use that value as the key for the addMetadata() method.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
METADATA_RESOLVE_REGEXP
static java.lang.String
OBJECT_RESOLVE_REGEXP
static java.lang.String
PAYLOAD_RESOLVE_KEY
static java.lang.String
SIZE_RESOLVE_KEY
static java.lang.String
UID_RESOLVE_KEY
-
Constructor Summary
Constructors Modifier Constructor Description protected
AdaptrisMessageImp(IdGenerator guid, AdaptrisMessageFactory fac)
Creates a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addEvent(MessageEventGenerator meg, boolean wasSuccessful)
Adds an event to thisAdaptrisMessage
'sMessageLifecycleEvent
.void
addMessageHeader(java.lang.String key, java.lang.String value)
void
addMetadata(MetadataElement e)
Puts the passedMetadataElement
into the metadata.void
addMetadata(java.lang.String key, java.lang.String value)
Puts the passedvalue
into the metadata against the passedkey
.void
addObjectHeader(java.lang.Object key, java.lang.Object object)
Adds anObject
to this message as metadata.void
clearMessageHeaders()
java.lang.Object
clone()
Returns a deep clone of this object.static void
copyPayload(AdaptrisMessage src, AdaptrisMessage dest)
Deprecated.since 3.11.0 use MessageHelper#copyPayload(AdaptrisMessage, AdaptrisMessage) instead.byte[]
encode(AdaptrisMessageEncoder encoder)
Uses the passedAdaptrisMessageEncoder
to create an encoded version of thisAdaptrisMessage
.java.lang.String
getContentEncoding()
AdaptrisMessageFactory
getFactory()
Return the factory that created this message.java.util.Map<java.lang.String,java.lang.String>
getMessageHeaders()
MessageLifecycleEvent
getMessageLifecycleEvent()
Returns this object'sMessageLifecycleEvent
.java.util.Set<MetadataElement>
getMetadata()
Returns a shallow clone of this message's metadata.MetadataElement
getMetadata(java.lang.String key)
Returns theMetadataElement
containing the passedkey
ornull
if thekey
does not exist.java.lang.String
getMetadataValue(java.lang.String key)
Returns theString
value associated with the passedkey
ornull
if thekey
does not exist.java.lang.String
getMetadataValueIgnoreKeyCase(java.lang.String key)
First looks for a metadata value stored against the passed key taking account of the passed key's case.java.lang.String
getNextServiceId()
Returns the unique ID of the nextService
to apply to the message.java.util.Map<java.lang.Object,java.lang.Object>
getObjectHeaders()
java.io.Reader
getReader()
java.lang.String
getUniqueId()
java.io.Writer
getWriter()
java.io.Writer
getWriter(java.lang.String encoding)
boolean
headersContainsKey(java.lang.String key)
void
removeMessageHeader(java.lang.String key)
void
removeMetadata(MetadataElement element)
Removes the passedMetadataElement
from the metadata if it is present.java.lang.String
resolve(java.lang.String s, boolean dotAll)
java.lang.Object
resolveObject(java.lang.String s)
Retrieve an object from headers/metadata using an expression: %messageObject{some_key}void
setContentEncoding(java.lang.String charEnc)
void
setMessageHeaders(java.util.Map<java.lang.String,java.lang.String> metadata)
void
setNextServiceId(java.lang.String s)
Sets the unique ID of the nextService
to apply to the message.void
setUniqueId(java.lang.String s)
java.lang.String
toString()
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.adaptris.core.AdaptrisMessage
addMetadata, addObjectMetadata, clearMetadata, containsKey, equivalentForTracking, getCharEncoding, getObjectMetadata, getPayload, getPayloadForLogging, getSize, getStringPayload, replaceAllMetadata, setCharEncoding, setMetadata, setPayload, setStringPayload, setStringPayload
-
Methods inherited from interface com.adaptris.interlok.types.InterlokMessage
addMessageHeaders, getContent, getInputStream, getOutputStream, replaceAllMessageHeaders, resolve, setContent, wrap
-
-
-
-
Field Detail
-
METADATA_RESOLVE_REGEXP
public static final java.lang.String METADATA_RESOLVE_REGEXP
- See Also:
- Constant Field Values
-
OBJECT_RESOLVE_REGEXP
public static final java.lang.String OBJECT_RESOLVE_REGEXP
- See Also:
- Constant Field Values
-
UID_RESOLVE_KEY
public static final java.lang.String UID_RESOLVE_KEY
- See Also:
- Constant Field Values
-
SIZE_RESOLVE_KEY
public static final java.lang.String SIZE_RESOLVE_KEY
- See Also:
- Constant Field Values
-
PAYLOAD_RESOLVE_KEY
public static final java.lang.String PAYLOAD_RESOLVE_KEY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AdaptrisMessageImp
protected AdaptrisMessageImp(IdGenerator guid, AdaptrisMessageFactory fac)
Creates a new instance.
- Parameters:
guid
- a GuidGenerator that will be used to create unique-ids.
-
-
Method Detail
-
getFactory
public AdaptrisMessageFactory getFactory()
Description copied from interface:AdaptrisMessage
Return the factory that created this message.- Specified by:
getFactory
in interfaceAdaptrisMessage
- Returns:
- the factory.
-
setContentEncoding
public void setContentEncoding(java.lang.String charEnc)
- Specified by:
setContentEncoding
in interfaceInterlokMessage
-
getContentEncoding
public java.lang.String getContentEncoding()
- Specified by:
getContentEncoding
in interfaceInterlokMessage
-
headersContainsKey
public boolean headersContainsKey(java.lang.String key)
- Specified by:
headersContainsKey
in interfaceInterlokMessage
-
addMetadata
public void addMetadata(java.lang.String key, java.lang.String value)
Description copied from interface:AdaptrisMessage
Puts the passed
value
into the metadata against the passedkey
. If a value has previously been set against thiskey
it will be overwritten.- Specified by:
addMetadata
in interfaceAdaptrisMessage
- Parameters:
key
- the keyvalue
- the value
-
addMessageHeader
public void addMessageHeader(java.lang.String key, java.lang.String value)
- Specified by:
addMessageHeader
in interfaceInterlokMessage
-
addMetadata
public void addMetadata(MetadataElement e)
Description copied from interface:AdaptrisMessage
Puts the passed
MetadataElement
into the metadata. If a value has previously been set with the samekey
it will be overwritten and a message to that effect should be logged.- Specified by:
addMetadata
in interfaceAdaptrisMessage
- Parameters:
e
- theMetadataElement
to add
-
removeMetadata
public void removeMetadata(MetadataElement element)
Description copied from interface:AdaptrisMessage
Removes the passed
MetadataElement
from the metadata if it is present.- Specified by:
removeMetadata
in interfaceAdaptrisMessage
- Parameters:
element
- theMetadataElement
to remove
-
removeMessageHeader
public void removeMessageHeader(java.lang.String key)
- Specified by:
removeMessageHeader
in interfaceInterlokMessage
-
setMessageHeaders
public void setMessageHeaders(java.util.Map<java.lang.String,java.lang.String> metadata)
- Specified by:
setMessageHeaders
in interfaceInterlokMessage
-
clearMessageHeaders
public void clearMessageHeaders()
- Specified by:
clearMessageHeaders
in interfaceInterlokMessage
-
getMetadataValue
public java.lang.String getMetadataValue(java.lang.String key)
Description copied from interface:AdaptrisMessage
Returns the
String
value associated with the passedkey
ornull
if thekey
does not exist. NB may also returnnull
ifnull
was explicitly set as the value of the key. UsecontainsKey
to differentiate these cases.- Specified by:
getMetadataValue
in interfaceAdaptrisMessage
- Parameters:
key
- the key to look for- Returns:
- the value associated with the key
-
getMetadata
public MetadataElement getMetadata(java.lang.String key)
Description copied from interface:AdaptrisMessage
Returns the
MetadataElement
containing the passedkey
ornull
if thekey
does not exist. NB may also returnnull
ifnull
was explicitly set as the value of the key. UsecontainsKey
to differentiate these cases.- Specified by:
getMetadata
in interfaceAdaptrisMessage
- Parameters:
key
- the key to look for- Returns:
- the
MetadataElement
containing the key
-
getMessageHeaders
public java.util.Map<java.lang.String,java.lang.String> getMessageHeaders()
- Specified by:
getMessageHeaders
in interfaceInterlokMessage
-
getMetadata
public java.util.Set<MetadataElement> getMetadata()
Description copied from interface:AdaptrisMessage
Returns a shallow clone of this message's metadata.
- Specified by:
getMetadata
in interfaceAdaptrisMessage
- Returns:
- a
Set
of allMetadataElements
s
-
getUniqueId
public java.lang.String getUniqueId()
- Specified by:
getUniqueId
in interfaceInterlokMessage
-
setUniqueId
public void setUniqueId(java.lang.String s)
- Specified by:
setUniqueId
in interfaceInterlokMessage
-
getReader
public java.io.Reader getReader() throws java.io.IOException
- Specified by:
getReader
in interfaceInterlokMessage
- Throws:
java.io.IOException
-
getWriter
public java.io.Writer getWriter() throws java.io.IOException
- Specified by:
getWriter
in interfaceInterlokMessage
- Throws:
java.io.IOException
-
getWriter
public java.io.Writer getWriter(java.lang.String encoding) throws java.io.IOException
- Specified by:
getWriter
in interfaceInterlokMessage
- Throws:
java.io.IOException
-
addEvent
public void addEvent(MessageEventGenerator meg, boolean wasSuccessful)
Description copied from interface:AdaptrisMessage
Adds an event to this
AdaptrisMessage
'sMessageLifecycleEvent
.- Specified by:
addEvent
in interfaceAdaptrisMessage
- Parameters:
meg
- theMessageEventGenerator
wasSuccessful
- the status of the event
-
getMessageLifecycleEvent
public MessageLifecycleEvent getMessageLifecycleEvent()
Description copied from interface:AdaptrisMessage
Returns this object's
MessageLifecycleEvent
.- Specified by:
getMessageLifecycleEvent
in interfaceAdaptrisMessage
- Returns:
- this object's
MessageLifecycleEvent
-
encode
public byte[] encode(AdaptrisMessageEncoder encoder) throws CoreException
Description copied from interface:AdaptrisMessage
Uses the passed
AdaptrisMessageEncoder
to create an encoded version of thisAdaptrisMessage
. If null is passed this method returnsthis.getPayload()
.- Specified by:
encode
in interfaceAdaptrisMessage
- Parameters:
encoder
- theAdaptrisMessageEncoder
to use- Returns:
- a byte[] representation of this message
- Throws:
CoreException
- wrapping any underlying Exceptions that may occur
-
addObjectHeader
public void addObjectHeader(java.lang.Object key, java.lang.Object object)
Adds an
Object
to this message as metadata. Object metadata is intended to be used within a singleWorkflow
only and will not be encoded or otherwise transported between Workflows.- Specified by:
addObjectHeader
in interfaceInterlokMessage
- Parameters:
object
- theObject
to set as metadatakey
- the key to store this object against.
-
getObjectHeaders
public java.util.Map<java.lang.Object,java.lang.Object> getObjectHeaders()
- Specified by:
getObjectHeaders
in interfaceInterlokMessage
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getNextServiceId
public java.lang.String getNextServiceId()
Description copied from interface:AdaptrisMessage
Returns the unique ID of the next
Service
to apply to the message. Optional, used byBranchingServiceCollection
and possibly others later.- Specified by:
getNextServiceId
in interfaceAdaptrisMessage
- Returns:
- the unique ID of the next
Service
to apply
-
setNextServiceId
public void setNextServiceId(java.lang.String s)
Description copied from interface:AdaptrisMessage
Sets the unique ID of the next
Service
to apply to the message.- Specified by:
setNextServiceId
in interfaceAdaptrisMessage
- Parameters:
s
- the unique ID of the nextService
to apply to the message
-
resolve
public java.lang.String resolve(java.lang.String s, boolean dotAll)
- Specified by:
resolve
in interfaceInterlokMessage
-
resolveObject
public java.lang.Object resolveObject(java.lang.String s)
Retrieve an object from headers/metadata using an expression: %messageObject{some_key}- Specified by:
resolveObject
in interfaceInterlokMessage
- Parameters:
s
- The expression to use to resolve the object.- Returns:
- The header/metadata object, or null.
-
getMetadataValueIgnoreKeyCase
public java.lang.String getMetadataValueIgnoreKeyCase(java.lang.String key)
Description copied from interface:AdaptrisMessage
First looks for a metadata value stored against the passed key taking account of the passed key's case. If a value is found it is returned. Next looks for a metadata value stored against the passed key ignoring. The valued stored against the first key which matches the passed key ignoring case is returned. As the underlying store is unordered, which key will match first is undefined. If no key matches the passed key ignoring case, null is returned.
E.g. where a message has the metdadata values "1" and "2" set against keys "AAA" and "aaa" respectively, calling
getMetadataValueIgnoreKeyCase("AAA")
will return "1', callinggetMetadataValueIgnoreKeyCase("aaa")
will return "2', and callinggetMetadataValueIgnoreKeyCase("aAA")
will return either "1' or "2".- Specified by:
getMetadataValueIgnoreKeyCase
in interfaceAdaptrisMessage
- Parameters:
key
- the key to look for- Returns:
- the value associated with the key or null
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
Description copied from interface:AdaptrisMessage
Returns a deep clone of this object.
- Specified by:
clone
in interfaceAdaptrisMessage
- Overrides:
clone
in classjava.lang.Object
- Returns:
- a deep clone of this object
- Throws:
java.lang.CloneNotSupportedException
- if the implementation does not support cloning
-
copyPayload
@Deprecated public static void copyPayload(AdaptrisMessage src, AdaptrisMessage dest) throws java.io.IOException
Deprecated.since 3.11.0 use MessageHelper#copyPayload(AdaptrisMessage, AdaptrisMessage) instead.Copy the payload from one AdaptrisMessage to another.- Throws:
java.io.IOException
-
-