org.jboss.esb.message
Class Payload

java.lang.Object
  extended by org.jboss.esb.message.Payload
All Implemented Interfaces:
Serializable

public class Payload
extends Object
implements Serializable

A message payload.

A message can have a number of payloads. Every message has a primary message payload, as well as 0 or more attachment payloads.

A payload can be any java Object, or an array of bytes. The content can be accessed through the getContent() method and set through the setContent(Object) and setContent(byte[], String) methods.

A payload definition also contains a set of MIME headers, which can be managed through the getMimeHeaders() method. Examples of such MIME headers are "Content-Type", "Content-ID" and "Content-Location".

If the content is a byte array, the "Content-Type" MIME header must be set, otherwise an exception is likely to occur during serialization of the message. This of course will depend on the wire format (XML stream, Java Object stream etc).

This class is modeled directly on AttachmentPart as defined in the SAAJ API.

Author:
tom.fennelly@jboss.com
See Also:
Serialized Form

Field Summary
static String CONTENT_ID
           
static String CONTENT_LOCATION
           
static String CONTENT_TYPE
           
 
Constructor Summary
Payload()
          Contruct an empty payload instance.
Payload(byte[] content, String contentType)
          Construct a binary content payload.
Payload(Object content)
          Construct a Java Object content payload.
 
Method Summary
 Object getContent()
          Get the message payload.
 String getContentType()
          Get the Content-Type MIME header.
 Properties getMimeHeaders()
          Get the MIME headers.
 void setContent(byte[] content, String contentType)
          Set a binary payload.
 void setContent(Object content)
          Set a Java Object content payload.
 void setContentType(String contentType)
          Set the Content-Type MIME header.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTENT_TYPE

public static String CONTENT_TYPE

CONTENT_ID

public static String CONTENT_ID

CONTENT_LOCATION

public static String CONTENT_LOCATION
Constructor Detail

Payload

public Payload()
Contruct an empty payload instance.

The content can be set by either of the setContent(Object) or setContent(byte[], String) methods.


Payload

public Payload(Object content)
Construct a Java Object content payload.

An IllegalArgumentException will occur if the supplied content instance is a byte[]. In this case, you should use the Payload(byte[], String) constructor.

Parameters:
content - The Java payload.

Payload

public Payload(byte[] content,
               String contentType)
Construct a binary content payload.

Parameters:
content - The binary payload.
contentType - The binary payload content type.
Method Detail

getMimeHeaders

public Properties getMimeHeaders()
Get the MIME headers.

Returns:
The MIME headers.

getContent

public Object getContent()
Get the message payload.

The object can be a byte[] instance for binary data, or a non byte[] Java Object instance. MIME info relating to the payload can be can be retreived through the getMimeHeaders() method.

Returns:
Payload content.

setContent

public void setContent(Object content)
Set a Java Object content payload.

An IllegalArgumentException will occur if the supplied content instance is a byte[]. In this case, you should use the setContent(byte[], String) method.

Parameters:
content - The content payload.

setContent

public void setContent(byte[] content,
                       String contentType)
Set a binary payload.

Parameters:
content - The binary payload.
contentType - The payload content type.

getContentType

public String getContentType()
Get the Content-Type MIME header.

This is just shorthand for:

  getMimeHeaders.getProperty(CONTENT_TYPE);
 

Returns:
The content type.

setContentType

public void setContentType(String contentType)
Set the Content-Type MIME header.

This is just shorthand for (with example value):

  getMimeHeaders.setProperty(CONTENT_TYPE, "text/plain");
 

Parameters:
contentType - The content type.


Copyright © 2007. All Rights Reserved.