Search in sources :

Example 1 with DavPropertyIterator

use of org.apache.jackrabbit.webdav.property.DavPropertyIterator in project lobcder by skoulouzis.

the class Utils method getResourceUID.

Long getResourceUID(String resource) throws IOException, DavException {
    DavPropertyName etag = DavPropertyName.create("getetag", Namespace.getNamespace("DAV:"));
    MultiStatus multiStatus = getProperty(resource, etag, true);
    MultiStatusResponse[] responses = multiStatus.getResponses();
    String value = null;
    // for (MultiStatusResponse r : responses) {
    DavPropertySet allProp = getProperties(responses[0]);
    DavPropertyIterator iter = allProp.iterator();
    while (iter.hasNext()) {
        DavProperty<?> p = iter.nextProperty();
        assertNotNull(p.getValue());
        assertEquals(p.getName(), etag);
        value = (String) p.getValue();
        value = value.replaceAll("\"", "");
        break;
    }
    return Long.valueOf(value.split("_")[0]);
}
Also used : DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) DavPropertyIterator(org.apache.jackrabbit.webdav.property.DavPropertyIterator) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName)

Example 2 with DavPropertyIterator

use of org.apache.jackrabbit.webdav.property.DavPropertyIterator in project lobcder by skoulouzis.

the class Utils method getAvailableStorageSites.

public String[] getAvailableStorageSites(String testuri1) throws IOException, DavException {
    DavPropertyNameSet availableStorageSitesNameSet = new DavPropertyNameSet();
    DavPropertyName availableStorageSitesName = DavPropertyName.create("avail-storage-sites", Namespace.getNamespace("custom:"));
    availableStorageSitesNameSet.add(availableStorageSitesName);
    PropFindMethod propFind = new PropFindMethod(testuri1, availableStorageSitesNameSet, DavConstants.DEPTH_INFINITY);
    int status = client.executeMethod(propFind);
    assertEquals(HttpStatus.SC_MULTI_STATUS, status);
    MultiStatus multiStatus = propFind.getResponseBodyAsMultiStatus();
    MultiStatusResponse[] responses = multiStatus.getResponses();
    String value = null;
    for (MultiStatusResponse r : responses) {
        DavPropertySet allProp = getProperties(r);
        DavPropertyIterator iter = allProp.iterator();
        while (iter.hasNext()) {
            DavProperty<?> p = iter.nextProperty();
            assertEquals(p.getName(), availableStorageSitesName);
            assertNotNull(p.getValue());
            value = (String) p.getValue();
        }
    }
    String sites = value.replaceAll("[\\[\\]]", "");
    return sites.split(",");
}
Also used : DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) PropFindMethod(org.apache.jackrabbit.webdav.client.methods.PropFindMethod) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) DavPropertyIterator(org.apache.jackrabbit.webdav.property.DavPropertyIterator) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName)

Example 3 with DavPropertyIterator

use of org.apache.jackrabbit.webdav.property.DavPropertyIterator in project lobcder by skoulouzis.

the class Utils method resourceExists.

boolean resourceExists(String resource) throws IOException, DavException {
    try {
        MultiStatus multiStatus = this.getProperty(resource, DavPropertyName.DISPLAYNAME, false);
        MultiStatusResponse[] responses = multiStatus.getResponses();
        String value = null;
        // for (MultiStatusResponse r : responses) {
        DavPropertySet allProp = getProperties(responses[0]);
        DavPropertyIterator iter = allProp.iterator();
        while (iter.hasNext()) {
            DavProperty<?> p = iter.nextProperty();
            assertNotNull(p.getValue());
            value = (String) p.getValue();
            System.err.println(p.getName() + ":" + p.getValue());
            break;
        }
        if (value != null) {
            return true;
        } else {
            return false;
        }
    } catch (DavException ex) {
        if (ex.getMessage().contains("Not Found")) {
            return false;
        } else {
            throw ex;
        }
    }
}
Also used : DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) DavException(org.apache.jackrabbit.webdav.DavException) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) DavPropertyIterator(org.apache.jackrabbit.webdav.property.DavPropertyIterator)

Example 4 with DavPropertyIterator

use of org.apache.jackrabbit.webdav.property.DavPropertyIterator in project lobcder by skoulouzis.

the class Utils method waitForReplication.

public void waitForReplication(String resource) throws IOException, DavException, InterruptedException {
    boolean done = false;
    int count = 0;
    String[] availStorageSites = getAvailableStorageSites(resource);
    while (!done) {
        DavPropertyName dataDistributionName = DavPropertyName.create("data-distribution", Namespace.getNamespace("custom:"));
        MultiStatus multiStatus = getProperty(resource, dataDistributionName, true);
        MultiStatusResponse[] responses = multiStatus.getResponses();
        String dataDist = null;
        for (MultiStatusResponse r : responses) {
            // System.out.println("Response: " + r.getHref());
            DavPropertySet allProp = getProperties(r);
            DavPropertyIterator iter = allProp.iterator();
            while (iter.hasNext()) {
                DavProperty<?> p = iter.nextProperty();
                assertEquals(p.getName(), dataDistributionName);
                assertNotNull(p.getValue());
                dataDist = (String) p.getValue();
                if (dataDist.contains(availStorageSites[0])) {
                    done = true;
                    assertTrue(dataDist.contains(availStorageSites[0]));
                    break;
                } else if (availStorageSites.length > 1 && dataDist.contains(availStorageSites[1])) {
                    done = true;
                    assertTrue(dataDist.contains(availStorageSites[1]));
                    break;
                } else {
                    count++;
                }
            // System.out.println(p.getName() + " : " + p.getValue());
            }
        }
        if (count > 200) {
            fail(resource + " is not replicated in " + availStorageSites[0] + " or " + availStorageSites[1] + " it is in " + dataDist);
            break;
        }
        if (done) {
            break;
        } else {
            Thread.sleep(7000);
        }
    }
}
Also used : DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) DavPropertyIterator(org.apache.jackrabbit.webdav.property.DavPropertyIterator) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName)

Aggregations

MultiStatus (org.apache.jackrabbit.webdav.MultiStatus)4 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)4 DavPropertyIterator (org.apache.jackrabbit.webdav.property.DavPropertyIterator)4 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)4 DavPropertyName (org.apache.jackrabbit.webdav.property.DavPropertyName)3 DavException (org.apache.jackrabbit.webdav.DavException)1 PropFindMethod (org.apache.jackrabbit.webdav.client.methods.PropFindMethod)1 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)1