1 16 17 package samples.swa; 18 19 import javax.activation.DataHandler ; 20 import javax.activation.FileDataSource ; 21 import javax.mail.internet.MimeBodyPart ; 22 import javax.mail.internet.MimeMultipart ; 23 24 29 public class Tester { 30 31 32 public static final String HEADER_CONTENT_TYPE = "Content-Type"; 33 34 35 public static final String HEADER_CONTENT_TRANSFER_ENCODING = 36 "Content-Transfer-Encoding"; 37 38 39 private static final java.lang.String address = 40 "http://localhost:8080/axis/services/SwaHttp"; 41 42 48 public static void main(String [] args) throws Exception { 49 50 57 SwaServiceLocator service = new SwaServiceLocator(); 58 59 64 java.net.URL endpoint; 65 try { 66 endpoint = new java.net.URL (address); 67 } catch (java.net.MalformedURLException e) { 68 throw new javax.xml.rpc.ServiceException (e); 69 } 70 71 SwaPort port = (SwaPort) service.getSwaHttp(endpoint); 72 73 77 78 82 MimeMultipart mpRoot = new MimeMultipart (); 83 System.out.println("MimeMultipart content: " + mpRoot.getContentType()); 84 DataHandler dh = new DataHandler (new FileDataSource ("duke.gif")); 85 addBodyPart(mpRoot, dh); 86 dh = new DataHandler (new FileDataSource ("pivots.jpg")); 87 addBodyPart(mpRoot, dh); 88 port.swaSend("AppName", mpRoot); 90 } 91 92 98 private static void addBodyPart(MimeMultipart mp, DataHandler dh) { 99 MimeBodyPart messageBodyPart = new MimeBodyPart (); 100 try { 101 messageBodyPart.setDataHandler(dh); 102 String contentType = dh.getContentType(); 103 if ((contentType == null) || (contentType.trim().length() == 0)) { 104 contentType = "application/octet-stream"; 105 } 106 System.out.println("Content type: " + contentType); 107 messageBodyPart.setHeader(HEADER_CONTENT_TYPE, contentType); 108 messageBodyPart.setHeader( 109 HEADER_CONTENT_TRANSFER_ENCODING, 110 "binary"); mp.addBodyPart(messageBodyPart); 112 } catch (javax.mail.MessagingException e) { 113 } 114 } 115 } 116 | Popular Tags |