X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=sandbox%2Fruntime%2Forg.argeo.sandbox.jackrabbit%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fsandbox%2Fjackrabbit%2FWebDavTest.java;h=58ba1ac1d74e517054018b950cf20eb8897fc955;hb=a550c5769a4d6044a8d45830c9097cd494a2cc1c;hp=f121e928eb17dd882d92d2fb84e30f4f19a754a7;hpb=47966699088f615c49bb4abbebfca2b2570524c1;p=lgpl%2Fargeo-commons.git diff --git a/sandbox/runtime/org.argeo.sandbox.jackrabbit/src/main/java/org/argeo/sandbox/jackrabbit/WebDavTest.java b/sandbox/runtime/org.argeo.sandbox.jackrabbit/src/main/java/org/argeo/sandbox/jackrabbit/WebDavTest.java index f121e928e..58ba1ac1d 100644 --- a/sandbox/runtime/org.argeo.sandbox.jackrabbit/src/main/java/org/argeo/sandbox/jackrabbit/WebDavTest.java +++ b/sandbox/runtime/org.argeo.sandbox.jackrabbit/src/main/java/org/argeo/sandbox/jackrabbit/WebDavTest.java @@ -1,6 +1,24 @@ +/* + * Copyright (C) 2010 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.argeo.sandbox.jackrabbit; import java.io.FileInputStream; +import java.util.ArrayList; +import java.util.List; import org.apache.commons.httpclient.Credentials; import org.apache.commons.httpclient.HostConfiguration; @@ -18,7 +36,11 @@ import org.apache.commons.logging.LogFactory; import org.apache.jackrabbit.webdav.client.methods.CheckoutMethod; import org.apache.jackrabbit.webdav.client.methods.CopyMethod; import org.apache.jackrabbit.webdav.client.methods.DavMethod; +import org.apache.jackrabbit.webdav.client.methods.PropPatchMethod; import org.apache.jackrabbit.webdav.client.methods.PutMethod; +import org.apache.jackrabbit.webdav.property.DavProperty; +import org.apache.jackrabbit.webdav.property.DefaultDavProperty; +import org.apache.jackrabbit.webdav.version.DeltaVConstants; public class WebDavTest { private final static Log log = LogFactory.getLog(WebDavTest.class); @@ -42,24 +64,47 @@ public class WebDavTest { client.setHostConfiguration(hostConfig); // return client; - String baseUrl = "http://localhost:7070/org.argeo.server.jackrabbit.webapp/default/"; - String fileName = "test.xml"; - String url1 = baseUrl + fileName; - String url2 = baseUrl + "test-copied.xml"; + String baseUrl = "http://localhost:7070/webdav/default/"; + // String fileName = "test.xml"; + String file00 = "dummy00.xls"; + String file01 = "dummy01.xls"; + String url00 = baseUrl + file00; + String url01 = baseUrl + file01; + String urlCopied = baseUrl + "test-copied.xls"; // PUT - log.debug("Create " + url1); - PutMethod pm = new PutMethod(url1); + log.debug("Create " + url00); + PutMethod pm = new PutMethod(url00); RequestEntity requestEntity = new InputStreamRequestEntity( - new FileInputStream(fileName)); + new FileInputStream(file00)); + pm.setRequestEntity(requestEntity); + client.executeMethod(pm); + log.debug("POST status: " + pm.getStatusCode() + " " + + pm.getStatusText()); + + // PROP PATCH + List props = new ArrayList(); + props.add(new DefaultDavProperty("auto-version", + DeltaVConstants.XML_CHECKOUT_CHECKIN, + DeltaVConstants.NAMESPACE)); + PropPatchMethod pp = new PropPatchMethod(url00, props); + client.executeMethod(pp); + log.debug("PROP PATCH status: " + pp.getStatusCode() + " " + + pp.getStatusText()); + + // PUT (update) + log.debug("Update " + url00); + pm = new PutMethod(url00); + requestEntity = new InputStreamRequestEntity(new FileInputStream( + file01)); pm.setRequestEntity(requestEntity); client.executeMethod(pm); log.debug("POST status: " + pm.getStatusCode() + " " + pm.getStatusText()); // COPY - log.debug("Copy to " + url2); - DavMethod copy = new CopyMethod(url1, url2, true); + log.debug("Copy to " + urlCopied); + DavMethod copy = new CopyMethod(url00, urlCopied, true); client.executeMethod(copy); log.debug("COPY status: " + copy.getStatusCode() + " " @@ -67,8 +112,8 @@ public class WebDavTest { // GET // CheckoutMethod gm = new CheckoutMethod(baseUrl + fileName); - log.debug("Retrieve " + url2); - GetMethod gm = new GetMethod(url2); + log.debug("Retrieve " + urlCopied); + GetMethod gm = new GetMethod(urlCopied); client.executeMethod(gm); String responseGet = gm.getResponseBodyAsString(); log.debug("GET status: " + gm.getStatusCode() + " " @@ -78,5 +123,4 @@ public class WebDavTest { e.printStackTrace(); } } - }