Working with the Client Download Service
This topic provides code examples for using the Content Platform Engine Client Download Service:
- Connecting to the Client Download Servlet
- Retrieving Server Version Information
- Iterating Package and Features
- Downloading Components
For a conceptual overview and developer requirements, see Overview.
Connecting to the Client Download Servlet
As shown in the example below, you use the ServerConnectionData object to connect to the Client Download servlet.
// Establish HTTP connection.
ServerConnectionData httpConnectionData = ServerConnectionData.getHttpConnectionData(hostName, portNumber);
You can also establish an HTTP secure protocol connection, with the option to enforce server certificate validation.
// Establish HTTPS connection.
boolean validateServerCertificate = true;
ServerConnectionData httpConnectionData = ServerConnectionData.getHttpsConnectionData(hostName, portNumber,
validateServerCertificate);
Retrieving Server Version Information
The following example demonstrates the use of the ServerVersion object to retrieve server version information. The code also calls the isCompatibleWithServer method to check the compatibility of a particular API installed on the client against the same API installed on the server. The method specifies the IBM® Content Cortex package and EJB transport feature, as well as the directory path to the client's API files. For the method to successfully check for compatibility, it requires the existence of a key file in the directory. The key file is determined by feature ID. For more information, see ServerVersion.isCompatibleWithServer.
ServerConnectionData httpConnectionData = ServerConnectionData.getHttpConnectionData(hostName, portNumber);
// Pass connection object to create ServerVersion object.
ServerVersion sv=ServerVersion.fetchInstance(httpConnectionData);
// Print server version information.
System.out.println("Server version: " + sv.getVersion() +"\n" +
"Server build number: " + sv.getServerBuildNumber() +"\n" +
// Check client Java API compatibility against server.
java.io.File libPath = new java.io.File("E:\\EclipseWorkspace\\ClientDownloadAPI\\currentComponents");
System.out.println("isCompatible?: " + sv.isCompatibleWithServer(libPath,
Package.IBM_FILENET_CONTENT_MANAGER_PACKAGE_ID,
Feature.JAVA_EJB_CLIENT_FEATURE_ID) );
Iterating Package and Features
The following example shows how to iterate Package and Feature objects. Iteration code can be used to display a list of the packages and features available on a server from which users can select.
A feature contains
components and configuration values. The components are the files
that are associated with the feature. The configuration values are
text strings that describe the configuration of the components in
the environment. For example, a JAR component has a configuration
value of classpath, indicating that you must add
the JAR to the class path. For more information, see ConfigurationValue.
ServerConnectionData httpConnectionData = ServerConnectionData.getHttpConnectionData(hostName, portNumber);
try
{
// Pass connection object to search for packages on the server.
List<Package> packageList = Package.search(httpConnectionData);
// Iterate the list and identify the packages on the Content Engine server.
Iterator<Package> it = packageList.iterator();
while(it.hasNext())
{
Package cePackage = (Package) it.next();
System.out.println("Package description: " + cePackage.getDescription() +
". Package ID: " + cePackage.getId());
// Return list of features in the package and iterate the list.
List<Feature> featureList = cePackage.getFeatures();
Iterator<Feature> it2 = featureList.iterator();
while (it2.hasNext() )
{
Feature feature = (Feature) it2.next();
System.out.println("Feature description: " + feature.getDescription() +
". Feature size: " + feature.getSize() );
// Return list of components in the feature and iterate the list.
List<Component> componentList = feature.getComponents();
Iterator<Component> it3 = componentList.iterator();
while(it3.hasNext())
{
Component comp = (Component) it3.next();
System.out.println("Component type: " + comp.getType() +
". Component path: " + comp.getPath() +
". Component size: " + comp.getSize() );
}
// Return list of configuration values in the feature and iterate the list.
List<ConfigurationValue> configurationValuesList = feature.getConfigurationValues();
Iterator<ConfigurationValue> it4 = configurationValuesList.iterator();
while(it4.hasNext())
{
ConfigurationValue cv = (ConfigurationValue) it4.next();
System.out.println("Configuration value type: " + cv.getType() +
". Configuration value value: " + cv.getValue());
}
}
}
}
catch (ClientDownloadRuntimeException e) {
System.out.println(e.getMessage() );
}
catch (Exception e) {
System.out.println(e.getMessage() );
}
Downloading Components
The following example shows how to check for client/server compatibility for the APIs in the Content Manager package. The example assumes a UI where a user selects a feature type of the package: EJB, CEWS, or Java™ Compatibility Layer. For the selected feature, the checkForNewFeature method of the ServerVersion object checks for compatibility between the client and server's API components. If there is an incompatibility, the method instantiates a Feature object, and the object's download method is used to download compatible components to the client.
When a download operation occurs, the Client Download Java API writes an XML-based file manifest that lists the downloaded components. The API writes the file to the download directory and names the file after the feature type, for example, ejb_manifest.xml. For more information, see Feature.download.
ServerConnectionData httpConnectionData = ServerConnectionData.getHttpConnectionData(hostName, portNumber);
try
{
// Pass connection object to create ServerVersion object.
ServerVersion sv=ServerVersion.fetchInstance(httpConnectionData);
/* File object specifies location of client Content Manager API components.
It will be used to compare API version against the server version,
and, if necessary, to download a compatible set of API components. */
java.io.File libPath = new java.io.File("E:\\EclipseWorkspace\\ClientDownloadAPI\\currentComponents");
/* For the feature type selected in the UI, check for compatibility.
The featureType variable is set with UI selection. */
Feature feature;
if (featureType=="ejb")
feature = sv.checkForNewFeature(libPath, Package.IBM_FILENET_CONTENT_MANAGER_PACKAGE_ID,
Feature.JAVA_EJB_CLIENT_FEATURE_ID);
else if (featureType=="cews")
feature = sv.checkForNewFeature(libPath, Package.IBM_FILENET_CONTENT_MANAGER_PACKAGE_ID,
Feature.JAVA_CEWS_CLIENT_FEATURE_ID);
else
feature = sv.checkForNewFeature(libPath, Package.IBM_FILENET_CONTENT_MANAGER_PACKAGE_ID,
Feature.JAVA_COMPATIBILITY_LAYER_FEATURE_ID);
// If the Content Manager Java API components are not compatible with the server version,
// download updated components.
if (feature != null)
feature.download("E:\\EclipseWorkspace\\ClientDownloadAPI\\newComponents");
else System.out.println("Client API is compatible with Content Manager feature; no download is required.");
}
catch (ClientDownloadRuntimeException e) {
System.out.println(e.getMessage() );
}
catch (Exception e) {
System.out.println(e.getMessage() );
}