Class ISOMsg
java.lang.Object
org.jpos.iso.ISOComponent
org.jpos.iso.ISOMsg
- All Implemented Interfaces:
Externalizable, Serializable, Cloneable, Loggeable
- Direct Known Subclasses:
FSDISOMsg, ISOMsgRef.Ref, ISOVMsg
implements Composite
within a Composite pattern
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intMessage direction: INCOMING or OUTGOING.protected booleanDirty flags for tracking state changes.protected intField number of this message when nested inside another ISOMsg.Map of field number to field value.protected ISOHeaderOptional ISO header for this message.static final intConstant indicating an incoming message direction.protected intHighest field number currently set in this message.protected booleanDirty flags for tracking state changes.static final intConstant indicating an outgoing message direction.protected ISOPackagerThe packager used to pack/unpack this message.protected byte[]Optional trailer bytes appended to the packed message. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()clone(int... fields) Partially clone an ISOMsgPartially clone an ISOMsg by field pathsvoiddump(PrintStream p, String indent) dump the message to a PrintStream.byte[]getBytes(int fldno) Return the byte[] value associated with the given ISOField numberbyte[]Return the String value associated with the given field pathclone fieldsgetComponent(int fldno) get the component associated with the given field numbergetComponent(String fpath) get the component associated with the given field numberIn order to interchange Composites and Leafs we use getComposite().intReturns the message direction.intReturns the field number this component occupies within its container.byte[]get optional message header imageReturn this messages ISOHeadergetKey()valid on Leafs only.intReturns the highest field number present in this message.getMTI()Returns the message type indicator.Returns the packager associated with this message.Returns the associated ISOSource (e.g.getString(int fldno) Return the String value associated with the given ISOField numberReturn the String value associated with the given field pathbyte[]Get optional trailer image.getValue()Returns this message itself as its value.getValue(int fldno) Return the object value associated with the given field numberReturn the object value associated with the given field pathbooleanhasAny(int[] fields) Check if the message has any of these fieldsbooleanCheck if the message has any of these fieldsbooleanhasField(int fldno) Check if a given field is presentbooleanCheck if a field indicated by a fpath is presentbooleanReturns true if this message has at least one field set.booleanhasFields(int[] fields) Check if all fields are presentbooleanhasMTI()Returns true if this message has an MTI field (field 0) set.booleanReturns true if this is an administrative message (MTI second digit = 6).booleanReturns true if this is an authorization message (MTI second digit = 1).booleanReturns true if this is a chargeback message (MTI second digit = 4, last digit 2 or 3).booleanReturns true if this is a fee collection message (MTI second digit = 7).booleanReturns true if this is a file action message (MTI second digit = 3).booleanReturns true if this is a financial message (MTI second digit = 2).booleanReturns true if this message was received from a channel.booleanisInner()Returns true if this is an inner (sub-) message.booleanReturns true if this is a network management message (MTI second digit = 8).booleanReturns true if this message is to be sent via a channel.booleanReturns true if this is a reconciliation message (MTI second digit = 5).booleanReturns true if the MTI suggests this is a request message.booleanReturns true if the MTI suggests this is a response message.booleanReturns true if this is a retransmission (MTI last digit = 1).booleanReturns true if this is a reversal message (MTI second digit = 4, last digit 0 or 1).voidMerges the content of the specified ISOMsg into this ISOMsg instance, excluding the header.voidMerges the content of the specified ISOMsg into this ISOMsg instance.voidmove(int oldFieldNumber, int newFieldNumber) moves a field (renumber)byte[]pack()Packs this message using the configured packager.protected voidDeserializes the message direction from the given ObjectInput.voidprotected voidDeserializes the message header from the given ObjectInput.protected voidDeserializes the packager from the given ObjectInput.voidsetup BitMapvoidset(int fldno, byte[] value) Creates an ISOBinaryField associated with fldno within this ISOMsg.voidCreates an ISOField associated with fldno within this ISOMsg.voidCreates an ISOField associated with fldno within this ISOMsg.voidCreates an ISOField associated with fldno within this ISOMsg.voidset(String fpath, ISOComponent c) Creates an ISOField associated with fldno within this ISOMsgvoidset(ISOComponent c) Set a field within this messagevoidsetDirection(int direction) Sets the direction information related to this messagevoidsetFieldNumber(int fieldNumber) changes this Component field number
Use with care, this method does not change any reference held by a Composite.voidsetHeader(byte[] b) Sets an optional message header imagevoidSets the ISO header for this message.voidSets the message type indicator.voidSets the packager used to pack/unpack this message.voidsets an appropriate response MTI.voidsets an appropriate retransmission MTIvoidLet this ISOMsg object hold a weak reference to an ISOSource (usually used to carry a reference to the incoming ISOChannel)voidsetTrailer(byte[] trailer) Sets optional trailer data.voidDon't call setValue on an ISOMsg.toString()intunpack(byte[] b) Unpacks the raw byte array into this message.voidunpack(InputStream in) Unpacks this component by reading fromin.voidunset(int fldno) Unset a field if it exists, otherwise ignore.voidunset(int... flds) Unsets several fields at oncevoidUnset a field referenced by a fpath if it exists, otherwise ignore.voidUnset a a set of fields referenced by fpaths if any ot them exist, otherwise ignore.with(int fldno, byte[] value) Sets a top-level binary field and returns this message for fluent chaining.Sets a top-level character field and returns this message for fluent chaining.Sets a binary field by path and returns this message for fluent chaining.Sets a character field by path and returns this message for fluent chaining.with(String fpath, ISOComponent c) Sets a component by path and returns this message for fluent chaining.without(int... flds) Unsets one or more top-level fields and returns this message for fluent chaining.Unsets one or more field paths, including nested composites and dataset elements, and returns this message for fluent chaining.protected voidSerializes the message direction to the given ObjectOutput.voidprotected voidwriteHeader(ObjectOutput out) Serializes the message header to the given ObjectOutput.protected voidSerializes the packager class name to the given ObjectOutput.Methods inherited from class ISOComponent
getBytes, packModifier and TypeMethodDescriptionbyte[]getBytes()get Value as bytes (when possible)voidpack(OutputStream out) Packs this component and writes it toout.Methods inherited from class Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Loggeable
dumpModifier and TypeMethodDescriptiondefault voiddump(PrintStream p, String indent, LogRenderer.Type type) Dumps a representation of this object using the specified renderer type.
-
Field Details
-
fields
-
maxField
Highest field number currently set in this message. -
packager
The packager used to pack/unpack this message. -
dirty
Dirty flags for tracking state changes. -
maxFieldDirty
Dirty flags for tracking state changes. -
direction
Message direction: INCOMING or OUTGOING. -
header
-
trailer
Optional trailer bytes appended to the packed message. -
fieldNumber
Field number of this message when nested inside another ISOMsg. -
INCOMING
-
OUTGOING
-
-
Constructor Details
-
ISOMsg
public ISOMsg()Creates an ISOMsg -
ISOMsg
Creates a nested ISOMsg- Parameters:
fieldNumber- (in the outer ISOMsg) of this nested message
-
ISOMsg
-
-
Method Details
-
setFieldNumber
changes this Component field number
Use with care, this method does not change any reference held by a Composite.- Specified by:
setFieldNumberin classISOComponent- Parameters:
fieldNumber- new field number
-
setDirection
Sets the direction information related to this message- Parameters:
direction- can be either ISOMsg.INCOMING or ISOMsg.OUTGOING
-
setHeader
-
setHeader
-
getHeader
get optional message header image- Returns:
- message header image (may be null)
-
setTrailer
Sets optional trailer data.Note: The trailer data requires a customised channel that explicitly handles the trailer data from the ISOMsg.
- Parameters:
trailer- The trailer data.- See Also:
-
getTrailer
-
getISOHeader
Return this messages ISOHeader- Returns:
- header associated with this ISOMsg, can be null
-
getDirection
Returns the message direction.- Returns:
- the direction (
ISOMsg.INCOMINGorISOMsg.OUTGOING) - See Also:
-
isIncoming
Returns true if this message was received from a channel.- Returns:
- true if this is an incoming message
- See Also:
-
isOutgoing
Returns true if this message is to be sent via a channel.- Returns:
- true if this is an outgoing message
- See Also:
-
getMaxField
Returns the highest field number present in this message.- Overrides:
getMaxFieldin classISOComponent- Returns:
- the max field number
-
setPackager
Sets the packager used to pack/unpack this message.- Parameters:
p- - a peer packager
-
getPackager
Returns the packager associated with this message.- Returns:
- the peer packager
-
set
Set a field within this message- Overrides:
setin classISOComponent- Parameters:
c- - a component- Throws:
ISOException- always thrown by leaves; composites override this
-
set
-
with
-
set
-
with
-
set
Creates an ISOField associated with fldno within this ISOMsg- Parameters:
fpath- dot-separated field path (i.e. 63.2)c- component- Throws:
ISOException- on error
-
with
Sets a component by path and returns this message for fluent chaining.- Parameters:
fpath- dot-separated field pathc- component to store- Returns:
- this message
- Throws:
ISOException- on path or component errors
-
set
-
with
-
with
-
set
Creates an ISOBinaryField associated with fldno within this ISOMsg.- Parameters:
fldno- field numbervalue- field value
-
unset
Unset a field if it exists, otherwise ignore.- Overrides:
unsetin classISOComponent- Parameters:
fldno- - the field number
-
unset
Unsets several fields at once- Parameters:
flds- - array of fields to be unset from this ISOMsg
-
unset
-
unset
-
without
-
without
-
getComposite
In order to interchange Composites and Leafs we use getComposite(). A Composite component returns itself and a Leaf returns null.- Overrides:
getCompositein classISOComponent- Returns:
- ISOComponent
-
recalcBitMap
-
getChildren
clone fields- Overrides:
getChildrenin classISOComponent- Returns:
- copy of fields
-
pack
Packs this message using the configured packager.- Specified by:
packin classISOComponent- Returns:
- the packed message
- Throws:
ISOException- on packing error
-
unpack
Unpacks the raw byte array into this message.- Specified by:
unpackin classISOComponent- Parameters:
b- - raw message- Returns:
- consumed bytes
- Throws:
ISOException- on unpacking error
-
unpack
Unpacks this component by reading fromin.- Specified by:
unpackin classISOComponent- Parameters:
in- source stream- Throws:
IOException- on I/O failureISOException- on unpacking error
-
dump
dump the message to a PrintStream. The output is sorta XML, intended to be easily parsed.
Each component is responsible for its own dump function, ISOMsg just calls dump on every valid field.- Specified by:
dumpin interfaceLoggeable- Specified by:
dumpin classISOComponent- Parameters:
p- - print streamindent- - optional indent string
-
getComponent
get the component associated with the given field number- Parameters:
fldno- the Field Number- Returns:
- the Component
-
getValue
-
getValue
Return the object value associated with the given field path- Parameters:
fpath- field path- Returns:
- the field Object (may be null)
- Throws:
ISOException- on error
-
getComponent
get the component associated with the given field number- Parameters:
fpath- field path- Returns:
- the Component
- Throws:
ISOException- on error
-
getString
-
getString
-
getBytes
Return the byte[] value associated with the given ISOField number- Parameters:
fldno- the Field Number- Returns:
- field's byte[] value or null if ISOException or UnsupportedEncodingException happens
-
getBytes
-
hasField
Check if a given field is present- Parameters:
fldno- the Field Number- Returns:
- boolean indicating the existence of the field
-
hasFields
Check if all fields are present- Parameters:
fields- an array of fields to check for presence- Returns:
- true if all fields are present
-
hasAny
Check if the message has any of these fields- Parameters:
fields- an array of fields to check for presence- Returns:
- true if at least one field is present
-
hasAny
-
hasField
-
hasFields
Returns true if this message has at least one field set.- Returns:
- true if at least one field is present
-
setValue
Don't call setValue on an ISOMsg. You'll sure get an ISOException. It's intended to be used on Leafs- Specified by:
setValuein classISOComponent- Parameters:
obj- value to set (not supported on ISOMsg)- Throws:
ISOException- always- See Also:
-
clone
-
clone
-
clone
-
merge
Merges the content of the specified ISOMsg into this ISOMsg instance. It iterates over the fields of the input message and, for each field that is present, sets the corresponding component in this message to the value from the input message. This operation includes all fields that are present in the input message, but does not remove any existing fields from this message unless they are explicitly overwritten by the input message.If the input message contains a header (non-null), this method also clones the header and sets it as the header of this message.
- Parameters:
m- The ISOMsg to merge into this ISOMsg. It must not benull. The method does nothing ifmisnull.mergeHeader- A boolean flag indicating whether to merge the header of the input message into this message.
-
merge
Merges the content of the specified ISOMsg into this ISOMsg instance, excluding the header. This method is a convenience wrapper aroundmerge(ISOMsg, boolean)with themergeHeaderparameter set tofalsefor backward compatibility, indicating that the header of the input message will not be merged.- Parameters:
m- the ISOMsg to merge into this message
-
toString
-
getKey
Description copied from class:ISOComponentvalid on Leafs only. The value returned is used by ISOMsg as a key to this field.- Overrides:
getKeyin classISOComponent- Returns:
- object representing the field number
- Throws:
ISOException- thrown by composites; leaves return their key
-
getValue
Returns this message itself as its value.- Overrides:
getValuein classISOComponent- Returns:
- this ISOMsg
-
isInner
Returns true if this is an inner (sub-) message.- Returns:
- true on inner messages
-
setMTI
Sets the message type indicator.- Parameters:
mti- new MTI- Throws:
ISOException- if message is inner message
-
move
moves a field (renumber)- Parameters:
oldFieldNumber- old field numbernewFieldNumber- new field number- Throws:
ISOException- on error
-
getFieldNumber
Description copied from class:ISOComponentReturns the field number this component occupies within its container.- Specified by:
getFieldNumberin classISOComponent- Returns:
- the field number
-
hasMTI
Returns true if this message has an MTI field (field 0) set.- Returns:
- true if MTI is present
- Throws:
ISOException- if this is an inner message
-
getMTI
Returns the message type indicator.- Returns:
- current MTI
- Throws:
ISOException- on inner message or MTI not set
-
isRequest
Returns true if the MTI suggests this is a request message.- Returns:
- true if message "seems to be" a request
- Throws:
ISOException- on MTI not set
-
isResponse
Returns true if the MTI suggests this is a response message.- Returns:
- true if message "seems not to be" a request
- Throws:
ISOException- on MTI not set
-
isAuthorization
Returns true if this is an authorization message (MTI second digit = 1).- Returns:
- true if message class is "authorization"
- Throws:
ISOException- on MTI not set
-
isFinancial
Returns true if this is a financial message (MTI second digit = 2).- Returns:
- true if message class is "financial"
- Throws:
ISOException- on MTI not set
-
isFileAction
Returns true if this is a file action message (MTI second digit = 3).- Returns:
- true if message class is "file action"
- Throws:
ISOException- on MTI not set
-
isReversal
Returns true if this is a reversal message (MTI second digit = 4, last digit 0 or 1).- Returns:
- true if message class is "reversal"
- Throws:
ISOException- on MTI not set
-
isChargeback
Returns true if this is a chargeback message (MTI second digit = 4, last digit 2 or 3).- Returns:
- true if message class is "chargeback"
- Throws:
ISOException- on MTI not set
-
isReconciliation
Returns true if this is a reconciliation message (MTI second digit = 5).- Returns:
- true if message class is "reconciliation"
- Throws:
ISOException- on MTI not set
-
isAdministrative
Returns true if this is an administrative message (MTI second digit = 6).- Returns:
- true if message class is "administrative"
- Throws:
ISOException- on MTI not set
-
isFeeCollection
Returns true if this is a fee collection message (MTI second digit = 7).- Returns:
- true if message class is "fee collection"
- Throws:
ISOException- on MTI not set
-
isNetworkManagement
Returns true if this is a network management message (MTI second digit = 8).- Returns:
- true if message class is "network management"
- Throws:
ISOException- on MTI not set
-
isRetransmission
Returns true if this is a retransmission (MTI last digit = 1).- Returns:
- true if message is a retransmission
- Throws:
ISOException- on MTI not set
-
setResponseMTI
sets an appropriate response MTI. i.e. 0100 becomes 0110
i.e. 0201 becomes 0210
i.e. 1201 becomes 1210- Throws:
ISOException- on MTI not set or it is not a request
-
setRetransmissionMTI
sets an appropriate retransmission MTI- Throws:
ISOException- on MTI not set or it is not a request
-
writeHeader
Serializes the message header to the given ObjectOutput.- Parameters:
out- the ObjectOutput to write to- Throws:
IOException- on write error
-
readHeader
Deserializes the message header from the given ObjectInput.- Parameters:
in- the ObjectInput to read from- Throws:
IOException- on read errorClassNotFoundException- if a referenced class cannot be found
-
writePackager
Serializes the packager class name to the given ObjectOutput.- Parameters:
out- the ObjectOutput to write to- Throws:
IOException- on write error
-
readPackager
Deserializes the packager from the given ObjectInput.- Parameters:
in- the ObjectInput to read from- Throws:
IOException- on read errorClassNotFoundException- if the packager class cannot be found
-
writeDirection
Serializes the message direction to the given ObjectOutput.- Parameters:
out- the ObjectOutput to write to- Throws:
IOException- on write error
-
readDirection
Deserializes the message direction from the given ObjectInput.- Parameters:
in- the ObjectInput to read from- Throws:
IOException- on read errorClassNotFoundException- if a class cannot be found
-
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
setSource
-
getSource
-