uCosminexus Application Server, Web Service Development Guide

[Contents][Glossary][Index][Back][Next]

22.1.17 Support range for using attachments

With a Web Service developed by using Provider Implementation Class or a dispatch-based Web Service client, you can generate and send or receive SOAP messages with attachments according to the SAAJ specifications. The size and number of attachments that can be sent and received at a time changes according to the amount of memory of the execution environment, but there are no restrictions. If you increase the amount of memory, you can also send and receive large attachments or a large number of attachments at a time.

For details on the memory usage when an attachment is sent and received, see the appendix C.3 Memory usage per request when attachments are used.

Organization of this subsection
(1) MIME type
(2) Notes on reading attachments
(3) Notes on using DOM APIs
(4) Notes on attaching multiple files

(1) MIME type

The MIME types corresponding to the attachments are determined according to the attachment extensions. If the MIME type of the attachment is not clearly specified, an appropriate MIME type is automatically set up according to the attachment extension. When the MIME type is clearly specified using methods such as the AttachmentPart#setContentType() method, you must specify an appropriate MIME type corresponding to the attachment extension. If an invalid MIME type is specified, the operations are not guaranteed.

The following table lists the appropriate combinations of the attachment extensions and the MIME types. For extensions other than those listed in the following table, the MIME type used is application/octet-stream.

Table 22-3 Attachment extensions and MIME types

No. Attachment extensions Corresponding MIME types
1 html, htm text/html
2 txt, text text/plain
3 gif, GIF image/gif
4 ief image/ief
5 jpeg, jpg, jpe, JPG image/jpeg
6 tiff, tif image/tiff
7 xwd image/x-xwindowdump
8 ai, eps, ps application/postscript
9 rtf application/rtf
10 tex application/x-tex
11 texinfo, texi application/x-texinfo
12 t, tr, roff application/x-troff
13 au audio/basic
14 midi, mid audio/midi
15 aifc audio/x-aifc
16 aif, aiff audio/x-aiff
17 wav audio/x-wav
18 mpeg, mpg, mpe video/mpeg
19 qt, mov video/quicktime
20 avi video/x-msvideo

(2) Notes on reading attachments

To read a file and then send or receive the file as an attachment, you must specify the object read using javax.activation.FileDataSource in the attachment instead of the object read using java.io.FileInputStream. An example is as follows:

 
AttachmentPart apPart = request.createAttachmentPart();
FileDataSource source = new FileDataSource("D:\\attachment.txt");
apPart.setDataHandler(new DataHandler(source));
request.addAttachmentPart(apPart);
 

The operations are not guaranteed if an object read using java.io.FileInputStream is specified.

(3) Notes on using DOM APIs

When you use the DOM APIs to create the SOAP messages, do not use the following methods. If used, the operations are not guaranteed.

(4) Notes on attaching multiple files

To send multiple attachments at one time, you must set up a unique Content-ID for every AttachmentPart object. If you attempt to send multiple attachments without specifying Content-ID or by specifying duplicated Content-IDs, only the attachment specified last is sent.

The following is an example of setting up a unique Content-ID for multiple AttachmentPart objects:

 
AttachmentPart apPart1 = request.createAttachmentPart();
FileDataSource source1 = new FileDataSource("D:\\attachment1.txt");
apPart1.setDataHandler(new DataHandler(source1));
apPart1.setContentId("001");
request.addAttachmentPart(apPart1);
 
AttachmentPart apPart2 = request.createAttachmentPart();
FileDataSource source2 = new FileDataSource("D:\\attachment2.txt");
apPart2.setDataHandler(new DataHandler(source2));
apPart2.setContentId("002");
request.addAttachmentPart(apPart2);
 
AttachmentPart apPart3 = request.createAttachmentPart();
FileDataSource source3 = new FileDataSource("D:\\attachment3.txt");
apPart3.setDataHandler(new DataHandler(source3));
apPart3.setContentId("003");
request.addAttachmentPart(apPart3);