@Test public void handleWhenNoGenericPermissionForScheme() throws Exception { setUp("customscheme", "wiki3", "space3", "page3", "test.zip", Arrays.asList("test.txt")); VfsPermissionChecker checker = this.mocker.getInstance(VfsPermissionChecker.class, "cascading"); doThrow(new VfsException("no permission")).when(checker).checkPermission(this.reference); try { this.mocker.getComponentUnderTest().handle(this.reference, mock(ResourceReferenceHandlerChain.class)); fail("Should have thrown exception here"); } catch (ResourceReferenceHandlerException expected) { assertEquals("VfsException: no permission", ExceptionUtils.getRootCauseMessage(expected)); } }
@Override public void handle(ResourceReference resourceReference, ResourceReferenceHandlerChain chain) throws ResourceReferenceHandlerException { VfsResourceReference vfsResourceReference = (VfsResourceReference) resourceReference; try { this.permissionChecker.checkPermission(vfsResourceReference); URI trueVFSURI = convertResourceReference(vfsResourceReference); Path path = new TPath(trueVFSURI); try (InputStream in = Files.newInputStream(path)) { List<String> pathSegments = vfsResourceReference.getPathSegments(); serveResource(pathSegments.get(pathSegments.size() - 1), in, vfsResourceReference.getContentType()); } } catch (Exception e) { throw new ResourceReferenceHandlerException( String.format("Failed to extract resource [%s]", vfsResourceReference), e); } chain.handleNext(vfsResourceReference); }
VfsResourceReferenceHandler extends AbstractContentResourceReferenceHandler { @Override public void handle(ResourceReference resourceReference, ResourceReferenceHandlerChain chain) throws ResourceReferenceHandlerException { VfsResourceReference vfsResourceReference = (VfsResourceReference) resourceReference; try { this.permissionChecker.checkPermission(vfsResourceReference); URI trueVFSURI = convertResourceReference(vfsResourceReference); Path path = new TPath(trueVFSURI); try (InputStream in = Files.newInputStream(path)) { List<String> pathSegments = vfsResourceReference.getPathSegments(); serveResource(pathSegments.get(pathSegments.size() - 1), in, vfsResourceReference.getContentType()); } } catch (Exception e) { throw new ResourceReferenceHandlerException( String.format("Failed to extract resource [%s]", vfsResourceReference), e); } chain.handleNext(vfsResourceReference); } }
VfsResourceReferenceHandler extends AbstractContentResourceReferenceHandler { @Override public void handle(ResourceReference resourceReference, ResourceReferenceHandlerChain chain) throws ResourceReferenceHandlerException { VfsResourceReference vfsResourceReference = (VfsResourceReference) resourceReference; try { this.permissionChecker.checkPermission(vfsResourceReference); URI trueVFSURI = convertResourceReference(vfsResourceReference); Path path = new TPath(trueVFSURI); try (InputStream in = Files.newInputStream(path)) { List<String> pathSegments = vfsResourceReference.getPathSegments(); serveResource(pathSegments.get(pathSegments.size() - 1), in, vfsResourceReference.getContentType()); } } catch (Exception e) { throw new ResourceReferenceHandlerException( String.format("Failed to extract resource [%s]", vfsResourceReference), e); } chain.handleNext(vfsResourceReference); }  }
VfsResourceReferenceHandler extends AbstractContentResourceReferenceHandler { @Override public void handle(ResourceReference resourceReference, ResourceReferenceHandlerChain chain) throws ResourceReferenceHandlerException { VfsResourceReference vfsResourceReference = (VfsResourceReference) resourceReference; try { this.permissionChecker.checkPermission(vfsResourceReference); URI trueVFSURI = convertResourceReference(vfsResourceReference); Path path = new TPath(trueVFSURI); try (InputStream in = Files.newInputStream(path)) { List<String> pathSegments = vfsResourceReference.getPathSegments(); serveResource(pathSegments.get(pathSegments.size() - 1), in, vfsResourceReference.getContentType()); } } catch (Exception e) { throw new ResourceReferenceHandlerException( String.format("Failed to extract resource [%s]", vfsResourceReference), e); } chain.handleNext(vfsResourceReference); }  @Override List<ResourceType> getSupportedResourceReferences(); @Override void handle(ResourceReference resourceReference, ResourceReferenceHandlerChain chain); }
VfsResourceReferenceHandler extends AbstractContentResourceReferenceHandler { @Override public void handle(ResourceReference resourceReference, ResourceReferenceHandlerChain chain) throws ResourceReferenceHandlerException { VfsResourceReference vfsResourceReference = (VfsResourceReference) resourceReference; try { this.permissionChecker.checkPermission(vfsResourceReference); URI trueVFSURI = convertResourceReference(vfsResourceReference); Path path = new TPath(trueVFSURI); try (InputStream in = Files.newInputStream(path)) { List<String> pathSegments = vfsResourceReference.getPathSegments(); serveResource(pathSegments.get(pathSegments.size() - 1), in, vfsResourceReference.getContentType()); } } catch (Exception e) { throw new ResourceReferenceHandlerException( String.format("Failed to extract resource [%s]", vfsResourceReference), e); } chain.handleNext(vfsResourceReference); }  @Override List<ResourceType> getSupportedResourceReferences(); @Override void handle(ResourceReference resourceReference, ResourceReferenceHandlerChain chain);  }