AttachmentPart getContentType() Method



Description

The Javax.xml.soap.AttachmentPart.getContentType() method gets the value of the MIME header whose name is "Content-Type".

Declaration

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

public String getContentType()

Parameters

NA

Return Value

This method returns a String giving the value of the "Content-Type" header or null if there is none

Exception

NA

Example

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

package com.tutorialspoint;

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 the attachment part in the message
         message.addAttachmentPart(attachPart);

         // get the content type
         System.out.println("" + attachPart.getContentType());


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

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

HandlerHeader
javax_xml_soap_attachmentpart.htm
Advertisements