001: /**
002: * SwaBindingImpl.java
003: *
004: * This file was auto-generated from WSDL
005: * by the Apache Axis 1.2alpha Dec 07, 2003 (08:01:12 EST) WSDL2Java emitter.
006: */package samples.swa;
007:
008: import org.apache.axis.AxisFault;
009: import org.apache.axis.Message;
010: import org.apache.axis.MessageContext;
011: import org.apache.axis.attachments.AttachmentPart;
012: import org.apache.axis.attachments.Attachments;
013:
014: import javax.activation.DataHandler;
015: import javax.mail.internet.MimeBodyPart;
016: import java.util.Iterator;
017:
018: /**
019: * Class SwaBindingImpl
020: *
021: * @version %I%, %G%
022: */
023: public class SwaBindingImpl implements samples.swa.SwaPort {
024:
025: /**
026: * Method swaSend
027: *
028: * @param applicationName
029: * @param content
030: * @return
031: * @throws java.rmi.RemoteException
032: */
033: public java.lang.String swaSend(java.lang.String applicationName,
034: javax.mail.internet.MimeMultipart content)
035: throws java.rmi.RemoteException {
036:
037: MimeBodyPart mpb = null;
038:
039: System.out.println("Application: " + applicationName);
040:
041: /*
042: * Now do some printing to get information about the multipart
043: * content and the associated attachments. Axis performs
044: * several steps during deserialization of this SOAP
045: * call. Only the steps of interesst are described here.
046: *
047: * The MIME multipart that contains the other parts (because
048: * it's multipart/mixed or multipart/related) is handled as
049: * ONE Axis attachment during the first part of
050: * deserialization. This attachment is identified by the CID:
051: * prefixed string generated during serialization.
052: *
053: * The next step (see
054: * MimeMultipartDataHandlerDeserializer.java) gets the data
055: * handler of the Axis attachment and creates a MimeMultipart
056: * object using the data source as input of the new
057: * MimeMultipart object. The MimeMultipart object parses the
058: * input (on demand? -> this need to be clarified) and builds
059: * the associated body parts.
060: *
061: * The Axis attachment part is not disposed or otherwise
062: * managed after it was serialized into the MimeMultipart
063: * object. Therefore it is a good idea to call the dispose()
064: * method of the Axis attachment part after processing is
065: * complete. Doing so releases all used resources, also
066: * deleting disk cache files if necessary, of this attachment
067: * part.
068: */
069: try {
070: int contCount = content.getCount();
071:
072: System.out.println("Number of Mimeparts: " + contCount);
073:
074: for (int i = 0; i < contCount; i++) {
075: mpb = (MimeBodyPart) content.getBodyPart(i);
076:
077: DataHandler dh = mpb.getDataHandler();
078:
079: System.out.println("Mime data type: "
080: + dh.getContentType());
081: }
082: } catch (javax.mail.MessagingException ex) {
083: }
084:
085: /*
086: * the next prints are just for information only
087: */
088: AttachmentPart[] attParts = getMessageAttachments();
089:
090: System.out
091: .println("Number of attachements: " + attParts.length);
092:
093: if (attParts.length > 0) {
094: try {
095: System.out.println("Att[0] type: "
096: + attParts[0].getContentType());
097: System.out
098: .println("Att[0] dh type: "
099: + attParts[0].getDataHandler()
100: .getContentType());
101: System.out.println("Att[0] file: "
102: + attParts[0].getAttachmentFile());
103: } catch (javax.xml.soap.SOAPException ex) {
104: }
105: }
106:
107: /*
108: * Now process the parametes including the MimeMultipart
109: */
110:
111: /*
112: * Processing is done, now dispose the attachements. This is not done
113: * by Axis, should be done by service.
114: */
115: MessageContext msgContext = MessageContext.getCurrentContext();
116: Message reqMsg = msgContext.getRequestMessage();
117: Attachments messageAttachments = reqMsg.getAttachmentsImpl();
118:
119: messageAttachments.dispose();
120:
121: return null;
122: }
123:
124: /**
125: * extract attachments from the current request
126: *
127: * @return a list of attachmentparts or
128: * an empty array for no attachments support in this axis
129: * buid/runtime
130: * @throws AxisFault
131: */
132: private AttachmentPart[] getMessageAttachments() throws AxisFault {
133:
134: MessageContext msgContext = MessageContext.getCurrentContext();
135: Message reqMsg = msgContext.getRequestMessage();
136: Attachments messageAttachments = reqMsg.getAttachmentsImpl();
137: int attachmentCount = messageAttachments.getAttachmentCount();
138: AttachmentPart attachments[] = new AttachmentPart[attachmentCount];
139: Iterator it = 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: }
|