X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=sandbox%2Fruntime%2Forg.argeo.sandbox.jackrabbit%2Fsrc%2Fmain%2Fjava%2Fwebdav%2FWebDavTest.java;h=5b938be0d4a1d772a538d59d956fe96a47e5217d;hb=cdfd09387221a87b3a36f54fd3d5e8a6f4279baf;hp=6ef840b884d08ad14ecd8a70d35979f622249cc9;hpb=c4109698590ac4e99e051eca6abe94dc97c302f7;p=lgpl%2Fargeo-commons.git diff --git a/sandbox/runtime/org.argeo.sandbox.jackrabbit/src/main/java/webdav/WebDavTest.java b/sandbox/runtime/org.argeo.sandbox.jackrabbit/src/main/java/webdav/WebDavTest.java index 6ef840b88..5b938be0d 100644 --- a/sandbox/runtime/org.argeo.sandbox.jackrabbit/src/main/java/webdav/WebDavTest.java +++ b/sandbox/runtime/org.argeo.sandbox.jackrabbit/src/main/java/webdav/WebDavTest.java @@ -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,10 +9,16 @@ 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.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.jackrabbit.webdav.client.methods.CheckoutMethod; import org.apache.jackrabbit.webdav.client.methods.PutMethod; public class WebDavTest { + private final static Log log = LogFactory.getLog(WebDavTest.class); /** * @param args @@ -18,7 +26,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,18 +34,27 @@ 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; - PutMethod pm = new PutMethod( - "http://localhost:8082/webdav/scanner1_queque/uploader/image_" - + ".txt"); - String text = "this is the document content"; - pm.setRequestBody(text); + String baseUrl = "http://localhost:7070/org.argeo.server.jackrabbit.webapp/default/"; + + String fileName = "test.xml"; + + // PUT + PutMethod pm = new PutMethod(baseUrl + fileName); + RequestEntity requestEntity = new InputStreamRequestEntity( + new FileInputStream(fileName)); + pm.setRequestEntity(requestEntity); client.executeMethod(pm); + + // GET + CheckoutMethod gm = new CheckoutMethod(baseUrl + fileName); + client.executeMethod(gm); + String responseGet = gm.getResponseBodyAsString(); + log.debug("CHECKOUT: " + responseGet); } catch (Exception e) { e.printStackTrace(); }