Package com.bea.wcp.diameter
Class Message
java.lang.Object
com.bea.wcp.diameter.Message
Diameter Message base class for both Request and Answer message types.
Message processing begins by decoding the message header from the message
bytes using an instance of MessageFactory. The default decoder will create
a new instance of Request for request messages, and Answer for answer
messages. The actual message AVPs are then decoded in a separate step by
calling "decodeAvps" in order to have the option of sending an error
answer early if the message header was bad. Finally, the AVP values are
fully decoded and validated by calling "validate" which in turn calls
"validateAvp" for each partially decoded AVP. Custom message implementations
can override the method "validateAvp" in order to provide additional
validation as well as save AVP values as they are being decoded.
Diameter header:
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Version | Message Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | command flags | Command-Code | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Application-ID | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Hop-by-Hop Identifier | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | End-to-End Identifier | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ... AVPs ... | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- Author:
- Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intDiameter version. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMessage(Message req, ResultCode rc) Creates a new Diameter answer message for the specified request.protectedThis constructor is only called by Request when creating a new request.protectedMessage(ByteBuffer bb, com.bea.wcp.diameter.transport.Connection c) Creates a new Message decoded from the specified message bytes. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a new AVP to the message.voidAdds a new AVP to the message.voidAdds a new AVP by name to the message.abstract voidcommit()Commits a message currently being sent.static Messagedecode(ByteBuffer bb, com.bea.wcp.diameter.transport.Connection c) Decodes the message header from the specified message bytes and connection.voiddecodeAvps(ByteBuffer bb) Called by Connection to decode message AVPs.encode()Returns a byte buffer which contains the encoded message bytes.encode(ByteBuffer bb) Encodes this diameter message to the specified byte buffer.voidintgetAppId()Returns the application identifier for this message.static intgetAppId(ByteBuffer bb) Returns the first AVP in the message with the specified attribute.Returns the first AVP for the specific attribute name, or null if noneReturns the list of message AVPs.intgetCode()Returns the Command code for this message.static intgetCode(ByteBuffer bb) Returns the Command for this message.com.bea.wcp.diameter.transport.ConnectionIf this message was received then returns the connection used to receive the message.Returns the session id of this message, or if none exists, looks for one in the original request.intReturns the end-to-end identifier for this message.intReturns the hop-by-hop identifier for this message.static intgetLength(ByteBuffer bb) Returns the value of the Origin-Host AVP.Returns the value of the Origin-Realm AVP.abstract SessionReturns the Session associated with this message, or null if none.Returns the value of the Session-Id AVP, or null if none.static intgetVersion(ByteBuffer bb) final booleanisAnswer()Returns true if this message an answer message.abstract booleanbooleanisError()Returns true if this message is an erorr according to the header flags.booleanReturns true if this message has been potentially retransmitted according to the header flags.booleanReturns true if this message is proxiable according to the header flags.final booleanReturns true if this message is a request.booleanRemoves the last proxy info element from this message.voidPerforms initial validation of a message to include validation of AVPs required to determine if the request/answer should be forwarded.protected voidpreValidateAvp(Avp avp) Fully decodes and validates the specified AVP.abstract voidsend()Sends this Diameter message.toString()voidvalidate()Validates the message by validating each message AVP.protected voidvalidateAvp(Avp avp)
-
Field Details
-
HEADER_SIZE
public static final int HEADER_SIZE- See Also:
-
VERSION
public static final int VERSIONDiameter version.- See Also:
-
FLAG_REQUEST
public static final int FLAG_REQUEST- See Also:
-
FLAG_PROXIABLE
public static final int FLAG_PROXIABLE- See Also:
-
FLAG_ERROR
public static final int FLAG_ERROR- See Also:
-
FLAG_POTENTIALLY_RETRANSMITTED
public static final int FLAG_POTENTIALLY_RETRANSMITTED- See Also:
-
FLAGS_MASK
public static final int FLAGS_MASK- See Also:
-
-
Constructor Details
-
Message
protected Message(Node node, Command cmd, int appId, int hopByHopId, int endToEndId, String sessionId) This constructor is only called by Request when creating a new request. The reason for the constructor being here rather than in Request itself is to have access to private fields within Message.- Parameters:
node- the Diameter node (used for setting origin Avps)cmd- the request commandappId- the application identifierhopByHopId- the hop-by-hop identifierendToEndId- the end-to-end identifiersessionId- optional session identifier
-
Message
Creates a new Diameter answer message for the specified request. The relevant header fields and AVPs are copied from the original request. Again, this constructor is defined here rather than in Answer to have access to private fields within Message.- Parameters:
req- the original request messagerc- the result code for the answer
-
Message
Creates a new Message decoded from the specified message bytes. The methods "decodeAvps" and "validate" should then be called in order to decode the message AVPs and validate the message.- Parameters:
bb- the message bytesc- the connection which received the message
-
-
Method Details
-
decodeAvps
Called by Connection to decode message AVPs.- Parameters:
bb- the message body bytes- Throws:
MessageException- if the message was invalid
-
preValidate
Performs initial validation of a message to include validation of AVPs required to determine if the request/answer should be forwarded. If we determine the message should be handled locally, then the remaining AVPs will be validated by 'validate()'.- Throws:
MessageException- if validation failed
-
preValidateAvp
Fully decodes and validates the specified AVP. Message implementations can override this to provide additional validation or to cache AVP results.- Parameters:
avp- the AVP to be validated- Throws:
AvpException- if the AVP was invalid
-
validate
Validates the message by validating each message AVP. If any AVP values are cached as message fields, they are cleared first. This supports validation of both received and originated messages.- Throws:
MessageException- if the message was invalid
-
validateAvp
- Throws:
AvpException
-
encode
Encodes this diameter message to the specified byte buffer. The buffer will be expanded as needed to accomodate the size of the encoded message.- Parameters:
bb- the output byte buffer- Returns:
- the byte buffer containing the encoded bytes
-
encode
Returns a byte buffer which contains the encoded message bytes. -
getAvp
Returns the first AVP in the message with the specified attribute.- Parameters:
attr- the AVP attribute- Returns:
- the first AVP with the specified attribute, or null if not found
-
getAvp
Returns the first AVP for the specific attribute name, or null if none- Parameters:
name- the attribute name- Returns:
- the AVP with the attribute, or null if none
-
addAvp
Adds a new AVP to the message.- Parameters:
avp- the AVP to be added
-
addAvp
Adds a new AVP to the message.- Parameters:
attr- the AVP Attributevalue- the AVP value
-
addAvp
Adds a new AVP by name to the message.- Parameters:
name- the AVP attribute namevalue- the AVP value
-
getCode
public int getCode()Returns the Command code for this message. -
getCommand
Returns the Command for this message. -
isRequest
public final boolean isRequest()Returns true if this message is a request. -
isAnswer
public final boolean isAnswer()Returns true if this message an answer message. -
isProxiable
public boolean isProxiable()Returns true if this message is proxiable according to the header flags. -
isError
public boolean isError()Returns true if this message is an erorr according to the header flags. -
isPotentiallyRetransmitted
public boolean isPotentiallyRetransmitted()Returns true if this message has been potentially retransmitted according to the header flags. -
getAppId
public int getAppId()Returns the application identifier for this message. -
getHopByHopId
public int getHopByHopId()Returns the hop-by-hop identifier for this message. -
getEndToEndId
public int getEndToEndId()Returns the end-to-end identifier for this message. -
getAvpList
Returns the list of message AVPs. -
getSessionId
Returns the value of the Session-Id AVP, or null if none. -
getEffectiveSessionId
Returns the session id of this message, or if none exists, looks for one in the original request. -
getOriginHost
Returns the value of the Origin-Host AVP. -
getOriginRealm
Returns the value of the Origin-Realm AVP. -
getSession
Returns the Session associated with this message, or null if none. -
getConnection
public com.bea.wcp.diameter.transport.Connection getConnection()If this message was received then returns the connection used to receive the message. Otherwise, returns null. -
send
Sends this Diameter message.- Throws:
IOException- if an I/O error occurred while sending
-
commit
Commits a message currently being sent.- Throws:
IOException
-
isCommitted
public abstract boolean isCommitted() -
popProxyInfo
public boolean popProxyInfo()Removes the last proxy info element from this message.- Returns:
- true if proxy info was found and removed
-
decode
Decodes the message header from the specified message bytes and connection.- Parameters:
bb- the message bytes to be decodedc- the connection used to receive the message- Returns:
- the decoded message
- Throws:
IndexOutOfBoundsException- if the message length was less than HEADER_SIZE
-
getLength
-
getCode
-
getVersion
-
getAppId
-
toString
-
toLoggableString
-
appendXml
-
extractAndSetSessionIdAvp
public void extractAndSetSessionIdAvp()
-