SCMPFileDownloadCall downloadFileCall = new SCMPFileDownloadCall(this.requester, this.serviceName, this.sessionId);
downloadFileCall.setRemoteFileName(remoteFileName);
try {
downloadFileCall.invoke(callback, operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
} catch (Exception e) {
throw new SCServiceException("Download file failed. ", e);
}
// 3. receiving reply and error handling
SCMPMessage reply = callback.getMessageSync(operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
if (reply.isFault()) {
SCServiceException ex = new SCServiceException("Download file failed.");
ex.setSCErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.SC_ERROR_CODE));
ex.setSCErrorText(reply.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
throw ex;
}
// 4. post process, reply to client
if (reply.isComposite()) {
((SCMPCompositeReceiver) reply).writeBodyAsStream(outStream);
return;
}
outStream.write((byte[]) reply.getBody());
} catch (IOException e) {
throw new SCServiceException("Writing to OutputStream failed. ", e);
} finally {
// always delete file session
this.deleteFileSession(operationTimeoutSeconds);
}
}