AttachmentPart getAllMimeHeaders() Method



Description

The Javax.xml.soap.AttachmentPart.getAllMimeHeaders() method retrieves all the headers for this AttachmentPart object as an iterator over the MimeHeader objects.

Declaration

Following is the declaration for javax.xml.soap.AttachmentPart.getAllMimeHeaders() method

public abstract Iterator getAllMimeHeaders()

Parameters

NA

Return Value

This method does not return a value.

Exception

NA

Example

The following example shows the usage of javax.xml.soap.AttachmentPart.getAllMimeHeaders() method.

package com.tutorialspoint;

import java.util.Iterator;
import javax.activation.DataHandler;
import javax.xml.soap.*;

public class AttachmentPartDemo {

   public static void main(String[] args) {
      try {

         // create a new SOAPMessage
         SOAPMessage message = MessageFactory.newInstance().createMessage();

         // create a string as a new attachment 
         String attachment = "This is an attachment";

         // get the data handler and assign the attachment
         DataHandler handler = new DataHandler(attachment, "HandlerHeader");

         // create the attachment part
         AttachmentPart attachPart = message.createAttachmentPart(handler);

         // add content in the attachment
         attachPart.setContent("Attachment Content", "plain/text");

         // add the attachment part in the message
         message.addAttachmentPart(attachPart);

         // get the content of attachment part
         System.out.println("" + attachPart.getContent());

         // print the mimeheaders names
         Iterator headers = attachPart.getAllMimeHeaders();
         while (headers.hasNext()) {
            MimeHeader header = (MimeHeader) headers.next();
            System.out.println("" + header.getName());
         }


      } catch (Exception ex) {
         ex.printStackTrace();
      }
   }
}

If we compile the code and execute it, this will produce the following result −

Attachment Content
Content-Type
javax_xml_soap_attachmentpart.htm
Advertisements