2013-10-24 71 views
0

开头兔崽子2.6.3和Commons的HttpClient 3.Apache Jackrabbit webDAV PUT方法。

我写了一个简单的WebDAV客户端上传文件到服务器,并想测试对兔崽子的独立服务器的默认存储库工作。简单地说,我只想将文件放入默认存储库中。

我的httpclient连接和方法开始缓冲我的文件。麻烦的是,我似乎无法工作什么URL我应该指向我的HTTP方法,以正确地将其放入存储库。单机服务器上运行:

http://localhost:8080. 

我似乎要么得到一个405 PUT,不支持或404或403或更好奇“库‘/’不‘/默认的’开始为所有的URL我已经试过,我可以看到默认的存储库的内容,如果我在点我的浏览器:?

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

简单地说,我的问题是,什么是URL以PutMethod这样做,因为这听起来很简陋

我已经为我写的类包含了一些截断代码,特别是方法我现在正在处理这个问题,我认为这应该足以证明我的方法是正确的。

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(); 
    } 

} 

我相信这是一个简单的答案,但拖网文档似乎没有显示任何资源或与此相关的教程。任何帮助赞赏。

回答

0

真的很愚蠢,完全认为requestEntity会发送一些文件上的数据并将其用作文件名,而不得不自己指定。 PROTIP:离开电脑5到10分钟。对于我的问题的其他人应该是'“yourUrl/repository/default”+ fileName'。简单。