@Test(expected = InteroperabilityException.class) public void testFindLock() throws Exception { final Path test = new DAVTouchFeature(session).touch(new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus()); final DAVAttributesFinderFeature f = new DAVAttributesFinderFeature(session); assertNull(f.find(test).getLockId()); final String lockId = new DAVLockFeature(session).lock(test); assertNotNull(f.find(test).getLockId()); new DAVLockFeature(session).unlock(test, lockId); new DAVDeleteFeature(session).delete(Collections.singletonList(test), new DisabledPasswordCallback(), new Delete.DisabledCallback()); }
@Override public PathAttributes find(final Path file) 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) { 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)) { attributes.setSize(NumberUtils.toLong(headers.get(HttpHeaders.CONTENT_LENGTH), -1)); } if(headers.containsKey(HttpHeaders.ETAG)) { attributes.setETag(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); } }
DAVAttributesFinderFeature implements AttributesFinder { @Override public PathAttributes find(final Path file) 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) { 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)) { attributes.setSize(NumberUtils.toLong(headers.get(HttpHeaders.CONTENT_LENGTH), -1)); } if(headers.containsKey(HttpHeaders.ETAG)) { attributes.setETag(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); } } }
DAVAttributesFinderFeature implements AttributesFinder { @Override public PathAttributes find(final Path file) 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) { 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)) { attributes.setSize(NumberUtils.toLong(headers.get(HttpHeaders.CONTENT_LENGTH), -1)); } if(headers.containsKey(HttpHeaders.ETAG)) { attributes.setETag(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); } } DAVAttributesFinderFeature(DAVSession session); }
DAVAttributesFinderFeature implements AttributesFinder { @Override public PathAttributes find(final Path file) 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) { 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)) { attributes.setSize(NumberUtils.toLong(headers.get(HttpHeaders.CONTENT_LENGTH), -1)); } if(headers.containsKey(HttpHeaders.ETAG)) { attributes.setETag(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); } } DAVAttributesFinderFeature(DAVSession session); @Override PathAttributes find(final Path file); }
DAVAttributesFinderFeature implements AttributesFinder { @Override public PathAttributes find(final Path file) 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) { 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)) { attributes.setSize(NumberUtils.toLong(headers.get(HttpHeaders.CONTENT_LENGTH), -1)); } if(headers.containsKey(HttpHeaders.ETAG)) { attributes.setETag(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); } } DAVAttributesFinderFeature(DAVSession session); @Override PathAttributes find(final Path file);  }