SFRMMessage

public class SFRMMessage implements Cloneable

This is the SFRM Message used for wrapping the payload and send it to the receiver side. Specification: Creation Date: 29/9/2006 Version 1.0.2 -

  • Add a message classifier for recognizing the message nature much easily.

Version 1.0.1 -

  • MIC Value is stored into ContentMD5 in the MimeBodyPart.
  • Support cloning.
Author:Twinsen Tsang

Fields

ALG_ENCRYPT_3DES

public static final String ALG_ENCRYPT_3DES

ALG_ENCRYPT_RC2

public static final String ALG_ENCRYPT_RC2

ALG_SIGN_MD5

public static final String ALG_SIGN_MD5

ALG_SIGN_SHA1

public static final String ALG_SIGN_SHA1

SFRM_MESSAGE_VERSION

public static final String SFRM_MESSAGE_VERSION

The current version of SFRM Message.

Constructors

SFRMMessage

public SFRMMessage()

Creates a new instance of SFRM Message.

SFRMMessage

public SFRMMessage(InputStream message)

Creates a new instance of SFRM Message.

Parameters:
  • message – the message as input stream.
Throws:
  • SFRMMessageException – if unable to construct from the given input stream.

SFRMMessage

public SFRMMessage(InternetHeaders headers, InputStream content)

Creates a new instance of SFRMMessage.

Parameters:
  • headers – the headers of this message.
  • ins – the content stream.
Throws:
  • SFRMMessageException – if unable to construct from the given content stream.

Methods

addHeader

public void addHeader(String name, String value)

Adds a message header of the specified name.

Parameters:
  • name – the header name.
  • value – the header value.

clone

protected Object clone()
Returns:returns a clone for this Message.

decrypt

public void decrypt(X509Certificate cert, PrivateKey privateKey)

digest

public static String digest(InputStream inStream)

digest

public static String digest(FileRegionDataSource frds)

digest

public String digest()

encrypt

public void encrypt(X509Certificate cert, String encryptAlg)

getBodyPart

public MimeBodyPart getBodyPart()

Gets the MIME body part of this message.

Returns:the MIME body part.

getClassifier

public SFRMMessageClassifier getClassifier()
Returns:a message classifier for this message.

getContent

public Object getContent()

Gets the content of payload from this message.

Throws:
Returns:

the content part.

getContentStream

public InputStream getContentStream()

Gets the content stream of this message.

Returns:the content stream of this message. null if there is no content.

getContentType

public String getContentType()

Gets the content type of the payload from this message.

Throws:
Returns:

the content type.

getConverationId

public String getConverationId()
Returns:the SFRM conversation id from the message.

getFilename

public String getFilename()

Get the filename of SFRM payload

Returns:filename of the SFRM payload

getHeader

public String getHeader(String name)

Gets a message header of the specified name.

Parameters:
  • name – the header name.
Returns:

the header value.

getHeader

public String getHeader(String name, String def)

Gets a message header of the specified name.

Parameters:
  • name – the header name.
  • def – the default value.
Returns:

the header value.

getHeaders

public InternetHeaders getHeaders()

Gets the headers of this message.

Returns:a copy of the headers of this message.

getHostname

public String getHostname()
Returns:the host name of the message.

getInputStream

public InputStream getInputStream()

Gets the input stream of this message’s content. Any transfer encodings will be decoded before the input stream is provided.

Throws:
Returns:

the input stream of this message’s content.

getMessageID

public String getMessageID()

Gets the message ID.

Returns:the message ID.

getMicValue

public String getMicValue()
Returns:the mic value of this message.

getPartnershipId

public String getPartnershipId()
Returns:the SFRM partnership id from the message.

getSegmentLength

public long getSegmentLength()
Returns:the SFRM segment length from this message.

getSegmentNo

public int getSegmentNo()
Returns:the SFRM segmet no from the message.

getSegmentOffset

public long getSegmentOffset()
Returns:the SFRM segment offset position from the message.

