ClientInterceptor を使用します。
public class AttachmentInterceptor implements ClientInterceptor {
Iterator<Attachment> attachments;
@Override
public boolean handleResponse(MessageContext msgCtx) throws WebServiceClientException {
WebServiceMessage msg = msgCtx.getResponse();
if (msg instanceof SaajSoapMessage) {
SaajSoapMessage sm = (SaajSoapMessage) msg;
attachments = sm.getAttachments();
return false;
} else {
return true;
}
}
public Iterator<Attachment> getAttachments() {
return attachments;
}...
次に、インターセプターを WebServiceTemplate にアタッチし、呼び出しを実行します。
AttachmentInterceptor ai = new AttachmentInterceptor();
wst.setInterceptors(new ClientInterceptor [] { ai });
wst.sendSourceAndReceiveToResult(src, result);
/**
* get attachment
*/
Iterator<Attachment> it = ai.getAttachments();
次に、添付ファイルを処理します。