32.2.4 ストリーミングされた添付ファイルの操作

ストリーミングを使用しているときに添付ファイルを含むMIME Multipart/Related構造のSOAPメッセージを受信すると,JAX-WSでは受信した添付ファイルをjavax.activation.DataHandlerクラスではなく,com.sun.xml.ws.developer.StreamingDataHandlerクラスにマッピングし,ストリーミングされた添付ファイルとして操作できます。

com.sun.xml.ws.developer.StreamingDataHandlerクラスについては,「19.2.4(2) com.sun.xml.ws.developer.StreamingDataHandlerクラス」を参照してください。

ストリーミングされた添付ファイルを操作する例を次に示します。この例では,ストリーミングされた添付ファイルを"C:/portrait.png"として別名で出力します。

package com.sample;

・・・・・・

@MTOM
@StreamingAttachment(dir="C:/TMP", parseEagerly=true, memoryThreshold=50000L)
@BindingType(・・・)
public class UserInfoImpl implements UserInfo {

   public DataHandler getUserInfo(DataHandler dataHandler)
       throws UserDefinedException {
       if (dataHandler instanceof StreamingDataHandler) {
           File file = new File("C:/portrait.png");
           StreamingDataHandler sdh = null;
           try {
               sdh = (StreamingDataHandler)dataHandler;
               sdh.moveTo(file);
               ・・・・・・
           } finally {
               try {
                   if (sdh != null) {
                       sdh.close();
                   }
               } catch(Exception ex) {
                   ・・・・・・
               }
           }
       }
   }
}

<この項の構成>
(1) ストリーミングされた添付ファイルの操作時の注意事項

(1) ストリーミングされた添付ファイルの操作時の注意事項

ストリーミングされた添付ファイルを操作する場合の注意事項を次に示します。