struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject svn commit: r1447453 - /struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
Date Mon, 18 Feb 2013 19:53:43 GMT
Author: lukaszlenart
Date: Mon Feb 18 19:53:42 2013
New Revision: 1447453

URL: http://svn.apache.org/r1447453
Log:
WW-3986 Reverts partially changes introduced with WW-3363 to use @Inject MultiPartRequest
instead of name of MultiPartRequest

Modified:
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java?rev=1447453&r1=1447452&r2=1447453&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
(original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
Mon Feb 18 19:53:42 2013
@@ -139,9 +139,9 @@ public class Dispatcher {
     private String multipartSaveDir;
 
     /**
-     * Stores reference to instance of {@link MultiPartRequest} implementation defined by
{@link StrutsConstants#STRUTS_MULTIPART_PARSER}
+     * Stores the value of StrutsConstants.STRUTS_MULTIPART_HANDLER setting
      */
-    private MultiPartRequest multipartHandler;
+    private String multipartHandlerName;
 
     /**
      * Provide list of default configuration files.
@@ -252,9 +252,9 @@ public class Dispatcher {
         multipartSaveDir = val;
     }
 
-    @Inject
-    public void setMultipartHandler(MultiPartRequest multiPartRequest) {
-        this.multipartHandler = multiPartRequest;
+    @Inject(StrutsConstants.STRUTS_MULTIPART_PARSER)
+    public void setMultipartHandler(String val) {
+        multipartHandlerName = val;
     }
 
     @Inject
@@ -774,8 +774,9 @@ public class Dispatcher {
 
         String content_type = request.getContentType();
         if (content_type != null && content_type.contains("multipart/form-data"))
{
+            MultiPartRequest mpr = getMultiPartRequest();
             LocaleProvider provider = getContainer().getInstance(LocaleProvider.class);
-            request = new MultiPartRequestWrapper(multipartHandler, request, getSaveDir(servletContext),
provider);
+            request = new MultiPartRequestWrapper(mpr, request, getSaveDir(servletContext),
provider);
         } else {
             request = new StrutsRequestWrapper(request);
         }
@@ -784,6 +785,27 @@ public class Dispatcher {
     }
 
     /**
+     * On each request it must return a new instance as implementation could be not thread
safe
+     * and thus ensure of resource clean up
+     *
+     * @return
+     */
+    protected MultiPartRequest getMultiPartRequest() {
+        MultiPartRequest mpr = null;
+        //check for alternate implementations of MultiPartRequest
+        Set<String> multiNames = getContainer().getInstanceNames(MultiPartRequest.class);
+        for (String multiName : multiNames) {
+            if (multiName.equals(multipartHandlerName)) {
+                mpr = getContainer().getInstance(MultiPartRequest.class, multiName);
+            }
+        }
+        if (mpr == null ) {
+            mpr = getContainer().getInstance(MultiPartRequest.class);
+        }
+        return mpr;
+    }
+
+    /**
      * Removes all the files created by MultiPartRequestWrapper.
      *
      * @param request the HttpServletRequest object.



Mime
View raw message