1 7 package samples.swa; 8 9 import org.apache.axis.AxisFault; 10 import org.apache.axis.Message; 11 import org.apache.axis.MessageContext; 12 import org.apache.axis.attachments.AttachmentPart; 13 import org.apache.axis.attachments.Attachments; 14 15 import javax.activation.DataHandler ; 16 import javax.mail.internet.MimeBodyPart ; 17 import java.util.Iterator ; 18 19 24 public class SwaBindingImpl implements samples.swa.SwaPort { 25 26 34 public java.lang.String swaSend( 35 java.lang.String applicationName, javax.mail.internet.MimeMultipart content) 36 throws java.rmi.RemoteException { 37 38 MimeBodyPart mpb = null; 39 40 System.out.println("Application: " + applicationName); 41 42 70 try { 71 int contCount = content.getCount(); 72 73 System.out.println("Number of Mimeparts: " + contCount); 74 75 for (int i = 0; i < contCount; i++) { 76 mpb = (MimeBodyPart ) content.getBodyPart(i); 77 78 DataHandler dh = mpb.getDataHandler(); 79 80 System.out.println("Mime data type: " + dh.getContentType()); 81 } 82 } catch (javax.mail.MessagingException ex) { 83 } 84 85 88 AttachmentPart[] attParts = getMessageAttachments(); 89 90 System.out.println("Number of attachements: " + attParts.length); 91 92 if (attParts.length > 0) { 93 try { 94 System.out.println("Att[0] type: " 95 + attParts[0].getContentType()); 96 System.out.println( 97 "Att[0] dh type: " 98 + attParts[0].getDataHandler().getContentType()); 99 System.out.println("Att[0] file: " 100 + attParts[0].getAttachmentFile()); 101 } catch (javax.xml.soap.SOAPException ex) { 102 } 103 } 104 105 108 109 113 MessageContext msgContext = MessageContext.getCurrentContext(); 114 Message reqMsg = msgContext.getRequestMessage(); 115 Attachments messageAttachments = reqMsg.getAttachmentsImpl(); 116 117 messageAttachments.dispose(); 118 119 return null; 120 } 121 122 130 private AttachmentPart[] getMessageAttachments() throws AxisFault { 131 132 MessageContext msgContext = MessageContext.getCurrentContext(); 133 Message reqMsg = msgContext.getRequestMessage(); 134 Attachments messageAttachments = reqMsg.getAttachmentsImpl(); 135 int attachmentCount = 136 messageAttachments.getAttachmentCount(); 137 AttachmentPart attachments[] = new AttachmentPart[attachmentCount]; 138 Iterator it = 139 messageAttachments.getAttachments().iterator(); 140 int count = 0; 141 142 while (it.hasNext()) { 143 AttachmentPart part = (AttachmentPart) it.next(); 144 attachments[count++] = part; 145 } 146 return attachments; 147 } 148 } 149 | Popular Tags |