KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > axis > Message


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.jboss.axis;
18
19 import org.jboss.axis.attachments.AttachmentSupport;
20 import org.jboss.axis.attachments.Attachments;
21 import org.jboss.axis.message.MimeHeadersImpl;
22 import org.jboss.axis.message.SOAPEnvelopeAxisImpl;
23 import org.jboss.axis.message.SOAPMessageAxisImpl;
24 import org.jboss.axis.soap.SOAPConstants;
25 import org.jboss.axis.transport.http.HTTPConstants;
26 import org.jboss.axis.utils.Messages;
27 import org.jboss.axis.utils.XMLUtils;
28 import org.jboss.logging.Logger;
29
30 import javax.xml.soap.AttachmentPart JavaDoc;
31 import javax.xml.soap.SOAPBody JavaDoc;
32 import javax.xml.soap.SOAPException JavaDoc;
33 import javax.xml.soap.SOAPHeader JavaDoc;
34 import javax.xml.soap.SOAPMessage JavaDoc;
35 import java.io.BufferedWriter JavaDoc;
36 import java.io.IOException JavaDoc;
37 import java.io.OutputStreamWriter JavaDoc;
38 import java.io.Writer JavaDoc;
39 import java.lang.reflect.Constructor JavaDoc;
40 import java.lang.reflect.InvocationTargetException JavaDoc;
41 import java.util.Collections JavaDoc;
42 import java.util.Iterator JavaDoc;
43
44 /**
45  * A complete SOAP (and/or XML-RPC, eventually) message.
46  * Includes both the root part (as a SOAPPart), and zero or
47  * more MIME attachments (as AttachmentParts).
48  * <p/>
49  * Eventually should be refactored to generalize SOAPPart
50  * for multiple protocols (XML-RPC?).
51  *
52  * @author Rob Jellinghaus (robj@unrealities.com)
53  * @author Doug Davis (dug@us.ibm.com)
54  * @author Glen Daniels (gdaniels@allaire.com)
55  * @author Rick Rineholt
56  * @author Heejune Ahn (cityboy@tmax.co.kr)
57  */

