List of usage examples for javax.xml.soap AttachmentPart setDataHandler
public abstract void setDataHandler(DataHandler dataHandler);
From source file:com.googlecode.ddom.saaj.SOAPMessageTest.java
@Validated @Test// w w w. j a v a 2 s. c o m public void testWriteToWithAttachment() throws Exception { SOAPMessage message = getFactory().createMessage(); message.getSOAPPart().getEnvelope().getBody().addBodyElement(new QName("urn:ns", "test", "p")); AttachmentPart attachment = message.createAttachmentPart(); attachment.setDataHandler(new DataHandler("This is a test", "text/plain; charset=iso-8859-15")); message.addAttachmentPart(attachment); ByteArrayOutputStream baos = new ByteArrayOutputStream(); message.writeTo(baos); System.out.write(baos.toByteArray()); MimeMultipart mp = new MimeMultipart(new ByteArrayDataSource(baos.toByteArray(), "multipart/related")); assertEquals(2, mp.getCount()); BodyPart part1 = mp.getBodyPart(0); // TODO // assertEquals(messageSet.getVersion().getContentType(), part1.getContentType()); BodyPart part2 = mp.getBodyPart(1); // Note: text/plain is the default content type, so we need to include the parameters in the assertion assertEquals("text/plain; charset=iso-8859-15", part2.getContentType()); }