From c3ee919adca4bd3278ee6d80b0d06b0115844297 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 2 Apr 2012 07:20:23 +0000 Subject: [PATCH] fix concurrent access when uploading files in parallel git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1308258 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/archiva/i18n/default.properties | 2 + .../api/DefaultFileUploadService.java | 41 +++++++++++-------- .../webapp/js/archiva/artifacts-management.js | 2 +- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties b/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties index cf8e23b87..327512da7 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties +++ b/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties @@ -398,5 +398,7 @@ fileupload.packaging=Packaging fileupload.generatePom=Generate Maven POM fileupload.repositoryId=Repository Id fileupload.save=Save Files +fileupload.upload.required=You must upload your files first. +fileupload.artifacts.saved=Artifacts uploaded and saved on Server side. diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/DefaultFileUploadService.java b/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/DefaultFileUploadService.java index 411eef67d..f9ca3d0d1 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/DefaultFileUploadService.java +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/DefaultFileUploadService.java @@ -81,6 +81,7 @@ import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.TimeZone; +import java.util.concurrent.CopyOnWriteArrayList; /** * @author Olivier Lamy @@ -123,13 +124,6 @@ public class DefaultFileUploadService try { - String groupId = getStringValue( multipartBody, "groupId" ); - - String artifactId = getStringValue( multipartBody, "artifactId" ); - - String version = getStringValue( multipartBody, "version" ); - - String packaging = getStringValue( multipartBody, "packaging" ); String classifier = getStringValue( multipartBody, "classifier" ); boolean pomFile = BooleanUtils.toBoolean( getStringValue( multipartBody, "pomFile" ) ); @@ -148,17 +142,12 @@ public class DefaultFileUploadService fileMetadata.setDeleteUrl( tmpFile.getName() ); fileMetadata.setPomFile( pomFile ); - log.info( "uploading file:{}", fileMetadata ); + log.info( "uploading file: {}", fileMetadata ); - List fileMetadatas = - (List) httpServletRequest.getSession().getAttribute( FILES_SESSION_KEY ); + List fileMetadatas = getSessionFilesList(); - if ( fileMetadatas == null ) - { - fileMetadatas = new ArrayList( 1 ); - } fileMetadatas.add( fileMetadata ); - httpServletRequest.getSession().setAttribute( FILES_SESSION_KEY, fileMetadatas ); + return fileMetadata; } catch ( IOException e ) @@ -169,6 +158,23 @@ public class DefaultFileUploadService } + /** + * FIXME must be per session synchronized not globally + * + * @return + */ + protected synchronized List getSessionFilesList() + { + List fileMetadatas = + (List) httpServletRequest.getSession().getAttribute( FILES_SESSION_KEY ); + if ( fileMetadatas == null ) + { + fileMetadatas = new CopyOnWriteArrayList(); + httpServletRequest.getSession().setAttribute( FILES_SESSION_KEY, fileMetadatas ); + } + return fileMetadatas; + } + public Boolean deleteFile( String fileName ) throws ArchivaRestServiceException { @@ -206,8 +212,7 @@ public class DefaultFileUploadService String packaging, final boolean generatePom ) throws ArchivaRestServiceException { - List fileMetadatas = - (List) httpServletRequest.getSession().getAttribute( FILES_SESSION_KEY ); + List fileMetadatas = getSessionFilesList(); if ( fileMetadatas == null || fileMetadatas.isEmpty() ) { return Boolean.FALSE; @@ -230,6 +235,7 @@ public class DefaultFileUploadService saveFile( repositoryId, fileMetadata, generatePom && !pomGenerated, groupId, artifactId, version, packaging ); pomGenerated = true; + deleteFile( fileMetadata.getServerFileName() ); } filesToAdd = Iterables.filter( fileMetadatas, new Predicate() @@ -246,6 +252,7 @@ public class DefaultFileUploadService FileMetadata fileMetadata = iterator.next(); log.debug( "fileToAdd: {}", fileMetadata ); savePomFile( repositoryId, fileMetadata, groupId, artifactId, version, packaging ); + deleteFile( fileMetadata.getServerFileName() ); } return Boolean.TRUE; diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/artifacts-management.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/artifacts-management.js index 53e5880ae..a7abf0fe7 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/artifacts-management.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/artifacts-management.js @@ -55,7 +55,7 @@ define("archiva.artifacts-management",["jquery","i18n","order!utils","order!jque type: "GET", dataType: 'json', success: function(data) { - + displaySuccessMessage($.i18n.prop("fileupload.artifacts.saved")); }, error: function(data) { var res = $.parseJSON(data.responseText); -- 2.39.5