Package org.apache.jackrabbit.webdav.client.methods

This package contains classes and utilities used to build a WebDAV client implementation.
Currently it consists of DAV-specific extensions to the Jakarta Commons HttpClient, namely a set of methods.

See: Description

Package org.apache.jackrabbit.webdav.client.methods Description

This package contains classes and utilities used to build a WebDAV client implementation.
Currently it consists of DAV-specific extensions to the Jakarta Commons HttpClient, namely a set of methods.

How to use Jakarta Commons HttpClient

Please refer to the tutorial present with Jakarta Commons HttpClient for detailed instructions.

Simple Example

The following simple example illustrates the additional functionality exposed by the DavMethod which serves as basic interface for all WebDAV specific extensions:

First you need to create the HostConfiguration which at least must define the uri pointing to your WebDAV enabled server
    String uri = "http://your-webdav-server";
    HostConfiguration hostConfig = new HostConfiguration();
    hostConfig.setHost(uri);
Define a HttpConnectionManager, which also is responsible for eventual multithreading support:
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    int maxHostConnections = 20;
    params.setMaxConnectionsPerHost(hostConfig, maxHostConnections);
    connectionManager.setParams(params);
Create the HttpClient object and eventually pass the Credentials:
    HttpClient client = new HttpClient(connectionManager);
    client.setHostConfiguration(hostConfig);
    Credentials creds = new UsernamePasswordCredentials("userId", "pw");
    client.getState().setCredentials(AuthScope.ANY, creds);
In order to execute a WebDAV request, choose the appropriate DavMethod. For example, a PROPFIND request could look as follows:
    String propfindUri = "http://your-webdav-server/anyresource";
    DavMethod method = new PropFindMethod(propfindUri, DavConstants.PROPFIND_ALL_PROP, DavConstants.DEPTH_1);
    client.executeMethod(method);
The DavMethod interface defines two methods that allows you to determine if the request was successfully executed without need to evaluate the status line and knowing about the required status codes:
    method.checkSuccess();
In case of success you can retrieve the response body in an appropriate formate and process it according to you needs,
For a PROPFIND request use e.g. DavMethod.getResponseBodyAsMultiStatus():
    MultiStatus multiStatus = method.getResponseBodyAsMultiStatus();

Copyright © 2004-2020 The Apache Software Foundation. All Rights Reserved.