|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Object dk.i1.diameter.Message
public class Message
A Diameter Message.
The Message is a container for the MessageHeader
and the AVP
s.
It supports converting to/from the on-the-wire format, and
manipulating the AVPs. The class is lean and mean, and does as little
checking as possible.
Example of building a Message:
Message msg = new Message(); msg.hdr.application_id = ProtocolConstants.DIAMETER_APPLICATION_ACCOUNTING; msg.hdr.command_code = ProtocolConstants.DIAMETER_COMMAND_ACCOUNTING; msg.hdr.setRequest(true); msg.hdr.setProxiable(true); //Add AVPs ... msg.add(new AVP_UTF8String(ProtocolConstants.DI_USER_NAME,"user@example.net")); msg.add(new AVP_Unsigned64(ProtocolConstants.DI_ACCOUNTING_INPUT_OCTETS,36758373691049)); ...Example of processing a message:
Message msg ...; for(AVP avp : msg.subset(ProtocolConstants.DI_FRAMED_IP_ADDRESS)) { try { InetAddress address = new AVP_Address(avp).queryAddress(); ..do something useful with the address... } catch(InvalidAVPLengthException ex) { .. handle when peer sends garbage } catch(InvalidAddressTypeException ex) { .. handle when peer sends garbage } } AVP avp_reply_message = msg.find(ProtocolConstants.DI_REPLY_MESSAGE); if(avp!=null) { ..do something sensible with reply-message }
Nested Class Summary | |
---|---|
static class |
Message.decode_status
The decode status from decode(byte[]) |
Field Summary | |
---|---|
MessageHeader |
hdr
The message header |
Constructor Summary | |
---|---|
Message()
The default constructor. |
|
Message(Message msg)
Copy-constructor. |
|
Message(MessageHeader header)
Construct a message with a specific header. |
Method Summary | |
---|---|
void |
add(AVP avp)
Adds an AVP at the end of the AVP list |
void |
add(int index,
AVP avp)
Inserts an AVP at the specified posistion (0-based) |
Iterable<AVP> |
avps()
Returns an Iterable for the AVPs |
void |
clear()
Removes all AVPs from the message |
Message.decode_status |
decode(byte[] b)
Decode a message from on-the-wire format. |
Message.decode_status |
decode(byte[] b,
int offset,
int bytes)
Decode a message from on-the-wire format. |
static int |
decodeSize(byte[] b,
int offset)
Determine the complete size of the message from a on-the-wire byte array. |
byte[] |
encode()
Encode the message to on-the-wire format |
void |
encode(byte[] b)
Encode the message in on-the-wire format to the specified byte array. |
int |
encodeSize()
Calculate the size of the message in on-the-wire format |
void |
ensureCapacity(int minCapacity)
Ensure that ther is room for at least he specified number of AVPs |
AVP |
find(int code)
Finds an AVP with the specified code. |
AVP |
find(int code,
int vendor_id)
Finds an AVP with the specified code/vendor-id. |
AVP |
get(int index)
Gets the AVP at the specified index (0-based) |
java.util.Iterator<AVP> |
iterator()
Returns an iterator for the AVP list |
java.util.Iterator<AVP> |
iterator(int code)
Returns an iterator for the AVPs with the specified code |
java.util.Iterator<AVP> |
iterator(int code,
int vendor_id)
Returns an iterator for the AVPs with the specified code and vendor id |
void |
prepareAnswer(Message request)
Prepare an answer from the specified request header. |
void |
prepareResponse(Message request)
Prepare a response the the supplied request. |
void |
remove(int index)
Removes the AVP at the specified position (0-based) |
int |
size()
Return the number of AVPs in the message |
Iterable<AVP> |
subset(int code)
Returns a iterable subset of the AVPs. |
Iterable<AVP> |
subset(int code,
int vendor_id)
Returns a iterable subset of the AVPs. |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public MessageHeader hdr
Constructor Detail |
---|
public Message()
public Message(MessageHeader header)
header
- The message header to use instead of a default one.public Message(Message msg)
Method Detail |
---|
public int encodeSize()
public void encode(byte[] b)
b
- The byte array which must be large enough.public byte[] encode()
public static int decodeSize(byte[] b, int offset)
b
- The byte arrayoffset
- The offset into the byte array where the message is supposed to start.
public Message.decode_status decode(byte[] b)
b
- A byte array which consists of exacly 1 message. Superfluous bytes are not permitted.
public Message.decode_status decode(byte[] b, int offset, int bytes)
b
- A byte array possibly containing a Diameter messageoffset
- Offset into the array where decoding should startbytes
- The bytes to try to decode
public int size()
public void ensureCapacity(int minCapacity)
public AVP get(int index)
public void clear()
public void add(AVP avp)
public void add(int index, AVP avp)
public void remove(int index)
public Iterable<AVP> avps()
public java.util.Iterator<AVP> iterator()
public java.util.Iterator<AVP> iterator(int code)
public java.util.Iterator<AVP> iterator(int code, int vendor_id)
public void prepareResponse(Message request)
MessageHeader.prepareResponse(MessageHeader)
public void prepareAnswer(Message request)
public Iterable<AVP> subset(int code)
return subset(code,0);
public Iterable<AVP> subset(int code, int vendor_id)
for(AVP avp : message.subset(...something...)) { //process the AVP }
code
- The AVP code
public AVP find(int code)
find(code,0);
public AVP find(int code, int vendor_id)
code
- AVP codevendor_id
- Vendor-ID. Use 0 to specify none.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |