1 16 package org.apache.axis2.om; 17 18 import junit.framework.TestCase; 19 import org.apache.axis2.attachments.ByteArrayDataSource; 20 import org.apache.axis2.soap.SOAPFactory; 21 22 import javax.activation.DataHandler ; 23 import javax.mail.MessagingException ; 24 import javax.mail.internet.MimeBodyPart ; 25 import javax.mail.internet.MimeMessage ; 26 import javax.mail.internet.MimeMultipart ; 27 import javax.mail.internet.MimePartDataSource ; 28 import java.io.ByteArrayInputStream ; 29 import java.io.ByteArrayOutputStream ; 30 import java.io.IOException ; 31 import java.util.Properties ; 32 33 36 public class MIMEOutputUtilsTest extends TestCase { 37 byte[] buffer; 38 byte[] byteArray = new byte[] { 13, 56, 65, 32, 12, 12, 7, -3, -2, -1, 39 98 }; 40 41 protected void setUp() throws Exception { 42 super.setUp(); 43 SOAPFactory factory = OMAbstractFactory.getSOAP11Factory(); 44 ByteArrayOutputStream outStream; 45 String boundary = "----TemporaryBoundary"; 46 47 String contentType = MIMEOutputUtils.getContentTypeForMime(boundary); 48 DataHandler dataHandler; 49 dataHandler = new DataHandler (new ByteArrayDataSource(byteArray)); 50 OMText textData = factory.createText(dataHandler, true); 51 52 DataHandler dataHandler2 = new DataHandler ( 53 "Apache Software Foundation", "text/plain"); 54 OMText text = factory.createText(dataHandler2, true); 55 outStream = new ByteArrayOutputStream (); 56 outStream.write(("Content-Type: "+contentType).getBytes()); 57 outStream.write(new byte[]{ 13, 10 }); 58 MIMEOutputUtils.startWritingMime(outStream, boundary); 60 MimeBodyPart part1 = MIMEOutputUtils.createMimeBodyPart(textData); 61 MIMEOutputUtils.writeBodyPart(outStream, part1, boundary); 62 MimeBodyPart part2 = MIMEOutputUtils.createMimeBodyPart(text); 63 MIMEOutputUtils.writeBodyPart(outStream, part2, boundary); 64 MIMEOutputUtils.finishWritingMime(outStream); 65 buffer = outStream.toByteArray(); 66 System.out.println(new String (buffer)); 67 System.out.println("Axis2"); 68 } 69 70 public void testMIMEWriting() throws IOException , MessagingException { 71 ByteArrayInputStream inStream = new ByteArrayInputStream (buffer); 72 Properties props = new Properties (); 73 javax.mail.Session session = javax.mail.Session 74 .getInstance(props, null); 75 MimeMessage mimeMessage = new MimeMessage (session, inStream); 76 DataHandler dh = mimeMessage.getDataHandler(); 77 MimeMultipart multiPart = new MimeMultipart ((MimePartDataSource ) dh 78 .getDataSource()); 79 MimeBodyPart mimeBodyPart2 = (MimeBodyPart ) multiPart.getBodyPart(0); 80 Object object = mimeBodyPart2.getContent(); 81 MimeBodyPart mimeBodyPart1 = (MimeBodyPart ) multiPart.getBodyPart(0); 82 83 } 84 85 } | Popular Tags |