Use jackrabbit as webdav server
[lgpl/argeo-commons.git] / sandbox / runtime / org.argeo.sandbox.jackrabbit / src / main / java / webdav / WebDavTest.java
index 6ef840b884d08ad14ecd8a70d35979f622249cc9..cb8a97ad2456b0dfac1d29903b689648153f042a 100644 (file)
@@ -1,5 +1,7 @@
 package webdav;
 
+import java.io.FileInputStream;
+
 import org.apache.commons.httpclient.Credentials;
 import org.apache.commons.httpclient.HostConfiguration;
 import org.apache.commons.httpclient.HttpClient;
@@ -7,6 +9,8 @@ import org.apache.commons.httpclient.HttpConnectionManager;
 import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
 import org.apache.commons.httpclient.UsernamePasswordCredentials;
 import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
+import org.apache.commons.httpclient.methods.RequestEntity;
 import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
 import org.apache.jackrabbit.webdav.client.methods.PutMethod;
 
@@ -18,7 +22,7 @@ public class WebDavTest {
        public static void main(String[] args) {
                try {
                        HostConfiguration hostConfig = new HostConfiguration();
-                       hostConfig.setHost("localhost", 8082);
+                       hostConfig.setHost("localhost", 7070);
                        // hostConfig.
                        HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
                        HttpConnectionManagerParams params = new HttpConnectionManagerParams();
@@ -26,17 +30,22 @@ public class WebDavTest {
                        params.setMaxConnectionsPerHost(hostConfig, maxHostConnections);
                        connectionManager.setParams(params);
                        HttpClient client = new HttpClient(connectionManager);
-                       Credentials creds = new UsernamePasswordCredentials("scanner1",
-                                       "scanner1");
+                       Credentials creds = new UsernamePasswordCredentials("demo", "demo");
                        client.getState().setCredentials(AuthScope.ANY, creds);
                        client.setHostConfiguration(hostConfig);
                        // return client;
 
+                       String fileName = "test.xml";
                        PutMethod pm = new PutMethod(
-                                       "http://localhost:8082/webdav/scanner1_queque/uploader/image_"
-                                                       + ".txt");
-                       String text = "this is the document content";
-                       pm.setRequestBody(text);
+                                       "http://localhost:7070/org.argeo.server.jackrabbit.webapp/default/"
+                                                       + fileName);
+                       // String text = "this is the document content";
+                       RequestEntity requestEntity = new InputStreamRequestEntity(
+                                       new FileInputStream(fileName));
+                       // pm.setRequestEntity(new StringRequestEntity(text, "text/plain",
+                       // null));
+                       // pm.setRequestBody(text);
+                       pm.setRequestEntity(requestEntity);
                        client.executeMethod(pm);
                } catch (Exception e) {
                        e.printStackTrace();