Oracle Corp.

Oracle WebLogic Communications Server 10.1 API Reference


com.bea.wcp.diameter
Class Message

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

public abstract class Message
extends java.lang.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 ...                          |
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 

Copyright © 2008 Oracle Corp. All Rights Reserved.

Field Summary
static int FLAG_ERROR
           
static int FLAG_POTENTIALLY_RETRANSMITTED
           
static int FLAG_PROXIABLE
           
static int FLAG_REQUEST
           
static int FLAGS_MASK
           
static int HEADER_SIZE
           
static int VERSION
          Diameter version
 
Constructor Summary
protected Message(java.nio.ByteBuffer bb, Connection c)
          Creates a new Message decoded from the specified message bytes.
protected Message(Message req, ResultCode rc)
          Creates a new Diameter answer message for the specified request.
protected Message(Node node, Command cmd, int appId, int hopByHopId, int endToEndId, java.lang.String sessionId)
          This constructor is only called by Request when creating a new request.
 
Method Summary
 void addAvp(Attribute attr, java.lang.Object value)
          Adds a new AVP to the message.
 void addAvp(Avp avp)
          Adds a new AVP to the message.
 void addAvp(java.lang.String name, java.lang.Object value)
          Adds a new AVP by name to the message.
abstract  void commit()
          Commits a message currently being sent.
static Message decode(java.nio.ByteBuffer bb, Connection c)
          Decodes message header from specified message bytes and connection.
 void decodeAvps(java.nio.ByteBuffer bb)
          Called by Connection to decode message AVPs.
 java.nio.ByteBuffer encode()
          Returns a byte buffer which contains the encoded message bytes.
 java.nio.ByteBuffer encode(java.nio.ByteBuffer bb)
          Encodes this diameter message to the specified byte buffer.
 int getAppId()
          Returns the application identifier for this message.
 Avp getAvp(Attribute attr)
          Returns the first AVP in the message with the specified attribute.
 Avp getAvp(java.lang.String name)
          Returns the first AVP for the specific attribute name, or null if none
 AvpList getAvpList()
          Returns the list of message AVPs.
 int getCode()
          Returns the Command code for this message.
static int getCode(java.nio.ByteBuffer bb)
           
 Command getCommand()
          Returns the Command for this message.
 Connection getConnection()
          If this message was received then returns the connection used to receive the message.
 java.lang.String getEffectiveSessionId()
          Returns the session id of this message, or if none exists, looks for one in the original request.
 int getEndToEndId()
          Returns the end-to-end identifier for this message.
 int getHopByHopId()
          Returns the hop-by-hop identifier for this message.
static int getLength(java.nio.ByteBuffer bb)
           
 java.lang.String getOriginHost()
          Returns the value of the Origin-Host AVP.
 java.lang.String getOriginRealm()
          Returns the value of the Origin-Realm AVP.
abstract  Session getSession()
          Returns the Session associated with this message, or null if none.
 java.lang.String getSessionId()
          Returns the value of the Session-Id AVP, or null if none.
static int getVersion(java.nio.ByteBuffer bb)
           
 boolean isAnswer()
          Returns true if this message an answer message.
abstract  boolean isCommitted()
           
 boolean isError()
          Returns true if this message is an erorr according to the header flags.
 boolean isPotentiallyRetransmitted()
          Returns true if this message has been potentially retransmitted according to the header flags.
 boolean isProxiable()
          Returns true if this message is proxiable according to the header flags.
 boolean isRequest()
          Returns true if this message is a request.
 void preValidate()
          Perform initial validation of message to include validation of AVPs required to determine if the request/answer should be forwarded.
protected  void preValidateAvp(Avp avp)
          Fully decodes and validates the specified AVP.
abstract  void send()
          Sends this Diameter message.
 java.lang.String toLoggableString()
           
 java.lang.String toString()
           
 void validate()
          Validates the message by validating each message AVP.
protected  void validateAvp(Avp avp)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FLAG_ERROR

