uCosminexus Application Server, Web Service Development Guide
The javax.activation.DataHandler object is generated as an attachment object. The following table lists the constructors of the javax.activation.DataHandler class:
Table 28-10 Constructors of the javax.activation.DataHandler class
| No. | Use case | Constructor | Description of the argument |
|---|---|---|---|
| 1 | Attaching a file | DataHandler(javax.activation.DataSource ds) | [First argument] This is the javax.activation.DataSource object. The object of the javax.activation.FileDataSource class can be specified. |
| 2 | Attaching an object that is on memory | DataHandler(java.lang.Object obj, java.lang.String mimeType) | [First argument] This is the Java object. [Second argument] This is the MIME type of the object. For details about the MIME type that can be specified, see 28.4.2(3) Mapping between the attachment extension and MIME types. |
Depending on the objects sent as attachments, the method of generating the javax.activation.DataHandler object is different. The following points describe the generation method for each object to be sent:
To attach and send an existing file:
javax.activation.FileDataSource fdSource =
new javax.activation.FileDataSource("/tmp/sample.jpg");
|
javax.activation.DataHandler dhandler = new javax.activation.DataHandler(fdSource); |
To send a Java object as an attachment:
java.awt.Image attachments =
Toolkit.getDefaultToolkit().createImage("sample.jpg");
|
javax.activation.DataHandler dhandler = new javax.activation.DataHandler(attachments, "image/jpeg"); |
To send the java.lang.String object as an attachment:
java.lang.String attachments = new java.lang.String("abcde");
|
javax.activation.DataHandler dhandler = new javax.activation.DataHandler(attachments, "text/plain; charset=UTF-8"); |
If the object that you want to send as an attachment in the wsi:swaRef format is a text file, an XML file, or a java.lang.String object (string), you can specify the character code of the string included in the object by using the DataHandler (Object, String) constructor of the javax.activation.DataHandler class.
If you do not specify the character code when creating the javax.activation.DataHandler object, the object to be sent is encoded by the default character code (US-ASCII). If the object contains characters other than the default character code (US-ASCII), the attachment that is sent is treated as invalid. Therefore, specify an appropriate character code especially when you want to include Japanese characters.
If the object to be sent is an XML file, the character code specified in the XML declaration is not used. The XML file is encoded using the default character code (US-ASCII), or the character code specified when creating the javax.activation.DataHandler object, and then sent.
To specify a character code, assign the charset parameter to the MIME type of the object to be specified in the second argument of the DataHandler(Object, String) constructor. The following is the coding format of the second argument of the DataHandler(Object, String) constructor.
Mime type of the object to be sent+";"+"charset"+"="+character code# |
All Rights Reserved. Copyright (C) 2013, Hitachi, Ltd.