Implementing the deployModule Method

The example in this section shows an implementation of the deployModule method for a WebDAV server. This method is responsible for the deployment of a single file to the WebDAV site.

public DeploymentStatus deployModule(String url)
                 throws DeploymentException {
    Assert.isNotNull(siteHandle);
    Assert.isTrue(url != null && url.trim().length() > 0);
    InputStream inputStream = null;
    String deploymentMsg = "Deploying: " + url;
    try {
        DAVClient client = siteHandle.getDAVClient();
        String remoteUrl = getSiteRelativeURL(siteHandle, url);
        ILocator resourceLocator = client.getDAVFactory().newLocator(
                remoteUrl);
        URL localUrl = new URL(url);
        inputStream = localUrl.openStream();
        IResponse response = client.put(resourceLocator, client
                .getDAVFactory().newContext(), inputStream);
        int statusCode = response.getStatusCode();
        String statusMessage = response.getStatusMessage();
        String responseMessage = "\n" + statusCode + ':' + statusMessage;
        if (statusCode == IResponse.SC_CREATED
                || statusCode == IResponse.SC_NO_CONTENT) {
            return new DeploymentSimpleStatus(
                    DeploymentSimpleStatus.Severity.OK, deploymentMsg
                            + responseMessage, null);
        } else {
            return new DeploymentSimpleStatus(
                    DeploymentSimpleStatus.Severity.ERROR, deploymentMsg
                            + responseMessage, null);
        }
    } catch (IOException e) {
        return new DeploymentSimpleStatus(
                DeploymentSimpleStatus.Severity.ERROR, deploymentMsg, e);
    } finally {
        try {
            inputStream.close();
        } catch (IOException e) {
            // TODO Log error
            e.printStackTrace();
        }
    }
}

The method’s parameter is a string that contains the URL of the file in the deployment repository (also called the inquiry URL). Because we use “Workspace Repository” this URL is the same as the URL of the local file. Before the module is deployed, it is published to the server repository and the repository is asked to provide the inquiry URL for the published module. This inquiry URL is passed as a parameter to the deployModule method, and it is used by the server to access the module from the repository (it could be different to the local module URL).