You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2008/01/25 21:18:46 UTC

svn commit: r615326 - in /tapestry/tapestry5/trunk: tapestry-core/src/test/app1/ tapestry-upload/src/main/java/org/apache/tapestry/upload/services/

Author: hlship
Date: Fri Jan 25 12:18:45 2008
New Revision: 615326

URL: http://svn.apache.org/viewvc?rev=615326&view=rev
Log:
TAPESTRY-2089: File upload does not ever invoke FileCleaner.exitWhenFinished()

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml
    tapestry/tapestry5/trunk/tapestry-upload/src/main/java/org/apache/tapestry/upload/services/MultipartDecoderImpl.java
    tapestry/tapestry5/trunk/tapestry-upload/src/main/java/org/apache/tapestry/upload/services/UploadModule.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml?rev=615326&r1=615325&r2=615326&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml Fri Jan 25 12:18:45 2008
@@ -3,6 +3,8 @@
 
     <h1>Tapestry 5 Integration Application 1</h1>
 
+    <p>${items.size()} standard test pages</p>
+
     <ul>
         <li t:type="loop" source="items" value="item">
             <t:pagelink page="prop:item.pageName">${item.label}</t:pagelink>

Modified: tapestry/tapestry5/trunk/tapestry-upload/src/main/java/org/apache/tapestry/upload/services/MultipartDecoderImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-upload/src/main/java/org/apache/tapestry/upload/services/MultipartDecoderImpl.java?rev=615326&r1=615325&r2=615326&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-upload/src/main/java/org/apache/tapestry/upload/services/MultipartDecoderImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-upload/src/main/java/org/apache/tapestry/upload/services/MultipartDecoderImpl.java Fri Jan 25 12:18:45 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2008 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -19,6 +19,8 @@
 import org.apache.commons.fileupload.FileUploadException;
 import org.apache.commons.fileupload.disk.DiskFileItemFactory;
 import org.apache.commons.fileupload.servlet.ServletFileUpload;
+import org.apache.tapestry.ioc.annotations.Inject;
+import org.apache.tapestry.ioc.annotations.Symbol;
 import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newMap;
 import org.apache.tapestry.ioc.services.ThreadCleanupListener;
 
@@ -29,7 +31,7 @@
 import java.util.Map;
 
 /**
- * Implementation of multipart decoder for servlets.
+ * Implementation of multipart decoder for servlets.  This implementation is perthread scope.
  */
 class MultipartDecoderImpl implements MultipartDecoder, ThreadCleanupListener
 {
@@ -43,8 +45,19 @@
 
     private final long _maxFileSize;
 
-    public MultipartDecoderImpl(String repositoryLocation, int repositoryThreshold, long maxRequestSize,
-                                long maxFileSize)
+    public MultipartDecoderImpl(
+
+            @Inject @Symbol(UploadSymbols.REPOSITORY_LOCATION)
+            String repositoryLocation,
+
+            @Symbol(UploadSymbols.REPOSITORY_THRESHOLD)
+            int repositoryThreshold,
+
+            @Symbol(UploadSymbols.REQUESTSIZE_MAX)
+            long maxRequestSize,
+
+            @Symbol(UploadSymbols.FILESIZE_MAX)
+            long maxFileSize)
     {
         _repositoryLocation = repositoryLocation;
         _repositoryThreshold = repositoryThreshold;
@@ -59,7 +72,6 @@
 
     public HttpServletRequest decode(HttpServletRequest request)
     {
-        // String encoding = request.getCharacterEncoding();
         List<FileItem> fileItems = parseRequest(request);
 
         return processFileItems(request, fileItems);
@@ -106,7 +118,6 @@
         }
 
         ParametersServletRequestWrapper wrapper = new ParametersServletRequestWrapper(request);
-
 
         String encoding = request.getCharacterEncoding();
 

Modified: tapestry/tapestry5/trunk/tapestry-upload/src/main/java/org/apache/tapestry/upload/services/UploadModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-upload/src/main/java/org/apache/tapestry/upload/services/UploadModule.java?rev=615326&r1=615325&r2=615326&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-upload/src/main/java/org/apache/tapestry/upload/services/UploadModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-upload/src/main/java/org/apache/tapestry/upload/services/UploadModule.java Fri Jan 25 12:18:45 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2008 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -16,22 +16,19 @@
 
 import org.apache.commons.fileupload.disk.DiskFileItemFactory;
 import org.apache.commons.io.FileCleaner;
-import org.apache.tapestry.ioc.Configuration;
-import org.apache.tapestry.ioc.MappedConfiguration;
-import org.apache.tapestry.ioc.OrderedConfiguration;
-import org.apache.tapestry.ioc.annotations.Inject;
+import org.apache.tapestry.ioc.*;
 import org.apache.tapestry.ioc.annotations.Scope;
-import org.apache.tapestry.ioc.annotations.Symbol;
 import org.apache.tapestry.ioc.services.RegistryShutdownHub;
 import org.apache.tapestry.ioc.services.RegistryShutdownListener;
-import org.apache.tapestry.ioc.services.SymbolSource;
 import org.apache.tapestry.ioc.services.ThreadCleanupHub;
 import org.apache.tapestry.services.HttpServletRequestFilter;
 import org.apache.tapestry.services.LibraryMapping;
 
+import java.util.concurrent.atomic.AtomicBoolean;
+
 public class UploadModule
 {
-    private static boolean _shutdownListenerSet;
+    private static final AtomicBoolean _needToAddShutdownListener = new AtomicBoolean(true);
 
     public static void contributeComponentClassResolver(Configuration<LibraryMapping> configuration)
     {
@@ -40,33 +37,20 @@
         configuration.add(new LibraryMapping("core", "org.apache.tapestry.upload"));
     }
 
-    @Scope("perthread")
+    @Scope(IOCConstants.PERTHREAD_SCOPE)
     public synchronized static MultipartDecoder buildMultipartDecoder(ThreadCleanupHub threadCleanupHub,
 
                                                                       RegistryShutdownHub shutdownHub,
 
-                                                                      @Inject @Symbol(UploadSymbols.REPOSITORY_LOCATION)
-                                                                      String repositoryPath,
-
-                                                                      @Symbol(UploadSymbols.REPOSITORY_THRESHOLD)
-                                                                      int repositoryThreshold,
-
-                                                                      @Symbol(UploadSymbols.REQUESTSIZE_MAX)
-                                                                      long maxRequestSize,
-
-                                                                      @Symbol(UploadSymbols.FILESIZE_MAX)
-                                                                      long maxFileSize,
-
-                                                                      SymbolSource symbolSource)
+                                                                      ObjectLocator locator)
     {
-        MultipartDecoderImpl multipartDecoder = new MultipartDecoderImpl(repositoryPath, repositoryThreshold,
-                                                                         maxRequestSize, maxFileSize);
+        MultipartDecoderImpl multipartDecoder = locator.autobuild(MultipartDecoderImpl.class);
 
         // This is proabably overkill since the FileCleaner should catch temporary files, but lets
         // be safe.
         threadCleanupHub.addThreadCleanupListener(multipartDecoder);
 
-        if (_shutdownListenerSet)
+        if (_needToAddShutdownListener.getAndSet(false))
         {
             shutdownHub.addRegistryShutdownListener(new RegistryShutdownListener()
             {
@@ -75,8 +59,6 @@
                     FileCleaner.exitWhenFinished();
                 }
             });
-
-            _shutdownListenerSet = true;
         }
 
         return multipartDecoder;