AttachmentPart removeMimeHeader() Method



Description

The Javax.xml.soap.AttachmentPart.removeMimeHeader(String header) method removes all MIME headers that match the given name.

Declaration

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

public abstract void removeMimeHeader()

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.removeMimeHeader() method.

package com.tutorialspoint;

import com.sun.xml.internal.messaging.saaj.util.Base64;
import com.sun.xml.internal.messaging.saaj.util.ByteInputStream;
import java.io.InputStream;
import java.util.Iterator;
import javax.activation.DataHandler;
import javax.xml.soap.*;
import javax.xml.soap.MimeHeaders;

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 another header
         attachPart.addMimeHeader("Header", "value");

         // remove remove the data handler header
         attachPart.removeMimeHeader("Header");

         // print the remaining headers
         Iterator a = attachPart.getAllMimeHeaders();

         while (a.hasNext()) {
            MimeHeader header = (MimeHeader) a.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 −

Content-Type
javax_xml_soap_attachmentpart.htm
Advertisements