AttachmentPart getMimeHeader() Method



Description

The Javax.xml.soap.AttachmentPart.getMimeHeader(String name) method gets all the values of the header identified by the given String.

Declaration

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

public abstract String[] getMimeHeader(String name)

Parameters

name − the name of the header; example: "Content-Type"

Return Value

This method returns a String array giving the value for the specified header

Exception

NA

Example

The following example shows the usage of javax.xml.soap.AttachmentPart.getMimeHeader() 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 a MIMEHeader
         attachPart.addMimeHeader("SecondHeader", "header");

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

         // get MIMEHeader "SecondHeader" value
         String[] header = attachPart.getMimeHeader("SecondHeader");
         System.out.println("" + header[0]);

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

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

header
javax_xml_soap_attachmentpart.htm
Advertisements