1

There is a good example showing how to put a file onto WebDAV server:

Java: How to upload a file to a WebDAV server from a servlet?

But how can I get a file content?

There is MethodPut class for the PUT command, but there is no appropriate GetMethod (although enum DavMethods.METHOD_GET is presented).

Pavel Vlasov
  • 4,206
  • 6
  • 41
  • 54

1 Answers1

0

I solved the task 1) implementing my own class for the GET method 2) reading response bytes which represents file's content. I'd prefer to find a simpler solution in Jackrabbit still.

public class MyGetMethod extends DavMethodBase {
    public MyGetMethod(String uri) {
        super(uri);
    }
    public String getName() {
        return DavMethods.METHOD_GET;
    }
    public boolean isSuccess(int statusCode) {
        return statusCode == 200;
    }
}

static void jackrabbitGet() throws Exception {
    HttpClient client = new HttpClient();
    Credentials creds = new UsernamePasswordCredentials("user", "pass");
    client.getState().setCredentials(AuthScope.ANY, creds);
    MyGetMethod method = new MyGetMethod(url goes here);
    client.executeMethod(method);
    if (method.isSuccess(method.getStatusCode())) {
        byte[] resp = method.getResponseBody();
        System.out.println("Got response: " + resp.length + " bytes");
    }
}
Pavel Vlasov
  • 4,206
  • 6
  • 41
  • 54