use of com.github.sardine.DavResource in project cyberduck by iterate-ch.
the class DAVAttributesFinderFeatureTest method testCustomModified_NotModified.
@Test
public void testCustomModified_NotModified() throws Exception {
final DAVAttributesFinderFeature f = new DAVAttributesFinderFeature(null);
final DavResource mock = mock(DavResource.class);
Map<QName, String> map = new HashMap<>();
final String ts = "Mon, 29 Oct 2018 21:14:06 UTC";
map.put(DAVTimestampFeature.LAST_MODIFIED_CUSTOM_NAMESPACE, ts);
map.put(DAVTimestampFeature.LAST_MODIFIED_SERVER_CUSTOM_NAMESPACE, "Thu, 01 Nov 2018 15:31:57 UTC");
when(mock.getModified()).thenReturn(new DateTime("2018-11-01T15:31:57Z").toDate());
when(mock.getCustomPropsNS()).thenReturn(map);
final PathAttributes attrs = f.toAttributes(mock);
assertEquals(new RFC1123DateFormatter().parse(ts).getTime(), attrs.getModificationDate());
}
use of com.github.sardine.DavResource in project cyberduck by iterate-ch.
the class DAVAttributesFinderFeatureTest method testCustomModified_Epoch.
@Test
public void testCustomModified_Epoch() {
final DAVAttributesFinderFeature f = new DAVAttributesFinderFeature(null);
final DavResource mock = mock(DavResource.class);
Map<QName, String> map = new HashMap<>();
map.put(DAVTimestampFeature.LAST_MODIFIED_CUSTOM_NAMESPACE, "Thu, 01 Jan 1970 00:00:00 UTC");
map.put(DAVTimestampFeature.LAST_MODIFIED_SERVER_CUSTOM_NAMESPACE, "Thu, 02 Nov 2018 15:31:57 UTC");
final Date modified = new DateTime("2018-11-02T15:31:57Z").toDate();
when(mock.getModified()).thenReturn(modified);
when(mock.getCustomPropsNS()).thenReturn(map);
final PathAttributes attrs = f.toAttributes(mock);
assertEquals(modified.getTime(), attrs.getModificationDate());
}
use of com.github.sardine.DavResource in project cyberduck by iterate-ch.
the class DAVAttributesFinderFeatureTest method testCustomModified_Modified.
@Test
public void testCustomModified_Modified() {
final DAVAttributesFinderFeature f = new DAVAttributesFinderFeature(null);
final DavResource mock = mock(DavResource.class);
Map<QName, String> map = new HashMap<>();
map.put(DAVTimestampFeature.LAST_MODIFIED_CUSTOM_NAMESPACE, "Mon, 29 Oct 2018 21:14:06 UTC");
map.put(DAVTimestampFeature.LAST_MODIFIED_SERVER_CUSTOM_NAMESPACE, "Thu, 01 Nov 2018 15:31:57 UTC");
final Date modified = new DateTime("2018-11-02T15:31:57Z").toDate();
when(mock.getModified()).thenReturn(modified);
when(mock.getCustomPropsNS()).thenReturn(map);
final PathAttributes attrs = f.toAttributes(mock);
assertEquals(modified.getTime(), attrs.getModificationDate());
}
use of com.github.sardine.DavResource in project cyberduck by iterate-ch.
the class DAVAttributesFinderFeature method find.
@Override
public PathAttributes find(final Path file, final ListProgressListener listener) throws BackgroundException {
if (file.isRoot()) {
return PathAttributes.EMPTY;
}
try {
try {
for (final DavResource resource : this.list(file)) {
if (resource.isDirectory()) {
if (!file.getType().contains(Path.Type.directory)) {
throw new NotfoundException(String.format("Path %s is directory", file.getAbsolute()));
}
} else {
if (!file.getType().contains(Path.Type.file)) {
throw new NotfoundException(String.format("Path %s is file", file.getAbsolute()));
}
}
return this.toAttributes(resource);
}
throw new NotfoundException(file.getAbsolute());
} catch (SardineException e) {
try {
throw new DAVExceptionMappingService().map("Failure to read attributes of {0}", e, file);
} catch (InteroperabilityException i) {
// PROPFIND Method not allowed
log.warn(String.format("Failure with PROPFIND request for %s. %s", file, i.getMessage()));
final Map<String, String> headers = session.getClient().execute(new HttpHead(new DAVPathEncoder().encode(file)), new HeadersResponseHandler());
final PathAttributes attributes = new PathAttributes();
try {
attributes.setModificationDate(rfc1123.parse(headers.get(HttpHeaders.LAST_MODIFIED)).getTime());
} catch (InvalidDateException p) {
log.warn(String.format("%s is not RFC 1123 format %s", headers.get(HttpHeaders.LAST_MODIFIED), p.getMessage()));
}
if (!headers.containsKey(HttpHeaders.CONTENT_ENCODING)) {
// Set size unless response is compressed
attributes.setSize(NumberUtils.toLong(headers.get(HttpHeaders.CONTENT_LENGTH), -1));
}
if (headers.containsKey(HttpHeaders.ETAG)) {
attributes.setETag(headers.get(HttpHeaders.ETAG));
// Setting checksum is disabled. See #8798
// attributes.setChecksum(Checksum.parse(headers.get(HttpHeaders.ETAG)));
}
if (headers.containsKey(HttpHeaders.CONTENT_MD5)) {
attributes.setChecksum(Checksum.parse(headers.get(HttpHeaders.CONTENT_MD5)));
}
return attributes;
}
}
} catch (SardineException e) {
throw new DAVExceptionMappingService().map("Failure to read attributes of {0}", e, file);
} catch (IOException e) {
throw new HttpExceptionMappingService().map(e, file);
}
}
use of com.github.sardine.DavResource in project cyberduck by iterate-ch.
the class DAVListService method list.
@Override
public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException {
try {
final AttributedList<Path> children = new AttributedList<Path>();
for (final DavResource resource : this.list(directory)) {
// Try to parse as RFC 2396
final String href = PathNormalizer.normalize(resource.getHref().getPath(), true);
if (href.equals(directory.getAbsolute())) {
log.warn(String.format("Ignore resource %s", href));
// Do not include self
if (resource.isDirectory()) {
continue;
}
throw new NotfoundException(directory.getAbsolute());
}
final PathAttributes attr = attributes.toAttributes(resource);
final Path file = new Path(directory, PathNormalizer.name(href), resource.isDirectory() ? EnumSet.of(Path.Type.directory) : EnumSet.of(Path.Type.file), attr);
children.add(file);
listener.chunk(directory, children);
}
return children;
} catch (SardineException e) {
throw new DAVExceptionMappingService().map("Listing directory {0} failed", e, directory);
} catch (IOException e) {
throw new HttpExceptionMappingService().map(e, directory);
}
}
Aggregations