SOAPMessage object. A SOAPMessage
object may contain zero, one, or many AttachmentPart objects.
Each AttachmentPart object consists of two parts,
application-specific content and associated MIME headers. The
MIME headers consists of name/value pairs that can be used to
identify and describe the content.
An AttachmentPart object must conform to certain standards.
Content-TypeAttachmentPart object and MUST conform to [RFC2045].
The following is an example of a Content-Type header:
Content-Type: application/xml
The following line of code, in which ap is an
AttachmentPart object, sets the header shown in
the previous example.
ap.setMimeHeader("Content-Type", "application/xml");
There are no restrictions on the content portion of an AttachmentPart object. The content may be anything from a
simple plain text object to a complex XML document or image file.
An AttachmentPart object is created with the method
SOAPMessage.createAttachmentPart. After setting its MIME headers,
the AttachmentPart object is added to the message
that created it with the method SOAPMessage.addAttachmentPart.
The following code fragment, in which m is a
SOAPMessage object and contentStringl is a
String, creates an instance of AttachmentPart,
sets the AttachmentPart object with some content and
header information, and adds the AttachmentPart object to
the SOAPMessage object.
AttachmentPart ap1 = m.createAttachmentPart();
ap1.setContent(contentString1, "text/plain");
m.addAttachmentPart(ap1);
The following code fragment creates and adds a second
AttachmentPart instance to the same message. jpegData
is a binary byte buffer representing the jpeg file.
AttachmentPart ap2 = m.createAttachmentPart();
byte[] jpegData = ...;
ap2.setContent(new ByteArrayInputStream(jpegData), "image/jpeg");
m.addAttachmentPart(ap2);
The getContent method retrieves the contents and header from
an AttachmentPart object. Depending on the
DataContentHandler objects present, the returned
Object can either be a typed Java object corresponding
to the MIME type or an InputStream object that contains the
content as bytes.
String content1 = ap1.getContent();
java.io.InputStream content2 = ap2.getContent();
The method clearContent removes all the content from an
AttachmentPart object but does not affect its header information.
ap1.clearContent();
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public abstract void | addMimeHeader(String
a name, String String giving the name of the header
to be addeda value)String giving the value of the header
to be addedAdds a MIME header with the specified name and value to this
|
| public abstract void | |
| public abstract Iterator | Returns: anIterator object with all of the Mime
headers for this AttachmentPart objectRetrieves all the headers for this |
| public abstract InputStream | Returns: anInputStream from which the Base64 encoded
AttachmentPart can be read.Returns an |
| public abstract Object | Returns: a Java object with the content of thisAttachmentPart
objectGets the content of this |
| public String | Returns: aString giving the value of the
"Content-ID" header or null if there
is noneGets the value of the MIME header whose name is "Content-ID". |
| public String | Returns: aString giving the value of the
"Content-Location" header or null if there
is noneGets the value of the MIME header whose name is "Content-Location". |
| public String | Returns: aString giving the value of the
"Content-Type" header or null if there
is noneGets the value of the MIME header whose name is "Content-Type". |
| public abstract DataHandler | Returns: theDataHandler object associated with this
AttachmentPart objectGets the |
| public abstract Iterator | Returns: all of the MIME headers that match one of the names in the given array as anIterator objecta names)String array with the name(s) of the
MIME headers to be returnedRetrieves all |
| public abstract String[] | Returns: aString array giving the value for the
specified headerthe name of the header; example: "Content-Type" name)Gets all the values of the header identified by the given
|
| public abstract Iterator | Returns: all of the MIME headers in thisAttachmentPart object
except those that match one of the names in the
given array. The nonmatching MIME headers are returned as an
Iterator object.a names)String array with the name(s) of the
MIME headers not to be returnedRetrieves all |
| public abstract InputStream | Returns: anInputStream from which the raw data contained by
the AttachmentPart can be accessed.Gets the content of this |
| public abstract byte[] | Returns: abyte[] array containing the raw data of the
AttachmentPart.Gets the content of this |
| public abstract int | Returns: the size of thisAttachmentPart object in bytes
or -1 if the size cannot be determinedReturns the number of bytes in this |
| public abstract void | |
| public abstract void | removeMimeHeader(String
the string name of the MIME header/s to
be removed header)Removes all MIME headers that match the given name. |
| public abstract void | setBase64Content(InputStream
the base64 encoded data to add to the attachment part content, String the value to set into the contentType)Content-Type
headerSets the content of this attachment part from the Base64 source
|
| public abstract void | setContent(Object
the Java object that makes up the content for
this attachment part object, String the MIME string that specifies the type of
the content contentType)Sets the content of this attachment part to that of the given
|
| public void | setContentId(String
a contentId)String giving the value of the
"Content-ID" headerSets the MIME header whose name is "Content-ID" with the given value. |
| public void | setContentLocation(String
a contentLocation)String giving the value of the
"Content-Location" headerSets the MIME header whose name is "Content-Location" with the given value. |
| public void | setContentType(String
a contentType)String giving the value of the
"Content-Type" headerSets the MIME header whose name is "Content-Type" with the given value. |
| public abstract void | setDataHandler(DataHandler
the dataHandler)DataHandler object to be setSets the given |
| public abstract void | setMimeHeader(String
a name, String String giving the name of the header
for which to searcha value)String giving the value to be set for
the header whose name matches the given nameChanges the first header entry that matches the given name to the given value, adding a new header if no existing header matches. |
| public abstract void | setRawContent(InputStream
the raw data to add to the attachment part content, String the value to set into the contentType)Content-Type
headerSets the content of this attachment part to that contained by the
|
| public abstract void | setRawContentBytes(byte[]
the raw data to add to the attachment part content, int the offset in the byte array of the content offset, int the number of bytes that form the content len, String the value to set into the contentType)Content-Type
headerSets the content of this attachment part to that contained by the
|
| AttachmentPart | back to summary |
|---|---|
| public AttachmentPart() | |
| addMimeHeader | back to summary |
|---|---|
| public abstract void addMimeHeader(String name, String value) Adds a MIME header with the specified name and value to this
Note that RFC822 headers can contain only US-ASCII characters.
| |
| clearContent | back to summary |
|---|---|
| public abstract void clearContent() Clears out the content of this | |
| getAllMimeHeaders | back to summary |
|---|---|
| public abstract Iterator Retrieves all the headers for this
| |
| getBase64Content | back to summary |
|---|---|
| public abstract InputStream getBase64Content() throws SOAPException Returns an
| |
| getContent | back to summary |
|---|---|
| public abstract Object getContent() throws SOAPException Gets the content of this
For the MIME content types "text/plain", "text/html" and "text/xml", the
A SAAJ-compliant implementation must, as a minimum, return a
| |
| getContentId | back to summary |
|---|---|
| public String getContentId() Gets the value of the MIME header whose name is "Content-ID".
| |
| getContentLocation | back to summary |
|---|---|
| public String getContentLocation() Gets the value of the MIME header whose name is "Content-Location".
| |
| getContentType | back to summary |
|---|---|
| public String getContentType() Gets the value of the MIME header whose name is "Content-Type".
| |
| getDataHandler | back to summary |
|---|---|
| public abstract DataHandler getDataHandler() throws SOAPException Gets the
| |
| getMatchingMimeHeaders | back to summary |
|---|---|
| public abstract Iterator Retrieves all
| |
| getMimeHeader | back to summary |
|---|---|
| public abstract String[] getMimeHeader(String name) Gets all the values of the header identified by the given
| |
| getNonMatchingMimeHeaders | back to summary |
|---|---|
| public abstract Iterator Retrieves all
| |
| getRawContent | back to summary |
|---|---|
| public abstract InputStream getRawContent() throws SOAPException Gets the content of this
Note that reading from the returned InputStream would result in consuming
the data in the stream. It is the responsibility of the caller to reset
the InputStream appropriately before calling a Subsequent API. If a copy
of the raw attachment content is required then the
| |
| getRawContentBytes | back to summary |
|---|---|
| public abstract byte[] getRawContentBytes() throws SOAPException Gets the content of this
| |
| getSize | back to summary |
|---|---|
| public abstract int getSize() throws SOAPException Returns the number of bytes in this
| |
| removeAllMimeHeaders | back to summary |
|---|---|
| public abstract void removeAllMimeHeaders() Removes all the MIME header entries. | |
| removeMimeHeader | back to summary |
|---|---|
| public abstract void removeMimeHeader(String header) Removes all MIME headers that match the given name.
| |
| setBase64Content | back to summary |
|---|---|
| public abstract void setBase64Content(InputStream content, String contentType) throws SOAPException Sets the content of this attachment part from the Base64 source
A subsequent call to getSize() may not be an exact measure of the content size.
| |
| setContent | back to summary |
|---|---|
| public abstract void setContent(Object object, String contentType) Sets the content of this attachment part to that of the given
| |
| setContentId | back to summary |
|---|---|
| public void setContentId(String contentId) Sets the MIME header whose name is "Content-ID" with the given value.
| |
| setContentLocation | back to summary |
|---|---|
| public void setContentLocation(String contentLocation) Sets the MIME header whose name is "Content-Location" with the given value.
| |
| setContentType | back to summary |
|---|---|
| public void setContentType(String contentType) Sets the MIME header whose name is "Content-Type" with the given value.
| |
| setDataHandler | back to summary |
|---|---|
| public abstract void setDataHandler(DataHandler dataHandler) Sets the given
| |
| setMimeHeader | back to summary |
|---|---|
| public abstract void setMimeHeader(String name, String value) Changes the first header entry that matches the given name to the given value, adding a new header if no existing header matches. This method also removes all matching headers but the first. Note that RFC822 headers can only contain US-ASCII characters.
| |
| setRawContent | back to summary |
|---|---|
| public abstract void setRawContent(InputStream content, String contentType) throws SOAPException Sets the content of this attachment part to that contained by the
A subsequent call to getSize() may not be an exact measure of the content size.
| |
| setRawContentBytes | back to summary |
|---|---|
| public abstract void setRawContentBytes(byte[] content, int offset, int len, String contentType) throws SOAPException Sets the content of this attachment part to that contained by the
| |