Example usage for javax.xml.soap SOAPMessage createAttachmentPart

List of usage examples for javax.xml.soap SOAPMessage createAttachmentPart

Introduction

In this page you can find the example usage for javax.xml.soap SOAPMessage createAttachmentPart.

Prototype

public AttachmentPart createAttachmentPart(Object content, String contentType) 

Source Link

Document

Creates an AttachmentPart object and populates it with the specified data of the specified content type.

Usage

From source file:com.googlecode.ddom.saaj.SOAPMessageTest.java

@Validated
@Test//from  www.  ja v  a2 s. com
public final void testRemoveAllAttachments() throws Exception {
    SOAPMessage message = getFactory().createMessage();
    for (int i = 0; i < 5; i++) {
        AttachmentPart att = message.createAttachmentPart("test" + i, "text/plain");
        message.addAttachmentPart(att);
    }
    assertEquals(5, message.countAttachments());
    message.removeAllAttachments();
    assertEquals(0, message.countAttachments());
    if (message.saveRequired()) {
        message.saveChanges();
    }
    String[] contentType = message.getMimeHeaders().getHeader("Content-Type");
    assertNotNull(contentType);
    assertEquals(1, contentType.length);
    assertEquals(messageSet.getVersion().getContentType(), new MimeType(contentType[0]).getBaseType());
}