Package org.dellroad.msrp.msg
Class MsrpRequest
- java.lang.Object
 - 
- org.dellroad.msrp.msg.MsrpMessage
 - 
- org.dellroad.msrp.msg.MsrpRequest
 
 
 
- 
public class MsrpRequest extends MsrpMessage
MSRP request. 
- 
- 
Constructor Summary
Constructors Constructor Description MsrpRequest(String method)Construct an instance with no body and a random transaction ID.MsrpRequest(String transactionId, String method, MsrpHeaders headers)Construct an instance with no body.MsrpRequest(String transactionId, String method, MsrpHeaders headers, byte[] body)Construct an instance with a body. 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description MsrpResponsebuildResponse(int code, String comment)Build anMsrpResponseto this request, if appropriate, with the given error code and comment.booleanequals(Object obj)byte[]getBody()Get the body payload associated with this instance, if any.protected StringgetFirstLine()Get the first message line.bytegetFlagByte()Get the end line flag byte.StringgetMethod()Get the MSRP request method associated with this instance.inthashCode()booleanisAborted()Get the whether this message body was flagged as aborted.booleanisComplete()Get the whether this message body was flagged as complete.static booleanisMimeHeader(String name)Determine if the given header name is a MIME header.voidsetAborted(boolean aborted)voidsetBody(byte[] body)voidsetComplete(boolean complete)voidvalidate()Apply some validation checks to this instance.protected voidwritePayload(OutputStream output)Write the message body, if any.- 
Methods inherited from class org.dellroad.msrp.msg.MsrpMessage
encode, getHeaders, getTransactionId, randomId, toString 
 - 
 
 - 
 
- 
- 
Constructor Detail
- 
MsrpRequest
public MsrpRequest(String method)
Construct an instance with no body and a random transaction ID.- Parameters:
 method- request method
 
- 
MsrpRequest
public MsrpRequest(String transactionId, String method, MsrpHeaders headers)
Construct an instance with no body.- Parameters:
 transactionId- transaction ID, or null to have a randomly generated one assignedmethod- request methodheaders- MSRP headers, or null to have an empty instance created- Throws:
 IllegalArgumentException- ifmethodis nullIllegalArgumentException- iftransactionIdis invalid
 
- 
MsrpRequest
public MsrpRequest(String transactionId, String method, MsrpHeaders headers, byte[] body)
Construct an instance with a body.- Parameters:
 transactionId- transaction IDmethod- request methodheaders- MSRP headers, or null to have an empty instance createdbody- payload body, or null for none- Throws:
 IllegalArgumentException- ifmethodis null or invalidIllegalArgumentException- iftransactionIdis invalid
 
 - 
 
- 
Method Detail
- 
getMethod
public String getMethod()
Get the MSRP request method associated with this instance.- Returns:
 - request method
 
 
- 
getBody
public byte[] getBody()
Get the body payload associated with this instance, if any.- Returns:
 - body, or null if there is none
 
 
- 
setBody
public void setBody(byte[] body)
 
- 
isComplete
public boolean isComplete()
Get the whether this message body was flagged as complete. Default is true.- Returns:
 - true if message completed
 
 
- 
setComplete
public void setComplete(boolean complete)
 
- 
isAborted
public boolean isAborted()
Get the whether this message body was flagged as aborted. Default is false.- Returns:
 - true if message aborted
 
 
- 
setAborted
public void setAborted(boolean aborted)
 
- 
buildResponse
public MsrpResponse buildResponse(int code, String comment)
Build anMsrpResponseto this request, if appropriate, with the given error code and comment.- Parameters:
 code- three digit error codecomment- error comment, or null- Returns:
 - valid response, or null if this request should not generate any response (i.e., 
FailureReport.NO). - Throws:
 IllegalArgumentException- ifcodeis not in the range 000 .. 999
 
- 
validate
public void validate() throws ProtocolExceptionApply some validation checks to this instance.If this method fails, the caller should return 400 Bad Request.
- Throws:
 ProtocolException- if message is invali
 
- 
isMimeHeader
public static boolean isMimeHeader(String name)
Determine if the given header name is a MIME header.- Parameters:
 name- header name- Returns:
 - true if 
nameis a MIME header name - Throws:
 IllegalArgumentException- ifnameis null
 
- 
equals
public boolean equals(Object obj)
- Overrides:
 equalsin classMsrpMessage
 
- 
hashCode
public int hashCode()
- Overrides:
 hashCodein classMsrpMessage
 
- 
getFlagByte
public byte getFlagByte()
Description copied from class:MsrpMessageGet the end line flag byte.- Specified by:
 getFlagBytein classMsrpMessage- Returns:
 - flag byte
 
 
- 
getFirstLine
protected String getFirstLine()
Description copied from class:MsrpMessageGet the first message line.- Specified by:
 getFirstLinein classMsrpMessage- Returns:
 - first line
 
 
- 
writePayload
protected void writePayload(OutputStream output) throws IOException
Description copied from class:MsrpMessageWrite 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.
- Specified by:
 writePayloadin classMsrpMessage- Parameters:
 output- destination for message- Throws:
 IOException- if an I/O error occurs
 
 - 
 
 -