@Test public void testRequestArtifactMetadataTwoPartsRepoHasDefaultLayout() throws Exception { DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + INTERNAL_REPO + "/eclipse/maven-metadata.xml", INTERNAL_REPO, new ArchivaDavLocatorFactory() ); ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO ); try { archivaConfigurationControl.reset(); expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2 ); expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo ); expect( request.getMethod() ).andReturn( "GET" ).times( 3 ); expect( request.getRemoteAddr() ).andReturn( "http: expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 ); expect( request.getContextPath() ).andReturn( "" ).times( 2 ); archivaConfigurationControl.replay(); repoContentFactoryControl.replay(); requestControl.replay(); resourceFactory.createResource( locator, request, response ); archivaConfigurationControl.verify(); repoContentFactoryControl.verify(); requestControl.verify(); fail( "A 404 error should have been thrown!" ); } catch ( DavException e ) { assertEquals( 404, e.getErrorCode() ); } }
@Override public DavResource createResource( final DavResourceLocator locator, final DavServletRequest request, final DavServletResponse response ) throws DavException { final ArchivaDavResourceLocator archivaLocator = checkLocatorIsInstanceOfRepositoryLocator( locator ); final String sRepoId = archivaLocator.getRepositoryId(); RepositoryGroup repoGroup = repositoryRegistry.getRepositoryGroup(sRepoId); final boolean isGroupRepo = repoGroup != null; String activePrincipal = getActivePrincipal( request ); List<String> resourcesInAbsolutePath = new ArrayList<>(); boolean readMethod = WebdavMethodUtil.isReadMethod( request.getMethod() ); RepositoryRequestInfo repositoryRequestInfo = null; DavResource resource; if ( isGroupRepo ) { if ( !readMethod ) { throw new DavException( HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Write method not allowed for repository groups." ); } log.debug( "Repository group '{}' accessed by '{}", repoGroup.getId(), activePrincipal ); if ( getLogicalResource( archivaLocator, null, true ).endsWith( "/" ) ) { DavResource davResource = getResourceFromGroup( request, archivaLocator, repoGroup ); setHeaders( response, locator, davResource, true ); return davResource; } else { resource = processRepositoryGroup( request, archivaLocator, activePrincipal, resourcesInAbsolutePath, repoGroup ); for (ManagedRepository repo : repoGroup.getRepositories() ) { if (repo!=null) { repositoryRequestInfo = repo.getRequestInfo(); break; } } } } else { ManagedRepository repo = repositoryRegistry.getManagedRepository( sRepoId ); if (repo==null) { throw new DavException( HttpServletResponse.SC_NOT_FOUND, "Invalid repository: " + archivaLocator.getRepositoryId() ); } ManagedRepositoryContent managedRepositoryContent = repo.getContent( ); if (managedRepositoryContent==null) { log.error("Inconsistency detected. Repository content not found for '{}'", archivaLocator.getRepositoryId()); throw new DavException( HttpServletResponse.SC_NOT_FOUND, "Invalid repository: " + archivaLocator.getRepositoryId() ); } log.debug( "Managed repository '{}' accessed by '{}'", managedRepositoryContent.getId(), activePrincipal ); resource = processRepository( request, archivaLocator, activePrincipal, managedRepositoryContent, repo); repositoryRequestInfo = repo.getRequestInfo(); String logicalResource = getLogicalResource( archivaLocator, null, false ); resourcesInAbsolutePath.add( managedRepositoryContent.getRepository().getRoot().getFilePath().resolve(logicalResource ).toAbsolutePath().toString() ); } String requestedResource = request.getRequestURI(); if ( ( repositoryRequestInfo.isMetadata( requestedResource ) || repositoryRequestInfo.isMetadataSupportFile( requestedResource ) ) && isGroupRepo ) { if ( isProjectReference( requestedResource ) ) { ArchivaDavResource res = (ArchivaDavResource) resource; String newPath; if (res.getAsset().hasParent()) { newPath = res.getAsset( ).getParent( ).getPath( ) + "/maven-metadata-" + sRepoId + ".xml"; } else { newPath = StringUtils.substringBeforeLast( res.getAsset().getPath(), "/" ) + "/maven-metadata-" + sRepoId + ".xml";; } if ( repositoryRequestInfo.isSupportFile( requestedResource ) ) { String metadataChecksumPath = newPath + "." + StringUtils.substringAfterLast( requestedResource, "." ); StorageAsset metadataChecksum = repoGroup.getAsset( metadataChecksumPath ); if ( repoGroup.getAsset( metadataChecksumPath ).exists() ) { LogicalResource logicalResource = new LogicalResource( getLogicalResource( archivaLocator, null, false ) ); try { resource = new ArchivaDavResource( metadataChecksum, logicalResource.getPath(), repoGroup, request.getRemoteAddr(), activePrincipal, request.getDavSession(), archivaLocator, this, mimeTypes, auditListeners, scheduler); } catch ( LayoutException e ) { log.error("Incompatible layout: {}", e.getMessage(), e); throw new DavException( 500, e ); } } } else { if ( resourcesInAbsolutePath != null && resourcesInAbsolutePath.size() > 1 ) { ArchivaRepositoryMetadata mergedMetadata = new ArchivaRepositoryMetadata(); for ( String resourceAbsPath : resourcesInAbsolutePath ) { try { Path metadataFile = Paths.get( resourceAbsPath ); FilesystemStorage storage = new FilesystemStorage( metadataFile.getParent( ), new DefaultFileLockManager( ) ); ArchivaRepositoryMetadata repoMetadata = repositoryRegistry.getMetadataReader( repoGroup.getType( ) ).read( storage.getAsset( metadataFile.getFileName().toString() ) ); mergedMetadata = RepositoryMetadataMerge.merge( mergedMetadata, repoMetadata ); } catch ( RepositoryMetadataException r ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while merging metadata file." ); } catch ( IOException e ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while merging metadata file." ); } } try { StorageAsset resourceFile = writeMergedMetadataToFile( repoGroup, mergedMetadata, newPath ); LogicalResource logicalResource = new LogicalResource( getLogicalResource( archivaLocator, null, false ) ); resource = new ArchivaDavResource( resourceFile, logicalResource.getPath(), repoGroup, request.getRemoteAddr(), activePrincipal, request.getDavSession(), archivaLocator, this, mimeTypes, auditListeners, scheduler); } catch ( RepositoryMetadataException r ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while writing metadata file." ); } catch ( IOException ie ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while generating checksum files." ); } catch ( LayoutException e ) { log.error("Incompatible layout: {}", e.getMessage(), e); throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Incompatible layout for repository "+repoGroup.getId()); } } } } } setHeaders( response, locator, resource, false ); if ( resource.isCollection() && !request.getRequestURI().endsWith( "/" ) ) { throw new BrowserRedirectException( resource.getHref() ); } resource.addLockManager( lockManager ); return resource; }
ArchivaDavResourceFactory implements DavResourceFactory, Auditable { @Override public DavResource createResource( final DavResourceLocator locator, final DavServletRequest request, final DavServletResponse response ) throws DavException { final ArchivaDavResourceLocator archivaLocator = checkLocatorIsInstanceOfRepositoryLocator( locator ); final String sRepoId = archivaLocator.getRepositoryId(); RepositoryGroup repoGroup = repositoryRegistry.getRepositoryGroup(sRepoId); final boolean isGroupRepo = repoGroup != null; String activePrincipal = getActivePrincipal( request ); List<String> resourcesInAbsolutePath = new ArrayList<>(); boolean readMethod = WebdavMethodUtil.isReadMethod( request.getMethod() ); RepositoryRequestInfo repositoryRequestInfo = null; DavResource resource; if ( isGroupRepo ) { if ( !readMethod ) { throw new DavException( HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Write method not allowed for repository groups." ); } log.debug( "Repository group '{}' accessed by '{}", repoGroup.getId(), activePrincipal ); if ( getLogicalResource( archivaLocator, null, true ).endsWith( "/" ) ) { DavResource davResource = getResourceFromGroup( request, archivaLocator, repoGroup ); setHeaders( response, locator, davResource, true ); return davResource; } else { resource = processRepositoryGroup( request, archivaLocator, activePrincipal, resourcesInAbsolutePath, repoGroup ); for (ManagedRepository repo : repoGroup.getRepositories() ) { if (repo!=null) { repositoryRequestInfo = repo.getRequestInfo(); break; } } } } else { ManagedRepository repo = repositoryRegistry.getManagedRepository( sRepoId ); if (repo==null) { throw new DavException( HttpServletResponse.SC_NOT_FOUND, "Invalid repository: " + archivaLocator.getRepositoryId() ); } ManagedRepositoryContent managedRepositoryContent = repo.getContent( ); if (managedRepositoryContent==null) { log.error("Inconsistency detected. Repository content not found for '{}'", archivaLocator.getRepositoryId()); throw new DavException( HttpServletResponse.SC_NOT_FOUND, "Invalid repository: " + archivaLocator.getRepositoryId() ); } log.debug( "Managed repository '{}' accessed by '{}'", managedRepositoryContent.getId(), activePrincipal ); resource = processRepository( request, archivaLocator, activePrincipal, managedRepositoryContent, repo); repositoryRequestInfo = repo.getRequestInfo(); String logicalResource = getLogicalResource( archivaLocator, null, false ); resourcesInAbsolutePath.add( managedRepositoryContent.getRepository().getRoot().getFilePath().resolve(logicalResource ).toAbsolutePath().toString() ); } String requestedResource = request.getRequestURI(); if ( ( repositoryRequestInfo.isMetadata( requestedResource ) || repositoryRequestInfo.isMetadataSupportFile( requestedResource ) ) && isGroupRepo ) { if ( isProjectReference( requestedResource ) ) { ArchivaDavResource res = (ArchivaDavResource) resource; String newPath; if (res.getAsset().hasParent()) { newPath = res.getAsset( ).getParent( ).getPath( ) + "/maven-metadata-" + sRepoId + ".xml"; } else { newPath = StringUtils.substringBeforeLast( res.getAsset().getPath(), "/" ) + "/maven-metadata-" + sRepoId + ".xml";; } if ( repositoryRequestInfo.isSupportFile( requestedResource ) ) { String metadataChecksumPath = newPath + "." + StringUtils.substringAfterLast( requestedResource, "." ); StorageAsset metadataChecksum = repoGroup.getAsset( metadataChecksumPath ); if ( repoGroup.getAsset( metadataChecksumPath ).exists() ) { LogicalResource logicalResource = new LogicalResource( getLogicalResource( archivaLocator, null, false ) ); try { resource = new ArchivaDavResource( metadataChecksum, logicalResource.getPath(), repoGroup, request.getRemoteAddr(), activePrincipal, request.getDavSession(), archivaLocator, this, mimeTypes, auditListeners, scheduler); } catch ( LayoutException e ) { log.error("Incompatible layout: {}", e.getMessage(), e); throw new DavException( 500, e ); } } } else { if ( resourcesInAbsolutePath != null && resourcesInAbsolutePath.size() > 1 ) { ArchivaRepositoryMetadata mergedMetadata = new ArchivaRepositoryMetadata(); for ( String resourceAbsPath : resourcesInAbsolutePath ) { try { Path metadataFile = Paths.get( resourceAbsPath ); FilesystemStorage storage = new FilesystemStorage( metadataFile.getParent( ), new DefaultFileLockManager( ) ); ArchivaRepositoryMetadata repoMetadata = repositoryRegistry.getMetadataReader( repoGroup.getType( ) ).read( storage.getAsset( metadataFile.getFileName().toString() ) ); mergedMetadata = RepositoryMetadataMerge.merge( mergedMetadata, repoMetadata ); } catch ( RepositoryMetadataException r ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while merging metadata file." ); } catch ( IOException e ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while merging metadata file." ); } } try { StorageAsset resourceFile = writeMergedMetadataToFile( repoGroup, mergedMetadata, newPath ); LogicalResource logicalResource = new LogicalResource( getLogicalResource( archivaLocator, null, false ) ); resource = new ArchivaDavResource( resourceFile, logicalResource.getPath(), repoGroup, request.getRemoteAddr(), activePrincipal, request.getDavSession(), archivaLocator, this, mimeTypes, auditListeners, scheduler); } catch ( RepositoryMetadataException r ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while writing metadata file." ); } catch ( IOException ie ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while generating checksum files." ); } catch ( LayoutException e ) { log.error("Incompatible layout: {}", e.getMessage(), e); throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Incompatible layout for repository "+repoGroup.getId()); } } } } } setHeaders( response, locator, resource, false ); if ( resource.isCollection() && !request.getRequestURI().endsWith( "/" ) ) { throw new BrowserRedirectException( resource.getHref() ); } resource.addLockManager( lockManager ); return resource; } }
ArchivaDavResourceFactory implements DavResourceFactory, Auditable { @Override public DavResource createResource( final DavResourceLocator locator, final DavServletRequest request, final DavServletResponse response ) throws DavException { final ArchivaDavResourceLocator archivaLocator = checkLocatorIsInstanceOfRepositoryLocator( locator ); final String sRepoId = archivaLocator.getRepositoryId(); RepositoryGroup repoGroup = repositoryRegistry.getRepositoryGroup(sRepoId); final boolean isGroupRepo = repoGroup != null; String activePrincipal = getActivePrincipal( request ); List<String> resourcesInAbsolutePath = new ArrayList<>(); boolean readMethod = WebdavMethodUtil.isReadMethod( request.getMethod() ); RepositoryRequestInfo repositoryRequestInfo = null; DavResource resource; if ( isGroupRepo ) { if ( !readMethod ) { throw new DavException( HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Write method not allowed for repository groups." ); } log.debug( "Repository group '{}' accessed by '{}", repoGroup.getId(), activePrincipal ); if ( getLogicalResource( archivaLocator, null, true ).endsWith( "/" ) ) { DavResource davResource = getResourceFromGroup( request, archivaLocator, repoGroup ); setHeaders( response, locator, davResource, true ); return davResource; } else { resource = processRepositoryGroup( request, archivaLocator, activePrincipal, resourcesInAbsolutePath, repoGroup ); for (ManagedRepository repo : repoGroup.getRepositories() ) { if (repo!=null) { repositoryRequestInfo = repo.getRequestInfo(); break; } } } } else { ManagedRepository repo = repositoryRegistry.getManagedRepository( sRepoId ); if (repo==null) { throw new DavException( HttpServletResponse.SC_NOT_FOUND, "Invalid repository: " + archivaLocator.getRepositoryId() ); } ManagedRepositoryContent managedRepositoryContent = repo.getContent( ); if (managedRepositoryContent==null) { log.error("Inconsistency detected. Repository content not found for '{}'", archivaLocator.getRepositoryId()); throw new DavException( HttpServletResponse.SC_NOT_FOUND, "Invalid repository: " + archivaLocator.getRepositoryId() ); } log.debug( "Managed repository '{}' accessed by '{}'", managedRepositoryContent.getId(), activePrincipal ); resource = processRepository( request, archivaLocator, activePrincipal, managedRepositoryContent, repo); repositoryRequestInfo = repo.getRequestInfo(); String logicalResource = getLogicalResource( archivaLocator, null, false ); resourcesInAbsolutePath.add( managedRepositoryContent.getRepository().getRoot().getFilePath().resolve(logicalResource ).toAbsolutePath().toString() ); } String requestedResource = request.getRequestURI(); if ( ( repositoryRequestInfo.isMetadata( requestedResource ) || repositoryRequestInfo.isMetadataSupportFile( requestedResource ) ) && isGroupRepo ) { if ( isProjectReference( requestedResource ) ) { ArchivaDavResource res = (ArchivaDavResource) resource; String newPath; if (res.getAsset().hasParent()) { newPath = res.getAsset( ).getParent( ).getPath( ) + "/maven-metadata-" + sRepoId + ".xml"; } else { newPath = StringUtils.substringBeforeLast( res.getAsset().getPath(), "/" ) + "/maven-metadata-" + sRepoId + ".xml";; } if ( repositoryRequestInfo.isSupportFile( requestedResource ) ) { String metadataChecksumPath = newPath + "." + StringUtils.substringAfterLast( requestedResource, "." ); StorageAsset metadataChecksum = repoGroup.getAsset( metadataChecksumPath ); if ( repoGroup.getAsset( metadataChecksumPath ).exists() ) { LogicalResource logicalResource = new LogicalResource( getLogicalResource( archivaLocator, null, false ) ); try { resource = new ArchivaDavResource( metadataChecksum, logicalResource.getPath(), repoGroup, request.getRemoteAddr(), activePrincipal, request.getDavSession(), archivaLocator, this, mimeTypes, auditListeners, scheduler); } catch ( LayoutException e ) { log.error("Incompatible layout: {}", e.getMessage(), e); throw new DavException( 500, e ); } } } else { if ( resourcesInAbsolutePath != null && resourcesInAbsolutePath.size() > 1 ) { ArchivaRepositoryMetadata mergedMetadata = new ArchivaRepositoryMetadata(); for ( String resourceAbsPath : resourcesInAbsolutePath ) { try { Path metadataFile = Paths.get( resourceAbsPath ); FilesystemStorage storage = new FilesystemStorage( metadataFile.getParent( ), new DefaultFileLockManager( ) ); ArchivaRepositoryMetadata repoMetadata = repositoryRegistry.getMetadataReader( repoGroup.getType( ) ).read( storage.getAsset( metadataFile.getFileName().toString() ) ); mergedMetadata = RepositoryMetadataMerge.merge( mergedMetadata, repoMetadata ); } catch ( RepositoryMetadataException r ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while merging metadata file." ); } catch ( IOException e ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while merging metadata file." ); } } try { StorageAsset resourceFile = writeMergedMetadataToFile( repoGroup, mergedMetadata, newPath ); LogicalResource logicalResource = new LogicalResource( getLogicalResource( archivaLocator, null, false ) ); resource = new ArchivaDavResource( resourceFile, logicalResource.getPath(), repoGroup, request.getRemoteAddr(), activePrincipal, request.getDavSession(), archivaLocator, this, mimeTypes, auditListeners, scheduler); } catch ( RepositoryMetadataException r ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while writing metadata file." ); } catch ( IOException ie ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while generating checksum files." ); } catch ( LayoutException e ) { log.error("Incompatible layout: {}", e.getMessage(), e); throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Incompatible layout for repository "+repoGroup.getId()); } } } } } setHeaders( response, locator, resource, false ); if ( resource.isCollection() && !request.getRequestURI().endsWith( "/" ) ) { throw new BrowserRedirectException( resource.getHref() ); } resource.addLockManager( lockManager ); return resource; } @Inject  ArchivaDavResourceFactory( ApplicationContext applicationContext, ArchivaConfiguration archivaConfiguration ); }
ArchivaDavResourceFactory implements DavResourceFactory, Auditable { @Override public DavResource createResource( final DavResourceLocator locator, final DavServletRequest request, final DavServletResponse response ) throws DavException { final ArchivaDavResourceLocator archivaLocator = checkLocatorIsInstanceOfRepositoryLocator( locator ); final String sRepoId = archivaLocator.getRepositoryId(); RepositoryGroup repoGroup = repositoryRegistry.getRepositoryGroup(sRepoId); final boolean isGroupRepo = repoGroup != null; String activePrincipal = getActivePrincipal( request ); List<String> resourcesInAbsolutePath = new ArrayList<>(); boolean readMethod = WebdavMethodUtil.isReadMethod( request.getMethod() ); RepositoryRequestInfo repositoryRequestInfo = null; DavResource resource; if ( isGroupRepo ) { if ( !readMethod ) { throw new DavException( HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Write method not allowed for repository groups." ); } log.debug( "Repository group '{}' accessed by '{}", repoGroup.getId(), activePrincipal ); if ( getLogicalResource( archivaLocator, null, true ).endsWith( "/" ) ) { DavResource davResource = getResourceFromGroup( request, archivaLocator, repoGroup ); setHeaders( response, locator, davResource, true ); return davResource; } else { resource = processRepositoryGroup( request, archivaLocator, activePrincipal, resourcesInAbsolutePath, repoGroup ); for (ManagedRepository repo : repoGroup.getRepositories() ) { if (repo!=null) { repositoryRequestInfo = repo.getRequestInfo(); break; } } } } else { ManagedRepository repo = repositoryRegistry.getManagedRepository( sRepoId ); if (repo==null) { throw new DavException( HttpServletResponse.SC_NOT_FOUND, "Invalid repository: " + archivaLocator.getRepositoryId() ); } ManagedRepositoryContent managedRepositoryContent = repo.getContent( ); if (managedRepositoryContent==null) { log.error("Inconsistency detected. Repository content not found for '{}'", archivaLocator.getRepositoryId()); throw new DavException( HttpServletResponse.SC_NOT_FOUND, "Invalid repository: " + archivaLocator.getRepositoryId() ); } log.debug( "Managed repository '{}' accessed by '{}'", managedRepositoryContent.getId(), activePrincipal ); resource = processRepository( request, archivaLocator, activePrincipal, managedRepositoryContent, repo); repositoryRequestInfo = repo.getRequestInfo(); String logicalResource = getLogicalResource( archivaLocator, null, false ); resourcesInAbsolutePath.add( managedRepositoryContent.getRepository().getRoot().getFilePath().resolve(logicalResource ).toAbsolutePath().toString() ); } String requestedResource = request.getRequestURI(); if ( ( repositoryRequestInfo.isMetadata( requestedResource ) || repositoryRequestInfo.isMetadataSupportFile( requestedResource ) ) && isGroupRepo ) { if ( isProjectReference( requestedResource ) ) { ArchivaDavResource res = (ArchivaDavResource) resource; String newPath; if (res.getAsset().hasParent()) { newPath = res.getAsset( ).getParent( ).getPath( ) + "/maven-metadata-" + sRepoId + ".xml"; } else { newPath = StringUtils.substringBeforeLast( res.getAsset().getPath(), "/" ) + "/maven-metadata-" + sRepoId + ".xml";; } if ( repositoryRequestInfo.isSupportFile( requestedResource ) ) { String metadataChecksumPath = newPath + "." + StringUtils.substringAfterLast( requestedResource, "." ); StorageAsset metadataChecksum = repoGroup.getAsset( metadataChecksumPath ); if ( repoGroup.getAsset( metadataChecksumPath ).exists() ) { LogicalResource logicalResource = new LogicalResource( getLogicalResource( archivaLocator, null, false ) ); try { resource = new ArchivaDavResource( metadataChecksum, logicalResource.getPath(), repoGroup, request.getRemoteAddr(), activePrincipal, request.getDavSession(), archivaLocator, this, mimeTypes, auditListeners, scheduler); } catch ( LayoutException e ) { log.error("Incompatible layout: {}", e.getMessage(), e); throw new DavException( 500, e ); } } } else { if ( resourcesInAbsolutePath != null && resourcesInAbsolutePath.size() > 1 ) { ArchivaRepositoryMetadata mergedMetadata = new ArchivaRepositoryMetadata(); for ( String resourceAbsPath : resourcesInAbsolutePath ) { try { Path metadataFile = Paths.get( resourceAbsPath ); FilesystemStorage storage = new FilesystemStorage( metadataFile.getParent( ), new DefaultFileLockManager( ) ); ArchivaRepositoryMetadata repoMetadata = repositoryRegistry.getMetadataReader( repoGroup.getType( ) ).read( storage.getAsset( metadataFile.getFileName().toString() ) ); mergedMetadata = RepositoryMetadataMerge.merge( mergedMetadata, repoMetadata ); } catch ( RepositoryMetadataException r ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while merging metadata file." ); } catch ( IOException e ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while merging metadata file." ); } } try { StorageAsset resourceFile = writeMergedMetadataToFile( repoGroup, mergedMetadata, newPath ); LogicalResource logicalResource = new LogicalResource( getLogicalResource( archivaLocator, null, false ) ); resource = new ArchivaDavResource( resourceFile, logicalResource.getPath(), repoGroup, request.getRemoteAddr(), activePrincipal, request.getDavSession(), archivaLocator, this, mimeTypes, auditListeners, scheduler); } catch ( RepositoryMetadataException r ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while writing metadata file." ); } catch ( IOException ie ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while generating checksum files." ); } catch ( LayoutException e ) { log.error("Incompatible layout: {}", e.getMessage(), e); throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Incompatible layout for repository "+repoGroup.getId()); } } } } } setHeaders( response, locator, resource, false ); if ( resource.isCollection() && !request.getRequestURI().endsWith( "/" ) ) { throw new BrowserRedirectException( resource.getHref() ); } resource.addLockManager( lockManager ); return resource; } @Inject  ArchivaDavResourceFactory( ApplicationContext applicationContext, ArchivaConfiguration archivaConfiguration ); @PostConstruct void initialize(); @Override DavResource createResource( final DavResourceLocator locator, final DavServletRequest request,
                                       final DavServletResponse response ); @Override DavResource createResource( final DavResourceLocator locator, final DavSession davSession ); @Override void addAuditListener( AuditListener listener ); @Override void clearAuditListeners(); @Override void removeAuditListener( AuditListener listener ); void setProxyRegistry(ProxyRegistry proxyRegistry); ProxyRegistry getProxyRegistry(); void setServletAuth( ServletAuthenticator servletAuth ); void setHttpAuth( HttpAuthenticator httpAuth ); void setScheduler( RepositoryArchivaTaskScheduler scheduler ); void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration ); RemoteRepositoryAdmin getRemoteRepositoryAdmin(); void setRemoteRepositoryAdmin( RemoteRepositoryAdmin remoteRepositoryAdmin ); ManagedRepositoryAdmin getManagedRepositoryAdmin(); void setManagedRepositoryAdmin( ManagedRepositoryAdmin managedRepositoryAdmin ); RepositoryRegistry getRepositoryRegistry( ); void setRepositoryRegistry( RepositoryRegistry repositoryRegistry ); }
ArchivaDavResourceFactory implements DavResourceFactory, Auditable { @Override public DavResource createResource( final DavResourceLocator locator, final DavServletRequest request, final DavServletResponse response ) throws DavException { final ArchivaDavResourceLocator archivaLocator = checkLocatorIsInstanceOfRepositoryLocator( locator ); final String sRepoId = archivaLocator.getRepositoryId(); RepositoryGroup repoGroup = repositoryRegistry.getRepositoryGroup(sRepoId); final boolean isGroupRepo = repoGroup != null; String activePrincipal = getActivePrincipal( request ); List<String> resourcesInAbsolutePath = new ArrayList<>(); boolean readMethod = WebdavMethodUtil.isReadMethod( request.getMethod() ); RepositoryRequestInfo repositoryRequestInfo = null; DavResource resource; if ( isGroupRepo ) { if ( !readMethod ) { throw new DavException( HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Write method not allowed for repository groups." ); } log.debug( "Repository group '{}' accessed by '{}", repoGroup.getId(), activePrincipal ); if ( getLogicalResource( archivaLocator, null, true ).endsWith( "/" ) ) { DavResource davResource = getResourceFromGroup( request, archivaLocator, repoGroup ); setHeaders( response, locator, davResource, true ); return davResource; } else { resource = processRepositoryGroup( request, archivaLocator, activePrincipal, resourcesInAbsolutePath, repoGroup ); for (ManagedRepository repo : repoGroup.getRepositories() ) { if (repo!=null) { repositoryRequestInfo = repo.getRequestInfo(); break; } } } } else { ManagedRepository repo = repositoryRegistry.getManagedRepository( sRepoId ); if (repo==null) { throw new DavException( HttpServletResponse.SC_NOT_FOUND, "Invalid repository: " + archivaLocator.getRepositoryId() ); } ManagedRepositoryContent managedRepositoryContent = repo.getContent( ); if (managedRepositoryContent==null) { log.error("Inconsistency detected. Repository content not found for '{}'", archivaLocator.getRepositoryId()); throw new DavException( HttpServletResponse.SC_NOT_FOUND, "Invalid repository: " + archivaLocator.getRepositoryId() ); } log.debug( "Managed repository '{}' accessed by '{}'", managedRepositoryContent.getId(), activePrincipal ); resource = processRepository( request, archivaLocator, activePrincipal, managedRepositoryContent, repo); repositoryRequestInfo = repo.getRequestInfo(); String logicalResource = getLogicalResource( archivaLocator, null, false ); resourcesInAbsolutePath.add( managedRepositoryContent.getRepository().getRoot().getFilePath().resolve(logicalResource ).toAbsolutePath().toString() ); } String requestedResource = request.getRequestURI(); if ( ( repositoryRequestInfo.isMetadata( requestedResource ) || repositoryRequestInfo.isMetadataSupportFile( requestedResource ) ) && isGroupRepo ) { if ( isProjectReference( requestedResource ) ) { ArchivaDavResource res = (ArchivaDavResource) resource; String newPath; if (res.getAsset().hasParent()) { newPath = res.getAsset( ).getParent( ).getPath( ) + "/maven-metadata-" + sRepoId + ".xml"; } else { newPath = StringUtils.substringBeforeLast( res.getAsset().getPath(), "/" ) + "/maven-metadata-" + sRepoId + ".xml";; } if ( repositoryRequestInfo.isSupportFile( requestedResource ) ) { String metadataChecksumPath = newPath + "." + StringUtils.substringAfterLast( requestedResource, "." ); StorageAsset metadataChecksum = repoGroup.getAsset( metadataChecksumPath ); if ( repoGroup.getAsset( metadataChecksumPath ).exists() ) { LogicalResource logicalResource = new LogicalResource( getLogicalResource( archivaLocator, null, false ) ); try { resource = new ArchivaDavResource( metadataChecksum, logicalResource.getPath(), repoGroup, request.getRemoteAddr(), activePrincipal, request.getDavSession(), archivaLocator, this, mimeTypes, auditListeners, scheduler); } catch ( LayoutException e ) { log.error("Incompatible layout: {}", e.getMessage(), e); throw new DavException( 500, e ); } } } else { if ( resourcesInAbsolutePath != null && resourcesInAbsolutePath.size() > 1 ) { ArchivaRepositoryMetadata mergedMetadata = new ArchivaRepositoryMetadata(); for ( String resourceAbsPath : resourcesInAbsolutePath ) { try { Path metadataFile = Paths.get( resourceAbsPath ); FilesystemStorage storage = new FilesystemStorage( metadataFile.getParent( ), new DefaultFileLockManager( ) ); ArchivaRepositoryMetadata repoMetadata = repositoryRegistry.getMetadataReader( repoGroup.getType( ) ).read( storage.getAsset( metadataFile.getFileName().toString() ) ); mergedMetadata = RepositoryMetadataMerge.merge( mergedMetadata, repoMetadata ); } catch ( RepositoryMetadataException r ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while merging metadata file." ); } catch ( IOException e ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while merging metadata file." ); } } try { StorageAsset resourceFile = writeMergedMetadataToFile( repoGroup, mergedMetadata, newPath ); LogicalResource logicalResource = new LogicalResource( getLogicalResource( archivaLocator, null, false ) ); resource = new ArchivaDavResource( resourceFile, logicalResource.getPath(), repoGroup, request.getRemoteAddr(), activePrincipal, request.getDavSession(), archivaLocator, this, mimeTypes, auditListeners, scheduler); } catch ( RepositoryMetadataException r ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while writing metadata file." ); } catch ( IOException ie ) { throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while generating checksum files." ); } catch ( LayoutException e ) { log.error("Incompatible layout: {}", e.getMessage(), e); throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Incompatible layout for repository "+repoGroup.getId()); } } } } } setHeaders( response, locator, resource, false ); if ( resource.isCollection() && !request.getRequestURI().endsWith( "/" ) ) { throw new BrowserRedirectException( resource.getHref() ); } resource.addLockManager( lockManager ); return resource; } @Inject  ArchivaDavResourceFactory( ApplicationContext applicationContext, ArchivaConfiguration archivaConfiguration ); @PostConstruct void initialize(); @Override DavResource createResource( final DavResourceLocator locator, final DavServletRequest request,
                                       final DavServletResponse response ); @Override DavResource createResource( final DavResourceLocator locator, final DavSession davSession ); @Override void addAuditListener( AuditListener listener ); @Override void clearAuditListeners(); @Override void removeAuditListener( AuditListener listener ); void setProxyRegistry(ProxyRegistry proxyRegistry); ProxyRegistry getProxyRegistry(); void setServletAuth( ServletAuthenticator servletAuth ); void setHttpAuth( HttpAuthenticator httpAuth ); void setScheduler( RepositoryArchivaTaskScheduler scheduler ); void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration ); RemoteRepositoryAdmin getRemoteRepositoryAdmin(); void setRemoteRepositoryAdmin( RemoteRepositoryAdmin remoteRepositoryAdmin ); ManagedRepositoryAdmin getManagedRepositoryAdmin(); void setManagedRepositoryAdmin( ManagedRepositoryAdmin managedRepositoryAdmin ); RepositoryRegistry getRepositoryRegistry( ); void setRepositoryRegistry( RepositoryRegistry repositoryRegistry );  }