[nuiton-web] branch develop updated (0213a5e -> 66a2f39)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository nuiton-web. See http://git.nuiton.org/nuiton-web.git from 0213a5e fix site configuration new 66a2f39 fixes #3563 [Nuiton-struts2] create an interceptor overriding ExecuteAndWaitInterceptor to copy the uploaded file The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 66a2f39e4dc968e3816d963e92ea0af23122394c Author: Kevin Morin <morin@codelutin.com> Date: Fri Oct 31 16:19:09 2014 +0100 fixes #3563 [Nuiton-struts2] create an interceptor overriding ExecuteAndWaitInterceptor to copy the uploaded file Summary of changes: .../web/struts2/interceptor/HasUploadedFile.java | 14 +++++ .../UploadExecuteAndWaitInterceptor.java | 60 ++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 nuiton-struts2/src/main/java/org/nuiton/web/struts2/interceptor/HasUploadedFile.java create mode 100644 nuiton-struts2/src/main/java/org/nuiton/web/struts2/interceptor/UploadExecuteAndWaitInterceptor.java -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository nuiton-web. See http://git.nuiton.org/nuiton-web.git commit 66a2f39e4dc968e3816d963e92ea0af23122394c Author: Kevin Morin <morin@codelutin.com> Date: Fri Oct 31 16:19:09 2014 +0100 fixes #3563 [Nuiton-struts2] create an interceptor overriding ExecuteAndWaitInterceptor to copy the uploaded file --- .../web/struts2/interceptor/HasUploadedFile.java | 14 +++++ .../UploadExecuteAndWaitInterceptor.java | 60 ++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/nuiton-struts2/src/main/java/org/nuiton/web/struts2/interceptor/HasUploadedFile.java b/nuiton-struts2/src/main/java/org/nuiton/web/struts2/interceptor/HasUploadedFile.java new file mode 100644 index 0000000..cdfb2a2 --- /dev/null +++ b/nuiton-struts2/src/main/java/org/nuiton/web/struts2/interceptor/HasUploadedFile.java @@ -0,0 +1,14 @@ +package org.nuiton.web.struts2.interceptor; + +import java.io.File; + +/** + * @author Kevin Morin (Code Lutin) + * @since 1.18 + */ +public interface HasUploadedFile { + + File getUploadedFile(); + + void setUploadedFile(File file); +} diff --git a/nuiton-struts2/src/main/java/org/nuiton/web/struts2/interceptor/UploadExecuteAndWaitInterceptor.java b/nuiton-struts2/src/main/java/org/nuiton/web/struts2/interceptor/UploadExecuteAndWaitInterceptor.java new file mode 100644 index 0000000..c61bd08 --- /dev/null +++ b/nuiton-struts2/src/main/java/org/nuiton/web/struts2/interceptor/UploadExecuteAndWaitInterceptor.java @@ -0,0 +1,60 @@ +package org.nuiton.web.struts2.interceptor; + +import com.opensymphony.xwork2.ActionInvocation; +import org.apache.commons.io.FileUtils; +import org.apache.struts2.interceptor.BackgroundProcess; +import org.apache.struts2.interceptor.ExecuteAndWaitInterceptor; + +import java.io.File; + +/** + * Interceptor to copy the temp file to avoid it is deleted before the execAndWait thread has time to read it + * cf http://stackoverflow.com/questions/22382779/file-not-saved-in-temp-path-usin... + * @author Kevin Morin (Code Lutin) + * @since 1.18 + */ +public class UploadExecuteAndWaitInterceptor extends ExecuteAndWaitInterceptor { + + @Override + protected BackgroundProcess getNewBackgroundProcess(String name, + ActionInvocation actionInvocation, + int threadPriority) { + + BackgroundProcess bgProcess; + if (actionInvocation.getAction() instanceof HasUploadedFile) { + HasUploadedFile uploadAction = (HasUploadedFile) actionInvocation.getAction(); + try { + File origFile = uploadAction.getUploadedFile(); + if (origFile != null) { + File altFile = new File(origFile.getParentFile(), origFile.getName() + "-alt.tmp"); + FileUtils.copyFile(origFile, altFile); + altFile.deleteOnExit(); + uploadAction.setUploadedFile(altFile); + } + } catch (Exception ex) { + throw new RuntimeException("Error copying uploaded file", ex); + } + bgProcess = new UploadBackgroundProcess(name + "BackgroundThread", actionInvocation, threadPriority); + + } else { + bgProcess = super.getNewBackgroundProcess(name, actionInvocation, threadPriority); + } + return bgProcess; + } + + /** + * Wraps the standard {@link org.apache.struts2.interceptor.BackgroundProcess} to clean up alternate file created above. + */ + private class UploadBackgroundProcess extends BackgroundProcess { + + public UploadBackgroundProcess(String threadName, ActionInvocation invocation, int threadPriority) { + super(threadName, invocation, threadPriority); + } + + @Override + protected void afterInvocation() throws Exception { + super.afterInvocation(); + FileUtils.deleteQuietly(((HasUploadedFile)getAction()).getUploadedFile()); + } + } +} -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
participants (1)
-
nuiton.org scm