getSegmentType

public String getSegmentType()
Returns:the SFRM segment type from the message.

getTotalSegment

public int getTotalSegment()
Returns:get the total segment in the meta message.

getTotalSize

public long getTotalSize()
Returns:the total size of payload in the meta message.

getVersion

public String getVersion()
Returns:the SFRM Version from the message.

isEncryptedContentType

public boolean isEncryptedContentType()

isSignedContentType

public boolean isSignedContentType()

removeHeader

public void removeHeader(String name)

Removes a message header of the specified name.

Parameters:
  • name – the header name.

setBodyPart

public void setBodyPart(MimeBodyPart bp)

Sets the MIME body part of this message.

Parameters:
  • bp – the new MIME body part.

setContent

public void setContent(Object content, String contentType)

Sets a content to this message.

Parameters:
  • content – the content part.
  • contentType – the content type.
Throws:

setContent

public void setContent(Object content, String contentType, String transferEncoding)

setConversationId

public void setConversationId(String conversationId)

Set the conversation id of this message.

Parameters:
  • conversationId – The conversation id.

setFilename

public void setFilename(String filename)

Set the filename of the SFRM payload

Parameters:
  • filename – the filename of the SFRM payload to be set

setHeader

public void setHeader(String name, String value)

Sets a message header of the specified name.

Parameters:
  • name – the header name.
  • value – the header value.

setIsEncrypted

public void setIsEncrypted(boolean isEncrypted)

Set whether the message is encrypted.

Parameters:
  • isEncrypted – true if encrypted, false vice versa.

setIsSigned

public void setIsSigned(boolean isSigned)

Set whether the message is signed.

Parameters:
  • isSigned – true if signed, false vice versa.

setMessageID

public void setMessageID(String messageId)

Set the message id of this message.

Parameters:
  • messageId – The message id of this message.

setMicValue

public void setMicValue(String micValue)

Set the MIC value of the message. I.e. the checksum of this message.

Parameters:
  • micValue – the mic value of this message.

setPartnershipId

public void setPartnershipId(String partnershipId)

Set the partnership id of the message.

setSegmentLength

public void setSegmentLength(long length)

Set the segment payload into this message. The segment length will only be set when it is greater than or equal to zero.

Parameters:
  • length – The length of this segment.

setSegmentNo

public void setSegmentNo(int segmentNo)

Set the segment number of the message. The segment number will only be set when it is greater than or equal to zero.

Parameters:
  • segmentNo – The segment number of message.

setSegmentOffset

public void setSegmentOffset(long offset)

Set the segment offset of this message. The segment offset will only be set when it is greater than or equal to zero.

Parameters:
  • offset – The offset of this segment.

setSegmentType

public void setSegmentType(String segmentType)

Set the segment type of the message. It can only be either “META”, “PAYLOAD”, “RECEIPT” AND “RECOVERY”.

Parameters:
  • segmentType – The segment type of the message.

setTotalSegment

public void setTotalSegment(int totalSegment)

Set the total segment in the meta message.

Parameters:
  • totalSegment – The total segment of the message.

setTotalSize

public void setTotalSize(long totalSize)

Set the total size in the meta message.

Parameters:
  • totalSize – The total size of the message.

sign

public void sign(X509Certificate cert, PrivateKey privateKey, String digestAlg)

toByteArray

public byte[] toByteArray()

Returns a byte array which represents this message contnet.

Throws:
Returns:

a byte array which represents this message.

toByteBuffer

public ByteBuffer toByteBuffer(boolean hardwareBuffer)

Returns a byte buffer which represents this message content, i.e. a MIME body part byte buffer.

Parameters:
  • hardwareBuffer

toString

public String toString()

Returns a string representation of this message.

Returns:a string representation of this message.

See also: java.lang.Object.toString()

verify

public void verify(X509Certificate cert)

writeTo

public void writeTo(OutputStream outs)

Writes the message to the given output stream.

Parameters:
  • outs – the output stream to be written.
Throws: