Package org.dellroad.msrp.msg
Class MsrpMessage
- java.lang.Object
-
- org.dellroad.msrp.msg.MsrpMessage
-
- Direct Known Subclasses:
MsrpRequest,MsrpResponse
public abstract class MsrpMessage extends Object
MSRP request/response support superclass.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedMsrpMessage()Default constructor.protectedMsrpMessage(String transactionId, MsrpHeaders headers)Construct an instance with the given transaction ID and headers.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description byte[]encode(boolean withBody)Encode this instance according to RFC 4975.booleanequals(Object obj)protected abstract StringgetFirstLine()Get the first message line.protected abstract bytegetFlagByte()Get the end line flag byte.MsrpHeadersgetHeaders()Get the headers associated with this instance.StringgetTransactionId()Get the transaction ID associated with this instance.inthashCode()static StringrandomId()Generate a random identifier for use as transaction or message ID.StringtoString()protected abstract voidwritePayload(OutputStream output)Write the message body, if any.
-
-
-
Constructor Detail
-
MsrpMessage
protected MsrpMessage()
Default constructor. Generates a random transaction ID.
-
MsrpMessage
protected MsrpMessage(String transactionId, MsrpHeaders headers)
Construct an instance with the given transaction ID and headers.- Parameters:
transactionId- transaction ID, or null to have a randomly generated one assignedheaders- MSRP headers, or null to have an empty instance created- Throws:
IllegalArgumentException- iftransactionIdis invalid
-
-
Method Detail
-
getTransactionId
public String getTransactionId()
Get the transaction ID associated with this instance.- Returns:
- transaction ID
-
getHeaders
public MsrpHeaders getHeaders()
Get the headers associated with this instance.- Returns:
- headers
-
encode
public byte[] encode(boolean withBody)
Encode this instance according to RFC 4975.- Parameters:
withBody- true to include the body, or false to omit the body, if any- Returns:
- encoded message
-
randomId
public static String randomId()
Generate a random identifier for use as transaction or message ID.- Returns:
- new random ID
-
getFlagByte
protected abstract byte getFlagByte()
Get the end line flag byte.- Returns:
- flag byte
-
getFirstLine
protected abstract String getFirstLine()
Get the first message line.- Returns:
- first line
-
writePayload
protected abstract void writePayload(OutputStream output) throws IOException
Write the message body, if any.If this message has a body, this method should output CRLF, followed by the binary body content, followed by a final CRLF. If this message has no body, this method should not output anything.
- Parameters:
output- destination for message- Throws:
IOException- if an I/O error occurs
-
-