@Test(expected = NotfoundException.class) public void testNotFound() throws Exception { final Host host = new Host(new AzureProtocol(), "kahy9boj3eib.blob.core.windows.net", new Credentials( System.getProperties().getProperty("azure.account"), System.getProperties().getProperty("azure.key") )); final AzureSession session = new AzureSession(host); new LoginConnectionService(new DisabledLoginCallback(), new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener()).connect(session, PathCache.empty(), new DisabledCancelCallback()); final Path container = new Path(UUID.randomUUID().toString(), EnumSet.of(Path.Type.directory, Path.Type.volume)); final AzureAttributesFinderFeature f = new AzureAttributesFinderFeature(session, null); f.find(new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file))); }
@Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } try { if(containerService.isContainer(file)) { final PathAttributes attributes = new PathAttributes(); final CloudBlobContainer container = session.getClient().getContainerReference(containerService.getContainer(file).getName()); container.downloadAttributes(null, null, context); final BlobContainerProperties properties = container.getProperties(); attributes.setETag(properties.getEtag()); attributes.setModificationDate(properties.getLastModified().getTime()); return attributes; } else { final CloudBlob blob = session.getClient().getContainerReference(containerService.getContainer(file).getName()) .getBlobReferenceFromServer(containerService.getKey(file)); final BlobRequestOptions options = new BlobRequestOptions(); blob.downloadAttributes(AccessCondition.generateEmptyCondition(), options, context); final BlobProperties properties = blob.getProperties(); final PathAttributes attributes = new PathAttributes(); attributes.setSize(properties.getLength()); attributes.setModificationDate(properties.getLastModified().getTime()); if(StringUtils.isNotBlank(properties.getContentMD5())) { attributes.setChecksum(Checksum.parse(Hex.encodeHexString(Base64.decodeBase64(properties.getContentMD5())))); } attributes.setETag(properties.getEtag()); final Map<String, String> custom = new HashMap<>(); custom.put(AzureAttributesFinderFeature.KEY_BLOB_TYPE, properties.getBlobType().name()); attributes.setCustom(custom); return attributes; } } catch(StorageException e) { throw new AzureExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch(URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } }
AzureAttributesFinderFeature implements AttributesFinder { @Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } try { if(containerService.isContainer(file)) { final PathAttributes attributes = new PathAttributes(); final CloudBlobContainer container = session.getClient().getContainerReference(containerService.getContainer(file).getName()); container.downloadAttributes(null, null, context); final BlobContainerProperties properties = container.getProperties(); attributes.setETag(properties.getEtag()); attributes.setModificationDate(properties.getLastModified().getTime()); return attributes; } else { final CloudBlob blob = session.getClient().getContainerReference(containerService.getContainer(file).getName()) .getBlobReferenceFromServer(containerService.getKey(file)); final BlobRequestOptions options = new BlobRequestOptions(); blob.downloadAttributes(AccessCondition.generateEmptyCondition(), options, context); final BlobProperties properties = blob.getProperties(); final PathAttributes attributes = new PathAttributes(); attributes.setSize(properties.getLength()); attributes.setModificationDate(properties.getLastModified().getTime()); if(StringUtils.isNotBlank(properties.getContentMD5())) { attributes.setChecksum(Checksum.parse(Hex.encodeHexString(Base64.decodeBase64(properties.getContentMD5())))); } attributes.setETag(properties.getEtag()); final Map<String, String> custom = new HashMap<>(); custom.put(AzureAttributesFinderFeature.KEY_BLOB_TYPE, properties.getBlobType().name()); attributes.setCustom(custom); return attributes; } } catch(StorageException e) { throw new AzureExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch(URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } } }
AzureAttributesFinderFeature implements AttributesFinder { @Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } try { if(containerService.isContainer(file)) { final PathAttributes attributes = new PathAttributes(); final CloudBlobContainer container = session.getClient().getContainerReference(containerService.getContainer(file).getName()); container.downloadAttributes(null, null, context); final BlobContainerProperties properties = container.getProperties(); attributes.setETag(properties.getEtag()); attributes.setModificationDate(properties.getLastModified().getTime()); return attributes; } else { final CloudBlob blob = session.getClient().getContainerReference(containerService.getContainer(file).getName()) .getBlobReferenceFromServer(containerService.getKey(file)); final BlobRequestOptions options = new BlobRequestOptions(); blob.downloadAttributes(AccessCondition.generateEmptyCondition(), options, context); final BlobProperties properties = blob.getProperties(); final PathAttributes attributes = new PathAttributes(); attributes.setSize(properties.getLength()); attributes.setModificationDate(properties.getLastModified().getTime()); if(StringUtils.isNotBlank(properties.getContentMD5())) { attributes.setChecksum(Checksum.parse(Hex.encodeHexString(Base64.decodeBase64(properties.getContentMD5())))); } attributes.setETag(properties.getEtag()); final Map<String, String> custom = new HashMap<>(); custom.put(AzureAttributesFinderFeature.KEY_BLOB_TYPE, properties.getBlobType().name()); attributes.setCustom(custom); return attributes; } } catch(StorageException e) { throw new AzureExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch(URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } } AzureAttributesFinderFeature(final AzureSession session, final OperationContext context); }
AzureAttributesFinderFeature implements AttributesFinder { @Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } try { if(containerService.isContainer(file)) { final PathAttributes attributes = new PathAttributes(); final CloudBlobContainer container = session.getClient().getContainerReference(containerService.getContainer(file).getName()); container.downloadAttributes(null, null, context); final BlobContainerProperties properties = container.getProperties(); attributes.setETag(properties.getEtag()); attributes.setModificationDate(properties.getLastModified().getTime()); return attributes; } else { final CloudBlob blob = session.getClient().getContainerReference(containerService.getContainer(file).getName()) .getBlobReferenceFromServer(containerService.getKey(file)); final BlobRequestOptions options = new BlobRequestOptions(); blob.downloadAttributes(AccessCondition.generateEmptyCondition(), options, context); final BlobProperties properties = blob.getProperties(); final PathAttributes attributes = new PathAttributes(); attributes.setSize(properties.getLength()); attributes.setModificationDate(properties.getLastModified().getTime()); if(StringUtils.isNotBlank(properties.getContentMD5())) { attributes.setChecksum(Checksum.parse(Hex.encodeHexString(Base64.decodeBase64(properties.getContentMD5())))); } attributes.setETag(properties.getEtag()); final Map<String, String> custom = new HashMap<>(); custom.put(AzureAttributesFinderFeature.KEY_BLOB_TYPE, properties.getBlobType().name()); attributes.setCustom(custom); return attributes; } } catch(StorageException e) { throw new AzureExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch(URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } } AzureAttributesFinderFeature(final AzureSession session, final OperationContext context); @Override PathAttributes find(final Path file); }
AzureAttributesFinderFeature implements AttributesFinder { @Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } try { if(containerService.isContainer(file)) { final PathAttributes attributes = new PathAttributes(); final CloudBlobContainer container = session.getClient().getContainerReference(containerService.getContainer(file).getName()); container.downloadAttributes(null, null, context); final BlobContainerProperties properties = container.getProperties(); attributes.setETag(properties.getEtag()); attributes.setModificationDate(properties.getLastModified().getTime()); return attributes; } else { final CloudBlob blob = session.getClient().getContainerReference(containerService.getContainer(file).getName()) .getBlobReferenceFromServer(containerService.getKey(file)); final BlobRequestOptions options = new BlobRequestOptions(); blob.downloadAttributes(AccessCondition.generateEmptyCondition(), options, context); final BlobProperties properties = blob.getProperties(); final PathAttributes attributes = new PathAttributes(); attributes.setSize(properties.getLength()); attributes.setModificationDate(properties.getLastModified().getTime()); if(StringUtils.isNotBlank(properties.getContentMD5())) { attributes.setChecksum(Checksum.parse(Hex.encodeHexString(Base64.decodeBase64(properties.getContentMD5())))); } attributes.setETag(properties.getEtag()); final Map<String, String> custom = new HashMap<>(); custom.put(AzureAttributesFinderFeature.KEY_BLOB_TYPE, properties.getBlobType().name()); attributes.setCustom(custom); return attributes; } } catch(StorageException e) { throw new AzureExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch(URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } } AzureAttributesFinderFeature(final AzureSession session, final OperationContext context); @Override PathAttributes find(final Path file); static final String KEY_BLOB_TYPE; }