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
AdaptrisMessageinterface.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.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAdaptrisMessageImp(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 voidaddEvent(MessageEventGenerator meg, boolean wasSuccessful)Adds an event to thisAdaptrisMessage'sMessageLifecycleEvent.voidaddMessageHeader(java.lang.String key, java.lang.String value)voidaddMetadata(MetadataElement e)Puts the passedMetadataElementinto the metadata.voidaddMetadata(java.lang.String key, java.lang.String value)Puts the passedvalueinto the metadata against the passedkey.voidaddObjectHeader(java.lang.Object key, java.lang.Object object)Adds anObjectto this message as metadata.voidclearMetadata()Clears the current metadata.java.lang.Objectclone()Returns a deep clone of this object.static voidcopyPayload(AdaptrisMessage src, AdaptrisMessage dest)Deprecated.since 3.11.0 use MessageHelper#copyPayload(AdaptrisMessage, AdaptrisMessage) instead.byte[]encode(AdaptrisMessageEncoder encoder)Uses the passedAdaptrisMessageEncoderto create an encoded version of thisAdaptrisMessage.java.lang.StringgetContentEncoding()AdaptrisMessageFactorygetFactory()Return the factory that created this message.java.util.Map<java.lang.String,java.lang.String>getMessageHeaders()MessageLifecycleEventgetMessageLifecycleEvent()Returns this object'sMessageLifecycleEvent.java.util.Set<MetadataElement>getMetadata()Returns a shallow clone of this message's metadata.MetadataElementgetMetadata(java.lang.String key)Returns theMetadataElementcontaining the passedkeyornullif thekeydoes not exist.java.lang.StringgetMetadataValue(java.lang.String key)Returns theStringvalue associated with the passedkeyornullif thekeydoes not exist.java.lang.StringgetMetadataValueIgnoreKeyCase(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.StringgetNextServiceId()Returns the unique ID of the nextServiceto apply to the message.java.util.Map<java.lang.Object,java.lang.Object>getObjectHeaders()java.io.ReadergetReader()java.lang.StringgetUniqueId()java.io.WritergetWriter()java.io.WritergetWriter(java.lang.String encoding)booleanheadersContainsKey(java.lang.String key)voidremoveMessageHeader(java.lang.String key)voidremoveMetadata(MetadataElement element)Removes the passedMetadataElementfrom the metadata if it is present.java.lang.Stringresolve(java.lang.String s, boolean dotAll)java.lang.ObjectresolveObject(java.lang.String s)Retrieve an object from headers/metadata using an expression: %messageObject{some_key}voidsetContentEncoding(java.lang.String charEnc)voidsetMessageHeaders(java.util.Map<java.lang.String,java.lang.String> metadata)voidsetMetadata(java.util.Set<MetadataElement> set)Adds all the passed metadata to this message's metadata.voidsetNextServiceId(java.lang.String s)Sets the unique ID of the nextServiceto apply to the message.voidsetUniqueId(java.lang.String s)java.lang.StringtoString()-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.adaptris.core.AdaptrisMessage
addObjectMetadata, containsKey, equivalentForTracking, getCharEncoding, getObjectMetadata, getPayload, getPayloadForLogging, getSize, getStringPayload, setCharEncoding, setPayload, setStringPayload, setStringPayload
-
Methods inherited from interface com.adaptris.interlok.types.InterlokMessage
getContent, getInputStream, getOutputStream, resolve, setContent, wrap
-
-
-
-
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:AdaptrisMessageReturn the factory that created this message.- Specified by:
getFactoryin interfaceAdaptrisMessage- Returns:
- the factory.
-
setContentEncoding
public void setContentEncoding(java.lang.String charEnc)
- Specified by:
setContentEncodingin interfaceInterlokMessage- See Also:
InterlokMessage.setContentEncoding(String)
-
getContentEncoding
public java.lang.String getContentEncoding()
- Specified by:
getContentEncodingin interfaceInterlokMessage- See Also:
InterlokMessage.getContentEncoding()
-
headersContainsKey
public boolean headersContainsKey(java.lang.String key)
- Specified by:
headersContainsKeyin interfaceInterlokMessage- See Also:
InterlokMessage.headersContainsKey(String)
-
addMetadata
public void addMetadata(java.lang.String key, java.lang.String value)Description copied from interface:AdaptrisMessagePuts the passed
valueinto the metadata against the passedkey. If a value has previously been set against thiskeyit will be overwritten.- Specified by:
addMetadatain interfaceAdaptrisMessage- Parameters:
key- the keyvalue- the value
-
addMessageHeader
public void addMessageHeader(java.lang.String key, java.lang.String value)- Specified by:
addMessageHeaderin interfaceInterlokMessage
-
addMetadata
public void addMetadata(MetadataElement e)
Description copied from interface:AdaptrisMessagePuts the passed
MetadataElementinto the metadata. If a value has previously been set with the samekeyit will be overwritten and a message to that effect should be logged.- Specified by:
addMetadatain interfaceAdaptrisMessage- Parameters:
e- theMetadataElementto add- See Also:
AdaptrisMessage.addMetadata(MetadataElement)
-
removeMetadata
public void removeMetadata(MetadataElement element)
Description copied from interface:AdaptrisMessageRemoves the passed
MetadataElementfrom the metadata if it is present.- Specified by:
removeMetadatain interfaceAdaptrisMessage- Parameters:
element- theMetadataElementto remove- See Also:
AdaptrisMessage.removeMetadata(MetadataElement)
-
removeMessageHeader
public void removeMessageHeader(java.lang.String key)
- Specified by:
removeMessageHeaderin interfaceInterlokMessage- See Also:
InterlokMessage.removeMessageHeader(String)
-
setMetadata
public void setMetadata(java.util.Set<MetadataElement> set)
Description copied from interface:AdaptrisMessageAdds all the passed metadata to this message's metadata.This will overwrite any pre-existing keys, but will not remove existing metadata
- Specified by:
setMetadatain interfaceAdaptrisMessage- Parameters:
set- the metadata to add
-
setMessageHeaders
public void setMessageHeaders(java.util.Map<java.lang.String,java.lang.String> metadata)
- Specified by:
setMessageHeadersin interfaceInterlokMessage
-
clearMetadata
public void clearMetadata()
Description copied from interface:AdaptrisMessageClears the current metadata.
- Specified by:
clearMetadatain interfaceAdaptrisMessage- See Also:
AdaptrisMessage.clearMetadata()
-
getMetadataValue
public java.lang.String getMetadataValue(java.lang.String key)
Description copied from interface:AdaptrisMessageReturns the
Stringvalue associated with the passedkeyornullif thekeydoes not exist. NB may also returnnullifnullwas explicitly set as the value of the key. UsecontainsKeyto differentiate these cases.- Specified by:
getMetadataValuein interfaceAdaptrisMessage- Parameters:
key- the key to look for- Returns:
- the value associated with the key
- See Also:
AdaptrisMessage.getMetadataValue(String)
-
getMetadata
public MetadataElement getMetadata(java.lang.String key)
Description copied from interface:AdaptrisMessageReturns the
MetadataElementcontaining the passedkeyornullif thekeydoes not exist. NB may also returnnullifnullwas explicitly set as the value of the key. UsecontainsKeyto differentiate these cases.- Specified by:
getMetadatain interfaceAdaptrisMessage- Parameters:
key- the key to look for- Returns:
- the
MetadataElementcontaining the key - See Also:
AdaptrisMessage.getMetadata(String)
-
getMessageHeaders
public java.util.Map<java.lang.String,java.lang.String> getMessageHeaders()
- Specified by:
getMessageHeadersin interfaceInterlokMessage
-
getMetadata
public java.util.Set<MetadataElement> getMetadata()
Description copied from interface:AdaptrisMessageReturns a shallow clone of this message's metadata.
- Specified by:
getMetadatain interfaceAdaptrisMessage- Returns:
- a
Setof allMetadataElementss
-
getUniqueId
public java.lang.String getUniqueId()
- Specified by:
getUniqueIdin interfaceInterlokMessage
-
setUniqueId
public void setUniqueId(java.lang.String s)
- Specified by:
setUniqueIdin interfaceInterlokMessage
-
getReader
public java.io.Reader getReader() throws java.io.IOException- Specified by:
getReaderin interfaceInterlokMessage- Throws:
java.io.IOException
-
getWriter
public java.io.Writer getWriter() throws java.io.IOException- Specified by:
getWriterin interfaceInterlokMessage- Throws:
java.io.IOException
-
getWriter
public java.io.Writer getWriter(java.lang.String encoding) throws java.io.IOException- Specified by:
getWriterin interfaceInterlokMessage- Throws:
java.io.IOException
-
addEvent
public void addEvent(MessageEventGenerator meg, boolean wasSuccessful)
Description copied from interface:AdaptrisMessageAdds an event to this
AdaptrisMessage'sMessageLifecycleEvent.- Specified by:
addEventin interfaceAdaptrisMessage- Parameters:
meg- theMessageEventGeneratorwasSuccessful- the status of the event
-
getMessageLifecycleEvent
public MessageLifecycleEvent getMessageLifecycleEvent()
Description copied from interface:AdaptrisMessageReturns this object's
MessageLifecycleEvent.- Specified by:
getMessageLifecycleEventin interfaceAdaptrisMessage- Returns:
- this object's
MessageLifecycleEvent - See Also:
AdaptrisMessage.getMessageLifecycleEvent()
-
encode
public byte[] encode(AdaptrisMessageEncoder encoder) throws CoreException
Description copied from interface:AdaptrisMessageUses the passed
AdaptrisMessageEncoderto create an encoded version of thisAdaptrisMessage. If null is passed this method returnsthis.getPayload().- Specified by:
encodein interfaceAdaptrisMessage- Parameters:
encoder- theAdaptrisMessageEncoderto use- Returns:
- a byte[] representation of this message
- Throws:
CoreException- wrapping any underlying Exceptions that may occur- See Also:
AdaptrisMessage.encode(AdaptrisMessageEncoder)
-
addObjectHeader
public void addObjectHeader(java.lang.Object key, java.lang.Object object)Adds an
Objectto this message as metadata. Object metadata is intended to be used within a singleWorkflowonly and will not be encoded or otherwise transported between Workflows.- Specified by:
addObjectHeaderin interfaceInterlokMessage- Parameters:
object- theObjectto set as metadatakey- the key to store this object against.
-
getObjectHeaders
public java.util.Map<java.lang.Object,java.lang.Object> getObjectHeaders()
- Specified by:
getObjectHeadersin interfaceInterlokMessage
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object- See Also:
Object.toString()
-
getNextServiceId
public java.lang.String getNextServiceId()
Description copied from interface:AdaptrisMessageReturns the unique ID of the next
Serviceto apply to the message. Optional, used byBranchingServiceCollectionand possibly others later.- Specified by:
getNextServiceIdin interfaceAdaptrisMessage- Returns:
- the unique ID of the next
Serviceto apply - See Also:
AdaptrisMessage.getNextServiceId()
-
setNextServiceId
public void setNextServiceId(java.lang.String s)
Description copied from interface:AdaptrisMessageSets the unique ID of the next
Serviceto apply to the message.- Specified by:
setNextServiceIdin interfaceAdaptrisMessage- Parameters:
s- the unique ID of the nextServiceto apply to the message
-
resolve
public java.lang.String resolve(java.lang.String s, boolean dotAll)- Specified by:
resolvein 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:
resolveObjectin 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:AdaptrisMessageFirst 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:
getMetadataValueIgnoreKeyCasein interfaceAdaptrisMessage- Parameters:
key- the key to look for- Returns:
- the value associated with the key or null
- See Also:
#getMetadataValueIgnoreKeyCase(java.lang.String)
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedExceptionDescription copied from interface:AdaptrisMessageReturns a deep clone of this object.
- Specified by:
clonein interfaceAdaptrisMessage- Overrides:
clonein classjava.lang.Object- Returns:
- a deep clone of this object
- Throws:
java.lang.CloneNotSupportedException- if the implementation does not support cloning- See Also:
Object.clone()
-
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
-
-