58 public class Message extends SOAPMessageAxisImpl
59 {
60    /**
61     * The <code>Log</code> that this class uses for logging all messages.
62     */

63    private static Logger log = Logger.getLogger(Message.class.getName());
64
65    /**
66     * Message is a request.
67     */

68    public static final String JavaDoc REQUEST = "request";
69
70    /**
71     * Message is a a response.
72     */

73    public static final String JavaDoc RESPONSE = "response";
74
75    /**
76     * MIME parts defined for messages.
77     */

78    public static final String JavaDoc MIME_MULTIPART_RELATED = "multipart/related";
79
80    /**
81     * DIME parts defined for messages.
82     */

83    public static final String JavaDoc MIME_APPLICATION_DIME = "application/dime";
84
85    /**
86     * Default Attachments Implementation class.
87     */

88    public static final String JavaDoc DEFAULT_ATTACHMNET_IMPL = "org.jboss.axis.attachments.AttachmentsImpl";
89
90    /**
91     * Current Attachment implementation.
92     */

93    private static String JavaDoc mAttachmentsImplClassName = DEFAULT_ATTACHMNET_IMPL;
94
95    /**
96     * Look at the input stream to find the headers to decide the mime type.
97     */

98    public static final String JavaDoc MIME_UNKNOWN = " ";
99
100    // fixme: is this constrained to two values - request/response (e.g.
101
// REQUEST and RESPONSE)? If so, this needs documenting in the get/set
102
// methods and/or converting into a type-safe e-num. Potentially get/set
103
// methods should check these values & throw IllegalArgumentException
104
/**
105     * The messageType indicates whether this is request or response.
106     */

107    private String JavaDoc messageType;
108
109    /**
110     * This Message's SOAPPart. Will always be here.
111     */

112    private MessagePart mSOAPPart;
113
114    /**
115     * This Message's Attachments object, which manages the attachments
116     * contained in this Message.
117     */

118    private Attachments mAttachments = null;
119
120    private MimeHeadersImpl headers;
121
122    private boolean saveRequired = true;
123
124    /**
125     * Returns the name of the class prividing Attachment Implementation.
126     *
127     * @return class name
128     */

129    public static String JavaDoc getAttachmentImplClassName()
130    {
131       return mAttachmentsImplClassName;
132    }
133
134    private MessageContext msgContext;
135
136    /**
137     * Get the message type.
138     *
139     * @return the message type <code>String</code>
140     */

141    public String JavaDoc getMessageType()
142    {
143       return messageType;
144    }
145
146    /**
147     * Set the message type.
148     *
149     * @param messageType the message type <code>String</code>
150     */

151    public void setMessageType(String JavaDoc messageType)
152    {
153       this.messageType = messageType;
154    }
155
156    /**
157     * Get the context associated with this message.
158     *
159     * @return the message context for this message
160     */

161    public MessageContext getMessageContext()
162    {
163       return msgContext;
164    }
165
166    /**
167     * Set the context associated with this message.
168     *
169     * @param msgContext the message context for this message
170     */

171    public void setMessageContext(MessageContext msgContext)
172    {
173       this.msgContext = msgContext;
174    }
175
176    /**
177     * Construct a Message, using the provided initialContents as the
178     * contents of the Message's SOAPPart.
179     * <p/>
180     * Eventually, genericize this to
181     * return the RootPart instead, which will have some kind of
182     * EnvelopeFactory to enable support for things other than SOAP.
183     * But that all will come later, with lots of additional refactoring.
184     *
185     * @param initialContents may be String, byte[], InputStream, SOAPEnvelope,
186     * or AxisFault.
187     * @param bodyInStream is true if initialContents is an InputStream
188     * containing just the SOAP body (no SOAP-ENV).
189     */

190    public Message(Object JavaDoc initialContents, boolean bodyInStream)
191    {
192       setup(initialContents, bodyInStream, null, null, null);
193    }
194
195    /**
196     * Construct a Message, using the provided initialContents as the
197     * contents of the Message's SOAPPart.
198     * <p/>
199     * Eventually, genericize this to
200     * return the RootPart instead, which will have some kind of
201     * EnvelopeFactory to enable support for things other than SOAP.
202     * But that all will come later, with lots of additional refactoring.
203     *
204     * @param initialContents may be String, byte[], InputStream, SOAPEnvelope,
205     * or AxisFault.
206     * @param bodyInStream is true if initialContents is an InputStream
207     * containing just the SOAP body (no SOAP-ENV).
208     * @param headers Mime Headers.
209     */

210    public Message(Object JavaDoc initialContents, boolean bodyInStream, javax.xml.soap.MimeHeaders JavaDoc headers)
211    {
212       setup(initialContents, bodyInStream, null, null, headers);
213    }
214
215    /**
216     * Construct a Message, using the provided initialContents as the
217     * contents of the Message's SOAPPart.
218     * <p/>
219     * Eventually, genericize this to
220     * return the RootPart instead, which will have some kind of
221     * EnvelopeFactory to enable support for things other than SOAP.
222     * But that all will come later, with lots of additional refactoring.
223     *
224     * @param initialContents may be String, byte[], InputStream, SOAPEnvelope,
225     * or AxisFault.
226     * @param headers Mime Headers.
227     */

228    public Message(Object JavaDoc initialContents, MimeHeadersImpl headers)
229    {
230       setup(initialContents, true, null, null, headers);
231    }
232
233    /**
234     * Construct a Message, using the provided initialContents as the
235     * contents of the Message's SOAPPart.
236     * <p/>
237     * Eventually, genericize this to
238     * return the RootPart instead, which will have some kind of
239     * EnvelopeFactory to enable support for things other than SOAP.
240     * But that all will come later, with lots of additional refactoring.
241     *
242     * @param initialContents may be String, byte[], InputStream, SOAPEnvelope,
243     * or AxisFault
244     * @param bodyInStream is true if initialContents is an InputStream
245     * containing just the SOAP body (no SOAP-ENV)
246     * @param contentType this if the contentType has been already determined
247     * (as in the case of servlets)
248     * @param contentLocation the location of the content
249     */

250    public Message(Object JavaDoc initialContents,
251                   boolean bodyInStream,
252                   String JavaDoc contentType,
253                   String JavaDoc contentLocation)
254    {
255       setup(initialContents, bodyInStream, contentType, contentLocation, null);
256    }
257
258    /**
259     * Construct a Message. An overload of Message(Object, boolean),
260     * defaulting bodyInStream to false.
261     *
262     * @param initialContents may be String, byte[], InputStream, SOAPEnvelope,
263     * or AxisFault
264     */

265    public Message(Object JavaDoc initialContents)
266    {
267       setup(initialContents, false, null, null, null);
268    }
269
270    /**
271     * Do the work of construction.
272     *
273     * @param initialContents may be String, byte[], InputStream, SOAPEnvelope,
274     * or AxisFault
275     * @param bodyInStream is true if initialContents is an InputStream
276     * containing just the SOAP body (no SOAP-ENV)
277     * @param contentType this if the contentType has been already determined
278     * (as in the case of servlets)
279     * @param contentLocation the location of the content
280     * @param mimeHeaders mime headers for attachments
281     */

282    private void setup(Object JavaDoc initialContents, boolean bodyInStream,
283                       String JavaDoc contentType, String JavaDoc contentLocation,
284                       javax.xml.soap.MimeHeaders JavaDoc mimeHeaders)
285    {
286
287       if (contentType == null && mimeHeaders != null)
288       {
289          String JavaDoc contentTypes[] = mimeHeaders.getHeader("Content-Type");
290          contentType = (contentTypes != null) ? contentTypes[0] : null;
291       }
292       if (contentLocation == null && mimeHeaders != null)
293       {
294          String JavaDoc contentLocations[] = mimeHeaders.getHeader("Content-Location");
295          contentLocation = (contentLocations != null) ? contentLocations[0] : null;
296       }
297       if (contentType != null)
298       {
299          int delimiterIndex = contentType.lastIndexOf("charset");
300          if (delimiterIndex > 0)
301          {
302             String JavaDoc charsetPart = contentType.substring(delimiterIndex);
303             int charsetIndex = charsetPart.indexOf('=');
304             String JavaDoc charset = charsetPart.substring(charsetIndex + 1).trim();
305             if ((charset.startsWith("\"") && charset.endsWith("\""))
306                     || (charset.startsWith("'") && charset.endsWith("'")))
307             {
308                charset = charset.substring(1, charset.length() - 1);
309             }
310             try
311             {
312                setProperty(SOAPMessage.CHARACTER_SET_ENCODING, charset);
313             }
314             catch (SOAPException JavaDoc e)
315             {
316             }
317          }
318       }
319       // Try to construct an AttachmentsImpl object for attachment
320
// functionality.
321
// If there is no org.jboss.axis.attachments.AttachmentsImpl class,
322
// it must mean activation.jar is not present and attachments are not
323
// supported.
324
if (AttachmentSupport.isAttachmentSupportEnabled(getMessageContext()))
325       {
326          // Construct one, and cast to Attachments.
327
// There must be exactly one constructor of AttachmentsImpl, which
328
// must take an org.jboss.axis.Message!
329
Class JavaDoc attachImpl = AttachmentSupport.getImplementationClass();
330          Constructor JavaDoc attachImplConstr = attachImpl.getConstructors()[0];
331          try
332          {
333             mAttachments = (Attachments)attachImplConstr.newInstance(new Object JavaDoc[]{initialContents,
334                                                                                   contentType, contentLocation});
335
336             //If it can't support it, it wont have a root part.
337
mSOAPPart = (MessagePart)mAttachments.getRootPart();
338          }
339          catch (InvocationTargetException JavaDoc ex)
340          {
341             log.fatal(Messages.getMessage("invocationTargetException00"),
342                     ex);
343             throw new RuntimeException JavaDoc(ex.getMessage());
344          }
345          catch (InstantiationException JavaDoc ex)
346          {
347             log.fatal(Messages.getMessage("instantiationException00"),
348                     ex);
349             throw new RuntimeException JavaDoc(ex.getMessage());
350          }
351          catch (IllegalAccessException JavaDoc ex)
352          {
353             log.fatal(Messages.getMessage("illegalAccessException00"),
354                     ex);
355             throw new RuntimeException JavaDoc(ex.getMessage());
356          }
357       }
358       else if (contentType != null && contentType.startsWith("multipart"))
359       {
360          throw new RuntimeException JavaDoc(Messages.getMessage("noAttachments"));
361       }
362
363       // text/xml
364
if (null == mSOAPPart)
365       {
366          mSOAPPart = new MessagePart(this, initialContents, bodyInStream);
367       }
368       else
369          mSOAPPart.setMessage(this);
370
371       // The stream was not determined by a more complex type so default to
372
if (mAttachments != null) mAttachments.setRootPart(mSOAPPart);
373
374       headers = (mimeHeaders == null) ? new MimeHeadersImpl() : new MimeHeadersImpl(mimeHeaders);
375    }
376
377    /**
378     * Get this message's SOAPPart.
379     * <p/>
380     * Eventually, this should be generalized beyond just SOAP,
381     * but it's hard to know how to do that without necessitating
382     * a lot of casts in client code. Refactoring keeps getting
383     * easier anyhow.
384     *
385     * @return the soap part of this message
386     */

387    public javax.xml.soap.SOAPPart JavaDoc getSOAPPart()
388    {
389       return mSOAPPart;
390    }
391
392    // fixme: do we realy need this? Can client code not just call
393
// getSOAPPart().getAsString() or is there some future optimization that
394
// could be hooked in here?
395
/**
396     * Get a string representation of this message's SOAPPart.
397     *
398     * @return the soap part of this message as a <code>String</code>
399     * @throws org.jboss.axis.AxisFault if the stringification failed
400     */

401    public String JavaDoc getSOAPPartAsString() throws org.jboss.axis.AxisFault
402    {
403       return mSOAPPart.getAsString();
404    }
405
406    // fixme: do we realy need this? Can client code not just call
407
// getSOAPPart().getAsBytes() or is there some future optimization that
408
// could be hooked in here?
409
/**
410     * Get a byte array representation of this message's SOAPPart.
411     *
412     * @return the soap part of this message as a <code>byte[]</code>
413     * @throws org.jboss.axis.AxisFault if creating the byte[] failed
414     */

415    public byte[] getSOAPPartAsBytes() throws org.jboss.axis.AxisFault
416    {
417       return mSOAPPart.getAsBytes();
418    }
419
420    /**
421     * Get this message's SOAPPart as a SOAPEnvelope.
422     *
423     * @return a SOAPEnvelope containing this message's SOAPPart
424     * @throws AxisFault if this failed
425     */

426    public SOAPEnvelopeAxisImpl getSOAPEnvelope() throws AxisFault
427    {
428       return mSOAPPart.getAsSOAPEnvelope();
429    }
430
431    /**
432     * Get the Attachments of this Message.
433     * <p/>
434     * If this returns null, then NO ATTACHMENT SUPPORT EXISTS in this
435     * configuration of Axis, and no attachment operations may be
436     * performed.
437     *
438     * @return the <code>Attachments</code> if attachments are supported, null
439     * otherwise
440     */

441    public Attachments getAttachmentsImpl()
442    {
443       return mAttachments;
444    }
445
446    /**
447     * Get the content type of the attachments.
448     *
449     * @param sc provides the default content type
450     * @return a <code>String</code> giving the content type of the
451     * attachment
452     * @throws AxisFault if there was an error deducing the content type from
453     * this message
454     */

455    public String JavaDoc getContentType(SOAPConstants sc) throws AxisFault
456    {
457
458       int sendType = Attachments.SEND_TYPE_NOTSET;
459       if ((msgContext != null) && (msgContext.getService() != null))
460       {
461          sendType = msgContext.getService().getSendType();
462       }
463
464       if (sendType != Attachments.SEND_TYPE_NONE)
465       {
466          //Force serialization if it hasn't happend it.
467
//Rick Rineholt fix this later.
468
//Heejune added null check.
469
if (mSOAPPart != null)
470          {
471             mSOAPPart.getAsBytes();
472          }
473       }
474
475       // The origional logic is very simple
476
// String ret = sc.getContentType() + "; charset="+XMLUtils.getEncoding().toLowerCase();
477
// The following logic is devised to utilize CHARACTER_SET_ENCODING property from SAAJ 1.2.
478
String JavaDoc encoding = null;
479       try
480       {
481          encoding = (String JavaDoc)getProperty(SOAPMessage.CHARACTER_SET_ENCODING);
482       }
483       catch (SOAPException JavaDoc ignore)
484       {
485       }
486       if (encoding == null)
487       {
488          encoding = XMLUtils.getEncoding().toLowerCase();
489       }
490
491       String JavaDoc ret = sc.getContentType();
492
493       // Support of SOAP 1.2 HTTP binding
494
SOAPEnvelopeAxisImpl envelope = getSOAPEnvelope();
495       if (envelope != null)
496       {
497          if (envelope.getSOAPConstants() == SOAPConstants.SOAP12_CONSTANTS)
498          {
499             ret = HTTPConstants.HEADER_ACCEPT_APPL_SOAP + "; charset=" + encoding;
500          }
501       }
502
503       if (mAttachments != null && 0 != mAttachments.getAttachmentCount())
504       {
505          ret = mAttachments.getContentType();
506       }
507
508       return ret;
509    }
510
511    //This will have to give way someday to HTTP Chunking but for now kludge.
512
/**
513     * Get the content length, including both soap and any attachments.
514     *
515     * @return the total length of this message in bytes
516     * @throws org.jboss.axis.AxisFault if there was a problem that prevented
517     * the length being calculated
518     */

519    public long getContentLength() throws org.jboss.axis.AxisFault
520    {
521       long ret = mSOAPPart.getAsBytes().length;
522       if (mAttachments != null && 0 < mAttachments.getAttachmentCount())
523       {
524          ret = mAttachments.getContentLength();
525       }
526       return ret;
527    }
528
529    /**
530     * Writes this <CODE>SOAPMessage</CODE> object to the given
531     * output stream. The externalization format is as defined by
532     * the SOAP 1.1 with Attachments specification.
533     * <p/>
534     * <P>If there are no attachments, just an XML stream is
535     * written out. For those messages that have attachments,
536     * <CODE>writeTo</CODE> writes a MIME-encoded byte stream.</P>
537     *
538     * @param os the <CODE>OutputStream</CODE>
539     * object to which this <CODE>SOAPMessage</CODE> object will
540     * be written
541     * @throws SOAPException if there was a problem in
542     * externalizing this SOAP message
543     * @throws IOException if an I/O error
544     * occurs
545     */

546    public void writeTo(java.io.OutputStream JavaDoc os) throws SOAPException JavaDoc, IOException JavaDoc
547    {
548       //Do it the old fashion way.
549
if (mAttachments == null || 0 == mAttachments.getAttachmentCount())
550       {
551          try
552          {
553             String JavaDoc charEncoding = (String JavaDoc)getProperty(SOAPMessage.CHARACTER_SET_ENCODING);
554             if (charEncoding == null)
555             {
556                charEncoding = "UTF-8";
557             }
558             Writer JavaDoc writer = new OutputStreamWriter JavaDoc(os, charEncoding);
559             writer = new BufferedWriter JavaDoc(writer);
560
561             // write the xml declaration header
562
String JavaDoc incXMLDecl = (String JavaDoc)getProperty(SOAPMessage.WRITE_XML_DECLARATION);
563             if (incXMLDecl == null)
564             {
565                incXMLDecl = "false";
566             }
567             if (incXMLDecl.equalsIgnoreCase("true"))
568             {
569                writer.write("<?xml version=\"1.0\" encoding=\"" + charEncoding + "\"?>");
570             }
571             mSOAPPart.writeTo(writer);
572             writer.flush();
573          }
574          catch (java.io.IOException JavaDoc e)
575          {
576             log.error(Messages.getMessage("javaIOException00"), e);
577          }
578       }
579       else
580       {
581          try
582          {
583             mAttachments.writeContentToStream(os);
584          }
585          catch (java.lang.Exception JavaDoc e)
586          {
587             log.error(Messages.getMessage("exception00"), e);
588          }
589       }
590    }
591
592    private java.util.Hashtable JavaDoc mProps = new java.util.Hashtable JavaDoc();
593
594    public SOAPBody JavaDoc getSOAPBody() throws SOAPException JavaDoc
595    {
596       return mSOAPPart.getEnvelope().getBody();
597    }
598
599    public SOAPHeader JavaDoc getSOAPHeader() throws SOAPException JavaDoc
600    {
601       return mSOAPPart.getEnvelope().getHeader();
602    }
603
604    public void setProperty(String JavaDoc property, Object JavaDoc value) throws SOAPException JavaDoc
605    {
606       mProps.put(property, value);
607    }
608
609    public Object JavaDoc getProperty(String JavaDoc property) throws SOAPException JavaDoc
610    {
611       return mProps.get(property);
612    }
613
614    /**
615     * Retrieves a description of this <CODE>SOAPMessage</CODE>
616     * object's content.
617     *
618     * @return a <CODE>String</CODE> describing the content of this
619     * message or <CODE>null</CODE> if no description has been
620     * set
621     * @see #setContentDescription(java.lang.String) setContentDescription(java.lang.String)
622     */

623    public String JavaDoc getContentDescription()
624    {
625       String JavaDoc values[] = headers.getHeader(HTTPConstants.HEADER_CONTENT_DESCRIPTION);
626       if (values != null && values.length > 0)
627          return values[0];
628       return null;
629    }
630
631    /**
632     * Sets the description of this <CODE>SOAPMessage</CODE>
633     * object's content with the given description.
634     *
635     * @param description a <CODE>String</CODE>
636     * describing the content of this message
637     * @see #getContentDescription() getContentDescription()
638     */

639    public void setContentDescription(String JavaDoc description)
640    {
641       headers.setHeader(HTTPConstants.HEADER_CONTENT_DESCRIPTION, description);
642    }
643
644    /**
645     * Updates this <CODE>SOAPMessage</CODE> object with all the
646     * changes that have been made to it. This method is called
647     * automatically when a message is sent or written to by the
648     * methods <CODE>ProviderConnection.send</CODE>, <CODE>
649     * SOAPConnection.call</CODE>, or <CODE>
650     * SOAPMessage.writeTo</CODE>. However, if changes are made to
651     * a message that was received or to one that has already been
652     * sent, the method <CODE>saveChanges</CODE> needs to be
653     * called explicitly in order to save the changes. The method
654     * <CODE>saveChanges</CODE> also generates any changes that
655     * can be read back (for example, a MessageId in profiles that
656     * support a message id). All MIME headers in a message that
657     * is created for sending purposes are guaranteed to have
658     * valid values only after <CODE>saveChanges</CODE> has been
659     * called.
660     * <p/>
661     * <P>In addition, this method marks the point at which the
662     * data from all constituent <CODE>AttachmentPart</CODE>
663     * objects are pulled into the message.</P>
664     *
665     * @throws SOAPException if there
666     * was a problem saving changes to this message.
667     */

668    public void saveChanges() throws SOAPException JavaDoc
669    {
670       if (mAttachments != null && 0 < mAttachments.getAttachmentCount())
671       {
672          try
673          {
674             headers.setHeader("Content-Type", mAttachments.getContentType());
675          }
676          catch (AxisFault af)
677          {
678             log.error(Messages.getMessage("exception00"), af);
679          }
680       }
681       saveRequired = false;
682       try
683       {
684          /* Fix for Bug 16418 - Start from scratch */
685          getSOAPPartAsString();
686       }
687       catch (AxisFault axisFault)
688       {
689          log.error(Messages.getMessage("exception00"), axisFault);
690       }
691    }
692
693    /**
694     * Indicates whether this <CODE>SOAPMessage</CODE> object
695     * has had the method <CODE>saveChanges</CODE> called on
696     * it.
697     *
698     * @return <CODE>true</CODE> if <CODE>saveChanges</CODE> has
699     * been called on this message at least once; <CODE>
700     * false</CODE> otherwise.
701     */

702    public boolean saveRequired()
703    {
704       return saveRequired;
705    }
706
707    /**
708     * Returns all the transport-specific MIME headers for this
709     * <CODE>SOAPMessage</CODE> object in a transport-independent
710     * fashion.
711     *
712     * @return a <CODE>MimeHeaders</CODE> object containing the
713     * <CODE>MimeHeader</CODE> objects
714     */

715    public javax.xml.soap.MimeHeaders JavaDoc getMimeHeaders()
716    {
717       return headers;
718    }
719
720    /**
721     * Removes all <CODE>AttachmentPart</CODE> objects that have
722     * been added to this <CODE>SOAPMessage</CODE> object.
723     * <p/>
724     * <P>This method does not touch the SOAP part.</P>
725     */

726    public void removeAllAttachments()
727    {
728       mAttachments.removeAllAttachments();
729    }
730
731    /**
732     * Gets a count of the number of attachments in this
733     * message. This count does not include the SOAP part.
734     *
735     * @return the number of <CODE>AttachmentPart</CODE> objects
736     * that are part of this <CODE>SOAPMessage</CODE>
737     * object
738     */

739    public int countAttachments()
740    {
741       return mAttachments == null ? 0 : mAttachments.getAttachmentCount();
742    }
743
744    /**
745     * Retrieves all the <CODE>AttachmentPart</CODE> objects
746     * that are part of this <CODE>SOAPMessage</CODE> object.
747     *
748     * @return an iterator over all the attachments in this
749     * message
750     */

751    public Iterator JavaDoc getAttachments()
752    {
753       try
754       {
755          if (mAttachments != null && 0 != mAttachments.getAttachmentCount())
756          {
757             return mAttachments.getAttachments().iterator();
758          }
759       }
760       catch (AxisFault af)
761       {
762          log.error(Messages.getMessage("exception00"), af);
763       }
764       return Collections.EMPTY_LIST.iterator();
765    }
766
767    /**
768     * Retrieves all the <CODE>AttachmentPart</CODE> objects
769     * that have header entries that match the specified headers.
770     * Note that a returned attachment could have headers in
771     * addition to those specified.
772     *
773     * @param headers a <CODE>MimeHeaders</CODE>
774     * object containing the MIME headers for which to
775     * search
776     * @return an iterator over all attachments that have a header
777     * that matches one of the given headers
778     */

779    public Iterator JavaDoc getAttachments(javax.xml.soap.MimeHeaders JavaDoc headers)
780    {
781       return mAttachments.getAttachments(headers);
782    }
783
784    /**
785     * Adds the given <CODE>AttachmentPart</CODE> object to this
786     * <CODE>SOAPMessage</CODE> object. An <CODE>
787     * AttachmentPart</CODE> object must be created before it can be
788     * added to a message.
789     *
790     * @param attachmentpart an <CODE>
791     * AttachmentPart</CODE> object that is to become part of
792     * this <CODE>SOAPMessage</CODE> object
793     * @throws java.lang.IllegalArgumentException
794     *
795     */

796    public void addAttachmentPart(AttachmentPart JavaDoc attachmentpart)
797    {
798       try
799       {
800          mAttachments.addAttachmentPart((org.jboss.axis.Part)attachmentpart);
801       }
802       catch (AxisFault af)
803       {
804          log.error(Messages.getMessage("exception00"), af);
805       }
806    }
807
808    /**
809     * Creates a new empty <CODE>AttachmentPart</CODE> object.
810     * Note that the method <CODE>addAttachmentPart</CODE> must be
811     * called with this new <CODE>AttachmentPart</CODE> object as
812     * the parameter in order for it to become an attachment to this
813     * <CODE>SOAPMessage</CODE> object.
814     *
815     * @return a new <CODE>AttachmentPart</CODE> object that can be
816     * populated and added to this <CODE>SOAPMessage</CODE>
817     * object
818     */

819    public AttachmentPart JavaDoc createAttachmentPart()
820    {
821       if (!AttachmentSupport.isAttachmentSupportEnabled(getMessageContext()))
822       {
823          throw new RuntimeException JavaDoc(Messages.getMessage("noAttachments"));
824       }
825
826       try
827       {
828          return (AttachmentPart JavaDoc)mAttachments.createAttachmentPart();
829       }
830       catch (AxisFault af)
831       {
832          log.error(Messages.getMessage("exception00"), af);
833       }
834       return null;
835    }
836
837    /**
838     * Dispose of attachments.
839     */

840    public void dispose()
841    {
842       if (mAttachments != null)
843       {
844          mAttachments.dispose();
845       }
846    }
847 }
848
Popular Tags