2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org
.argeo
.sandbox
.jackrabbit
;
19 import java
.io
.FileInputStream
;
20 import java
.util
.ArrayList
;
21 import java
.util
.List
;
23 import org
.apache
.commons
.httpclient
.Credentials
;
24 import org
.apache
.commons
.httpclient
.HostConfiguration
;
25 import org
.apache
.commons
.httpclient
.HttpClient
;
26 import org
.apache
.commons
.httpclient
.HttpConnectionManager
;
27 import org
.apache
.commons
.httpclient
.MultiThreadedHttpConnectionManager
;
28 import org
.apache
.commons
.httpclient
.UsernamePasswordCredentials
;
29 import org
.apache
.commons
.httpclient
.auth
.AuthScope
;
30 import org
.apache
.commons
.httpclient
.methods
.GetMethod
;
31 import org
.apache
.commons
.httpclient
.methods
.InputStreamRequestEntity
;
32 import org
.apache
.commons
.httpclient
.methods
.RequestEntity
;
33 import org
.apache
.commons
.httpclient
.params
.HttpConnectionManagerParams
;
34 import org
.apache
.commons
.logging
.Log
;
35 import org
.apache
.commons
.logging
.LogFactory
;
36 import org
.apache
.jackrabbit
.webdav
.client
.methods
.CheckoutMethod
;
37 import org
.apache
.jackrabbit
.webdav
.client
.methods
.CopyMethod
;
38 import org
.apache
.jackrabbit
.webdav
.client
.methods
.DavMethod
;
39 import org
.apache
.jackrabbit
.webdav
.client
.methods
.PropPatchMethod
;
40 import org
.apache
.jackrabbit
.webdav
.client
.methods
.PutMethod
;
41 import org
.apache
.jackrabbit
.webdav
.property
.DavProperty
;
42 import org
.apache
.jackrabbit
.webdav
.property
.DefaultDavProperty
;
43 import org
.apache
.jackrabbit
.webdav
.version
.DeltaVConstants
;
45 public class WebDavTest
{
46 private final static Log log
= LogFactory
.getLog(WebDavTest
.class);
51 public static void main(String
[] args
) {
53 HostConfiguration hostConfig
= new HostConfiguration();
54 hostConfig
.setHost("localhost", 7070);
56 HttpConnectionManager connectionManager
= new MultiThreadedHttpConnectionManager();
57 HttpConnectionManagerParams params
= new HttpConnectionManagerParams();
58 int maxHostConnections
= 20;
59 params
.setMaxConnectionsPerHost(hostConfig
, maxHostConnections
);
60 connectionManager
.setParams(params
);
61 HttpClient client
= new HttpClient(connectionManager
);
62 Credentials creds
= new UsernamePasswordCredentials("demo", "demo");
63 client
.getState().setCredentials(AuthScope
.ANY
, creds
);
64 client
.setHostConfiguration(hostConfig
);
67 String baseUrl
= "http://localhost:7070/webdav/default/";
68 // String fileName = "test.xml";
69 String file00
= "dummy00.xls";
70 String file01
= "dummy01.xls";
71 String url00
= baseUrl
+ file00
;
72 String url01
= baseUrl
+ file01
;
73 String urlCopied
= baseUrl
+ "test-copied.xls";
76 log
.debug("Create " + url00
);
77 PutMethod pm
= new PutMethod(url00
);
78 RequestEntity requestEntity
= new InputStreamRequestEntity(
79 new FileInputStream(file00
));
80 pm
.setRequestEntity(requestEntity
);
81 client
.executeMethod(pm
);
82 log
.debug("POST status: " + pm
.getStatusCode() + " "
83 + pm
.getStatusText());
86 List
<DavProperty
> props
= new ArrayList
<DavProperty
>();
87 props
.add(new DefaultDavProperty("auto-version",
88 DeltaVConstants
.XML_CHECKOUT_CHECKIN
,
89 DeltaVConstants
.NAMESPACE
));
90 PropPatchMethod pp
= new PropPatchMethod(url00
, props
);
91 client
.executeMethod(pp
);
92 log
.debug("PROP PATCH status: " + pp
.getStatusCode() + " "
93 + pp
.getStatusText());
96 log
.debug("Update " + url00
);
97 pm
= new PutMethod(url00
);
98 requestEntity
= new InputStreamRequestEntity(new FileInputStream(
100 pm
.setRequestEntity(requestEntity
);
101 client
.executeMethod(pm
);
102 log
.debug("POST status: " + pm
.getStatusCode() + " "
103 + pm
.getStatusText());
106 log
.debug("Copy to " + urlCopied
);
107 DavMethod copy
= new CopyMethod(url00
, urlCopied
, true);
108 client
.executeMethod(copy
);
110 log
.debug("COPY status: " + copy
.getStatusCode() + " "
111 + copy
.getStatusText());
114 // CheckoutMethod gm = new CheckoutMethod(baseUrl + fileName);
115 log
.debug("Retrieve " + urlCopied
);
116 GetMethod gm
= new GetMethod(urlCopied
);
117 client
.executeMethod(gm
);
118 String responseGet
= gm
.getResponseBodyAsString();
119 log
.debug("GET status: " + gm
.getStatusCode() + " "
120 + gm
.getStatusText());
121 // log.debug("GET: " + responseGet);
122 } catch (Exception e
) {