uCosminexus Application Server, Web Service Development Guide

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

28.5.2 Method of obtaining the attachment data (wsi:swaRef format)

This subsection describes about how to obtain the attachment data. The "dhandler" indicated in each example shows the received javax.activation.DataHandler object.

Organization of this subsection
(1) Method of obtaining an attachment as a java.io.InputStream object
(2) Method of obtaining an attachment as a javax.activation.DataSource object
(3) Method of obtaining an attachment as a Java object
(4) Method of obtaining an attachment as a java.lang.String object
(5) Notes when acquiring a javax.activation.DataHandler object

(1) Method of obtaining an attachment as a java.io.InputStream object

To obtain the received attachment as the java.io.InputStream object, obtain the java.io.InputStream object using the getInputStream method from the received javax.activation.DataHandler object.

java.io.InputStream stream = dhandler.getInputStream();

(2) Method of obtaining an attachment as a javax.activation.DataSource object

To obtain the received attachment as the javax.activation.DataSource object, obtain the javax.activation.DataSource object linked using the getDataSource method from the received javax.activation.DataHandler object.

javax.activation.DataSource datasource = dhandler.getDataSource();

(3) Method of obtaining an attachment as a Java object

The procedure for obtaining the received attachment as a Java object is as follows. An example of obtaining the java.awt.Image object is described here.

  1. Obtain the attachment data as an object.
    Obtain the object using the getContent method from the received javax.activation.DataHandler object.
    java.lang.Object content = dhandler.getContent();
  2. Obtain the MIME type of the attachment.
    Execute the getContentType method for the received javax.activation.DataHandler object. By executing the getContentType method, you can obtain the MIME type of the attachment.
    java.lang.String mimetype = dhandler.getContentType();
     
    Obtained-mimetype-contents image/jpeg
  3. Cast the object to the appropriate type.
    Cast the object to the appropriate type according to the MIME type of the attachment.
    java.awt.Image attachment = (java.awt.Image) content;

(4) Method of obtaining an attachment as a java.lang.String object

To obtain the received attachment as a Java object:

  1. Obtain the attachment data as an object.
    Obtain the object using the getContent method from the received javax.activation.DataHandler object.
    java.lang.Object content = dhandler.getContent();
  2. Obtain the MIME type of the attachment.
    Execute the getContentType method for the received javax.activation.DataHandler object. By executing the getContentType method, you can obtain the MIME type and character code of the attachment.
    java.lang.String mimetype = dhandler.getContentType();
     
    Obtained-mimetype-contents text/plain; charset=UTF-8
  3. Cast the object to the appropriate type.
    Cast the object to the appropriate type according to the MIME type of the attachment.
    java.lang.String attachment = (java.lang.String) content;

(5) Notes when acquiring a javax.activation.DataHandler object

Receiving a SOAP message of the MIME Multipart or related structure that contains an attachment of the wsi:swaRef format enables you to handle the SOAP messages as an attachment of the streamed wsi:swaRef format. Because the receiving process requires all the data to be imported from the input stream of the javax.activation.DataHandler object to completely receive the attachment of the wsi: swaRef format, the sender is in stand-by status until all the data is imported from the input stream.To resolve this condition, you must either import all the data from the java.io.InputStream object of the javax.activation.DataHandler object or write the data from the input stream to the output stream by using the writeTo(java.io.OutputStream) method of the javax.activation.DataHandler class.