Class Message

java.lang.Object
com.bea.wcp.diameter.Message
Direct Known Subclasses:
Answer, Request

public abstract class Message extends Object
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 Details

  • 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 command
      appId - the application identifier
      hopByHopId - the hop-by-hop identifier
      endToEndId - the end-to-end identifier
      sessionId - optional session identifier
    • Message

      protected Message(Message req, ResultCode rc)
      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 message
      rc - the result code for the answer
    • Message

      protected Message(ByteBuffer bb, com.bea.wcp.diameter.transport.Connection c)
      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 bytes
      c - the connection which received the message
  • Method Details

    • decodeAvps

      public void decodeAvps(ByteBuffer bb) throws MessageException
      Called by Connection to decode message AVPs.
      Parameters:
      bb - the message body bytes
      Throws:
      MessageException - if the message was invalid
    • preValidate

      public void preValidate() throws MessageException
      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

      protected void preValidateAvp(Avp avp) throws AvpException
      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

      public void validate() throws MessageException
      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

      protected void validateAvp(Avp avp) throws AvpException
      Throws:
      AvpException
    • encode

      public ByteBuffer encode(ByteBuffer bb)
      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

      public ByteBuffer encode()
      Returns a byte buffer which contains the encoded message bytes.
    • getAvp

      public Avp getAvp(Attribute attr)
      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

      public Avp getAvp(String name)
      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

      public void addAvp(Avp avp)
      Adds a new AVP to the message.
      Parameters:
      avp - the AVP to be added
    • addAvp

      public void addAvp(Attribute attr, Object value)
      Adds a new AVP to the message.
      Parameters:
      attr - the AVP Attribute
      value - the AVP value
    • addAvp

      public void addAvp(String name, Object value)
      Adds a new AVP by name to the message.
      Parameters:
      name - the AVP attribute name
      value - the AVP value
    • getCode

      public int getCode()
      Returns the Command code for this message.
    • getCommand

      public Command 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

      public AvpList getAvpList()
      Returns the list of message AVPs.
    • getSessionId

      public String getSessionId()
      Returns the value of the Session-Id AVP, or null if none.
    • getEffectiveSessionId

      public String getEffectiveSessionId()
      Returns the session id of this message, or if none exists, looks for one in the original request.
    • getOriginHost

      public String getOriginHost()
      Returns the value of the Origin-Host AVP.
    • getOriginRealm

      public String getOriginRealm()
      Returns the value of the Origin-Realm AVP.
    • getSession

      public abstract Session 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

      public abstract void send() throws IOException
      Sends this Diameter message.
      Throws:
      IOException - if an I/O error occurred while sending
    • commit

      public abstract void commit() throws IOException
      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

      public static Message decode(ByteBuffer bb, com.bea.wcp.diameter.transport.Connection c)
      Decodes the message header from the specified message bytes and connection.
      Parameters:
      bb - the message bytes to be decoded
      c - the connection used to receive the message
      Returns:
      the decoded message
      Throws:
      IndexOutOfBoundsException - if the message length was less than HEADER_SIZE
    • getLength

      public static int getLength(ByteBuffer bb)
    • getCode

      public static int getCode(ByteBuffer bb)
    • getVersion

      public static int getVersion(ByteBuffer bb)
    • getAppId

      public static int getAppId(ByteBuffer bb)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toLoggableString

      public String toLoggableString()
    • appendXml

      public XmlBuffer appendXml(XmlBuffer xb)
    • extractAndSetSessionIdAvp

      public void extractAndSetSessionIdAvp()