From 8f8455827504e7c92ec242a15133659b0eee7abe Mon Sep 17 00:00:00 2001 From: Thusitha Dayaratne Date: Thu, 21 Jul 2016 18:01:11 +0530 Subject: [PATCH] WMS-81: Improve temp file deleting strategy with FormParam --- .../internal/router/HttpResourceModelProcessor.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/wso2/msf4j/internal/router/HttpResourceModelProcessor.java b/core/src/main/java/org/wso2/msf4j/internal/router/HttpResourceModelProcessor.java index 779a422f0..4fab930d2 100644 --- a/core/src/main/java/org/wso2/msf4j/internal/router/HttpResourceModelProcessor.java +++ b/core/src/main/java/org/wso2/msf4j/internal/router/HttpResourceModelProcessor.java @@ -18,6 +18,7 @@ import com.google.common.base.Preconditions; import org.apache.commons.io.FileCleaningTracker; +import org.apache.commons.io.FileDeleteStrategy; import org.wso2.msf4j.HttpStreamer; import org.wso2.msf4j.Request; import org.wso2.msf4j.Response; @@ -160,10 +161,6 @@ private void createObject(Request request, Object[] args, int idx, HttpResourceM private Object getFormDataParamValue(HttpResourceModel.ParameterInfo> paramInfo, Request request) throws FormUploadException, IOException { - if (Files.notExists(tempRepoPath)) { - Files.createDirectory(tempRepoPath); - } - Type paramType = paramInfo.getParameterType(); FormDataParam formDataParam = paramInfo.getAnnotation(); if (getFormParameters() == null) { @@ -267,12 +264,16 @@ private Object createBean(List parameter, FormDataParam formDataParam, T private File createAndTrackTempFile(FormItem item) throws IOException { if (tmpPathForRequest == null) { + if (Files.notExists(tempRepoPath)) { + Files.createDirectory(tempRepoPath); + } tmpPathForRequest = Files.createTempDirectory(tempRepoPath, "tmp"); } Path path = Paths.get(tmpPathForRequest.toString(), item.getName()); File file = path.toFile(); StreamUtil.copy(item.openStream(), new FileOutputStream(file), true); fileCleaningTracker.track(file, file); + fileCleaningTracker.track(tmpPathForRequest.toFile(), file, FileDeleteStrategy.FORCE); return file; }