0
votes

beginning to work with Jackrabbit 2.6.3 and commons httpclient 3.

I've written a simple webDav client to upload a file to a server and want to test it against jackrabbit's standalone server's default repository. Simply I just want to put a file in the default repository.

my httpclient connects and the method begins buffering my file. Trouble is, I can't seem to work what URL I should point my http method at to correctly put it in the repository. The standalone server is running on:

http://localhost:8080.

I seem to either get a 405 PUT not supported or 404 or 403 or the even more curious "repository '/' does not begin with '/default' for all the urls I've tried. I can see the default repository content if I point my browser at:

http://localhost:8080/repository/default/ 

Simply, my question is, what is the url to do this with a PutMethod? As rudimentary as that sounds.

I've included some truncated code for the class I've written, specifically the method I'm working with at the moment, I think it should be enough to show my approach is correct.

public void insertFile(byte[] content, String id) throws Exception {
    PutMethod httpMethod = new PutMethod("http://localhost:8080/repository/default/");
    InputStream is = new ByteArrayInputStream(content);
    FileMetaData meta = new FileMetaData();
    meta.address = destUri;
    meta.id = id;
    meta.mimeType = Files.probeContentType(Paths.get(meta.address));
    RequestEntity requestEntity = new InputStreamRequestEntity(is, meta.mimeType);
    httpMethod.setRequestEntity(requestEntity);
    try {
        int statusCode = client.executeMethod(httpMethod);
        if (statusCode != HttpStatus.SC_OK) System.err.println("Method failed: " + httpMethod.getStatusLine());
        byte[] responseBody = httpMethod.getResponseBody();
        System.out.println(new String(responseBody));
    } catch (HttpException e) {
        System.err.println("Fatal protocol violation: " + e.getMessage());
        e.printStackTrace();
    } catch (IOException e) {
        System.err.println("Fatal transport error: " + e.getMessage());
        e.printStackTrace();
    } finally {
        httpMethod.releaseConnection();
    }

}

I'm sure it's a simple answer, but trawling the docs don't seem to show up any resources or tutorials relating to this. Any help appreciated.

1

1 Answers

0
votes

Really silly, totally thought that the requestEntity would send some data on file and use that as a file name, instead I have to specify that myself. PROTIP: Step away from the computer for 5 - 10 minutes. For anyone else with my issue it should be '"yourUrl/repository/default" + fileName'. Easy.