Webサービスクライアントでストリーミングを使用するには,SEIを取得する際にcom.sun.xml.ws.developer.StreamingAttachmentFeatureクラスを設定します。
com.sun.xml.ws.developer.StreamingAttachmentFeatureクラスについては,「19.2.4(1) com.sun.xml.ws.developer.StreamingAttachmentFeatureクラス」を参照してください。
ストリーミングを使用したWebサービスクライアントの例を次に示します。この例では,"C:/TMP"ディレクトリをストリーミングによる一時ファイルの出力先に指定し,添付ファイルを含むSOAPメッセージの詳細な解析をし,50,000バイト以上のMIMEボディを一時ファイルとして出力します。
package com.sample;
・・・・・・
public class TestClient {
public static void main(String[] args) {
try {
File portrait = new File("portrait.png");
FileDataSource fileDataSource = new FileDataSource(portrait);
DataHandler dataHandler = new DataHandler(fileDataSource);
MTOMFeature mtomFeature = new MTOMFeature();
StreamingAttachmentFeature streamingAttachmentFeature = new StreamingAttachmentFeature("C:/TMP", true, 50000L);
UserInfoService service = new UserInfoService();
UserInfoImpl port = service.getUserInfoImplPort(mtomFeature, streamingAttachmentFeature);
DataHandler userData = port.getUserInfo(dataHandler);
if (userData instanceof StreamingDataHandler) {
StreamingDataHandler sdh = null;
try {
sdh = (StreamingDataHandler)userData;
sdh.moveTo(file);
・・・・・・
} finally {
try {
if (sdh != null) {
sdh.close();
}
} catch(Exception ex) {
・・・・・・
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
} |