Cosminexus V9 アプリケーションサーバ Webサービス開発ガイド
ストリーミングを使用しているときに添付ファイルを含む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) {
・・・・・・
}
}
}
}
}
|
ストリーミングされた添付ファイルを操作する場合の注意事項を次に示します。
package com.sample;
...
@MTOM
@StreamingAttachment(...)
...
public class UserInfoImpl implements UserInfo {
public @XmlMimeType("application/octet-stream")
DataHandler getUserInfo(
@XmlMimeType("application/octet-stream")
DataHandler dataHandler)
throws ... {
if (dataHandler instanceof StreamingDataHandler) {
StreamingDataHandler sdh = null;
try {
sdh = (StreamingDataHandler)dataHandler;
...
InputStream inputStream = sdh.readOnce();
...
// 入力ストリームから添付ファイルのデータをすべて
// 読み込む
while ((inputStream.read()) != -1);
// 入力ストリームをクローズする
inputStream.close();
} finally {
try {
if (sdh != null) {
// StreamingDataHandlerクラスのclose()
// メソッドを呼び出す
sdh.close();
}
} catch(Exception ex) {
...
}
}
}
...
}
}
|
package com.sample;
...
@MTOM
@StreamingAttachment(...)
...
public class UserInfoImpl implements UserInfo {
public @XmlMimeType("application/octet-stream")
DataHandler getUserInfo(
@XmlMimeType("application/octet-stream")
DataHandler dataHandler)
throws ... {
if (dataHandler instanceof StreamingDataHandler) {
StreamingDataHandler sdh = null;
try {
File file = new File(...);
sdh = (StreamingDataHandler)dataHandler;
...
sdh.moveTo(file);
} catch(Exception e)
try {
if (sdh != null) {
InputStream inputStream = sdh.readOnce();
// 入力ストリームから添付ファイルのデータをすべて
// 読み込む
while ((inputStream.read()) != -1);
// 入力ストリームをクローズする
inputStream.close();
}
} catch(Exception ex) {
...
}
} finally {
try {
if (sdh != null) {
// StreamingDataHandlerクラスのclose()
// メソッドを呼び出す
sdh.close();
}
} catch(Exception ex) {
...
}
}
}
...
}
}
|
All Rights Reserved. Copyright (C) 2012, 2015, Hitachi, Ltd.