Search code examples
javahttpclientwebdavjackrabbitsling

How do I make a WebDav call using HttpClient?


Specifically I want to call MKCOL through HttpClient to create a folder for Apache Jackrabbit through the Sling REST API.

I've tried variants of

BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("MKCOL", restUrl);

But no dice so far. I'm guessing this is less difficult than I'm making it.

I also see there is MkColMethod for something like

MkColMethod mkColMethod = new MkColMethod(restUrl);

But I don't know how to utilize this. I think it may have worked with a previous version of HttpClient. I'm using 4.x


Solution

  • Best is to look at the Sling integration tests, which use Sling's RESTful APIs to create content.

    The "old" SlingIntegrationTestClient class is used to test Sling itself and uses httpclient 3.x to create content. It is used by the tests found here, so you can find examples there.

    The "new" SlingClient class is meant to be a cleaner and simpler re-implementation of that, used by the Sling testing tools described at http://sling.apache.org/site/sling-testing-tools.html . It uses httpclient 4.x which has a slightly different API.

    The SlingClient.mkdir and mkdirs methods do use the MKCOL method.