Downloading a file
To download a file from an Encyclopedia volume, identify the file and indicate whether to embed the content in the response or use chunked transfer encoding. In HTTP 1.0, you must embed the entire file in the response and send it in a long, uninterrupted file stream. In HTTP 1.1, you can send the file in smaller chunks, which increases the efficiency of the file transfer. Although the Encyclopedia volume supports both methods, BIRT iHub messages typically use chunked transfer encoding.
The following example application uses chunked transfer encoding and relevant com.actuate.schemas classes to build an application that downloads a file from an Encyclopedia volume.
Using com.actuate.schemas.DownloadFile
The com.actuate.schemas.DownloadFile class downloads a file from an Encyclopedia volume to the client. You can choose to embed the file content in the response or send it to the client as an attachment.
The DownloadFile class contains the following list of attributes:
*FileName or FileId is a String specifying the ID or name of the file to download.
Specify either FileId or FileName.
*DecomposeCompoundDocument is a Boolean indicating whether to download a compound document as one file or multiple attachments.
If the DecomposeCompoundDocument value is False, you can download the file as a single file. If the value is True, and the file is a compound document, the Encyclopedia volume splits the file into attachments containing the atomic elements of the compound document such as fonts and images. A decomposed document is not in a viewable format. The default value is False.
*DownloadEmbedded is a Boolean indicating whether to embed the content in the response or use chunked transfer encoding.
*FileProperties is a String array specifying the file properties to return.
How to build an application that downloads a file
The following application derives from the code in the BIRT iHub Integration Technology example applications for the Apache Axis 2 client. In the example application, AcDownloadFile_Chunked class, downloads a file from the Encyclopedia volume, using the chunked option, and saves the file in the user ~\temp directory.
The AcDownloadFile_Chunked class performs the following operations:
*Instantiates an org.apache.axis.client.Service object.
public class AcDownloadFile_Chunked {
Service service = new Service( );
*In AcDownloadFile_Chunked.main( ), defines an attribute for the file name and initializes the downloadEmbedded flag to False.
public static void main(String[ ] args) {
// download settings
String filename;
Boolean downloadEmbedded = Boolean.FALSE;
*Gets the command line argument, specifying the file name.
Arguments arguments = new Arguments(args);
filename = arguments.getArgument();
*Creates a client Call object, using ActuateControl.createCall( ).
try {
// create a call object
org.apache.axis.client.Call call =
actuateControl.createCall( );
The ActuateControl.createCall( ) method performs the following tasks:
*Uses ActuateAPI.createCall( ) to create a client Call object that can send a SOAP message to BIRT iHub
*Casts the Call object as an org.apache.axis.client.Call object as required by the Apache Axis framework
*Sets the target BIRT iHub URL
*Returns the Call object to AcDownloadFile_Chunked.main( )
The following example shows the code for ActuateControl.createCall( ):
public org.apache.axis.client.Call createCall( ) throws ServiceException {
org.apache.axis.client.Call call =
(org.apache.axis.client.Call) actuateAPI.createCall( );
call.setTargetEndpointAddress(this.actuateServerURL);
return call;
}
*AcDownloadFile_Chunked.main( ) sets up the Call parameters using a local method, prepareDownloadFileCall( ), passing in the reference to the Call object.
prepareDownloadFileCall(call);
The prepareDownloadFileCall( ) method sets up the org.apache.axis.client.Call parameters as shown in the following code:
public static void prepareDownloadFileCall(
org.apache.axis.client.Call call) {
call.addParameter(
new javax.xml.namespace.QName(
"http://schemas.actuate.com/actuate11",
"DownloadFile"),
new javax.xml.namespace.QName(
"http://schemas.actuate.com/actuate11",
"DownloadFile"),
com.actuate.schemas.DownloadFile.class,
javax.xml.rpc.ParameterMode.IN);
call.setReturnType(
new javax.xml.namespace.QName(
"http://schemas.actuate.com/actuate11",
"DownloadFileResponse"));
call.setUseSOAPAction(true);
call.setSOAPActionURI("");
call.setEncodingStyle(null);
call.setProperty(
org.apache.axis.AxisEngine.PROP_DOMULTIREFS,
Boolean.FALSE);
call.setProperty(snew javax.xml.namespace.QName(
"http://schemas.actuate.com/actuate11",
"DownloadFile"));
}
*Next, AcDownloadFile_Chunked.main( ) sets up the DownloadFile request object, specifying the downloadEmbedded flag and file name.
// set download message
com.actuate.schemas.DownloadFile request =
new com.actuate.schemas.DownloadFile( );
request.setDownloadEmbedded(downloadEmbedded);
request.setFileName(filename);
*Invokes the Call object, passing the reference to the DownloadFile request in an Object array.
Object resp = call.invoke(new Object[ ] {request});
*Uses org.apache.axis.client.Call.getMessageContext( ) to obtain the reference to the org.apache.axis.MessageContext object.
MessageContext messageContext = call.getMessageContext();
*Uses MessageContext.getResponseMessage( ) to obtain the response message.
Message message = messageContext.getResponseMessage( );
*Uses an Iterator to get the attachments and stream the attachment parts to the Axis default location for the downloaded file in user ~/temp directory.
Iterator iterator = message.getAttachments( );
while (iterator.hasNext( )) {
 
AttachmentPart attachmentPart =
(AttachmentPart) iterator.next( ); try {
filename =
attachmentPart.getDataHandler( ).getName( );
System.out.println("Attachment saved at " +
filename);
}
catch (SOAPException e) {
e.printStackTrace( );
}
}
 
}
catch (Exception e) {
 
e.printStackTrace( );
}
}
}
The Java application writes the messages to the command prompt window when the download succeeds. The path and file name in the output message provide the file name and location information for the attachment.