public static final int FLAG_ERROR
See Also:
Constant Field Values

FLAG_POTENTIALLY_RETRANSMITTED

public static final int FLAG_POTENTIALLY_RETRANSMITTED
See Also:
Constant Field Values

FLAG_PROXIABLE

public static final int FLAG_PROXIABLE
See Also:
Constant Field Values

FLAG_REQUEST

public static final int FLAG_REQUEST
See Also:
Constant Field Values

FLAGS_MASK

public static final int FLAGS_MASK
See Also:
Constant Field Values

HEADER_SIZE

public static final int HEADER_SIZE
See Also:
Constant Field Values

VERSION

public static final int VERSION
Diameter version

See Also:
Constant Field Values
Constructor Detail

Message

protected Message(java.nio.ByteBuffer bb,
                  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.


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 in order to have access to private fields within Message.


Message

protected Message(Node node,
                  Command cmd,
                  int appId,
                  int hopByHopId,
                  int endToEndId,
                  java.lang.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 in order to have access to private fields within Message.

Method Detail

addAvp

public void addAvp(Attribute attr,
                   java.lang.Object value)
Adds a new AVP to the message.

Parameters:
attr - the AVP Attribute
value - the AVP value

addAvp

public void addAvp(Avp avp)
Adds a new AVP to the message.

Parameters:
avp - the AVP to be added

addAvp

public void addAvp(java.lang.String name,
                   java.lang.Object value)
Adds a new AVP by name to the message.

Parameters:
name - the AVP attribute name
value - the AVP value

commit

public abstract void commit()
                     throws java.io.IOException
Commits a message currently being sent.

Throws:
java.io.IOException

decode

public static Message decode(java.nio.ByteBuffer bb,
                             Connection c)
Decodes message header from 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:
java.lang.IndexOutOfBoundsException - if the message length was less than HEADER_SIZE

decodeAvps

public void decodeAvps(java.nio.ByteBuffer bb)
                throws MessageException
Called by Connection to decode message AVPs.

Parameters:
bb - the message body bytes
Throws:
MessageException - if the message was invalid

encode

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


encode

public java.nio.ByteBuffer encode(java.nio.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

getAppId

public int getAppId()
Returns the application identifier for this message.


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(java.lang.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

getAvpList

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


getCode

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


getCode

public static int getCode(java.nio.ByteBuffer bb)

getCommand

public Command getCommand()
Returns the Command for this message.


getConnection

public Connection getConnection()
If this message was received then returns the connection used to receive the message. Otherwise, returns null.


getEffectiveSessionId

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


getEndToEndId

public int getEndToEndId()
Returns the end-to-end identifier for this message.


getHopByHopId

public int getHopByHopId()
Returns the hop-by-hop identifier for this message.


getLength

public static int getLength(java.nio.ByteBuffer bb)

getOriginHost

public java.lang.String getOriginHost()
Returns the value of the Origin-Host AVP.


getOriginRealm

public java.lang.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.


getSessionId

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


getVersion

public static int getVersion(java.nio.ByteBuffer bb)

isAnswer

public final boolean isAnswer()
Returns true if this message an answer message.


isCommitted

public abstract boolean isCommitted()

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.


isProxiable

public boolean isProxiable()
Returns true if this message is proxiable according to the header flags.


isRequest

public final boolean isRequest()
Returns true if this message is a request.


preValidate

public void preValidate()
                 throws MessageException
Perform initial validation of message to include validation of AVPs required to determine if the request/answer should be forwarded. If we determine the message should be locally handled, 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

send

public abstract void send()
                   throws java.io.IOException
Sends this Diameter message.

Throws:
java.io.IOException - if an I/O error occurred while sending

toLoggableString

public java.lang.String toLoggableString()

toString

public java.lang.String toString()

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

Documentation is available at
http://e-docs.bea.com/wlcp/wlss40/
Copyright 2008 Oracle Corp.