History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: WW-1102
Type: Bug Bug
Status: Resolved Resolved
Resolution: Cannot Reproduce
Priority: Major Major
Assignee: Rainer Hermanns
Reporter: Joe Jordan
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
WebWork

Multipart requests are not cleaned up correctly

Created: 20/Jan/06 12:19 AM   Updated: 03/Feb/06 09:21 AM
Component/s: Actions, Interceptors
Affects Version/s: 2.2
Fix Version/s: 2.2.1

Environment: Linux (KUbuntu 5.10) running Orion 2.0.5 application server


 Description  « Hide
Multipart requests, using either the fileUpload interceptor or MultiPartRequestWrapper, are not cleaned up correctly.


Markup:

<form action="/command/Thumbnails/create" method="POST" enctype="multipart/form-data">
    <input type='file' name='newThumbnail' />
    <input type='text' name='newThumbnailCaption' />
    <input type='submit' value='Upload' />
</form>


Behaviour:

When this form is submitted with the fileUpload interceptor in place, two temporary files are created named upload_00000000.tmp and upload_00000001.tmp. One of the temporary files contains the image, the other temporary file contains the contents of the text field. Upon completion of the action, only the file containing the image is deleted - the other file is left in the temporary directory indefinitely. This behaviour is identical when the lower-level MultiPartRequestWrapper is used explicitly, as in the second example below.


Example 1 with the fileUpload interceptor:

import java.io.File;

public class ThumbnailsView {

private File newThumbnail;
    private String newThumbnailContentType;
    private String newThumbnailFileName;
    private String newThumbnailCaption;

public String create() { return "success"; }

public void setNewThumbnail(File newThumbnail) { this.newThumbnail = newThumbnail; }
    public void setNewThumbnailContentType(String newThumbnailContentType) {
        this.newThumbnailContentType = newThumbnailContentType;
    }
    public void setNewThumbnailFileName(String newThumbnailFileName) {
        this.newThumbnailFileName = newThumbnailFileName;
    }
    public void setNewThumbnailCaption(String newThumbnailCaption) {
        this.newThumbnailCaption = newThumbnailCaption;
    }

}


Example 2 using MultiPartRequestWrapper:

import com.opensymphony.webwork.interceptor.ServletRequestAware;
import com.opensymphony.webwork.dispatcher.multipart.MultiPartRequestWrapper;
import javax.servlet.http.HttpServletRequest;
import java.io.File;

public class ThumbnailsView implements ServletRequestAware {

private HttpServletRequest request;
    private File newThumbnail;
    private String newThumbnailContentType;
    private String newThumbnailFileName;
    private String newThumbnailCaption;

public String create() {
        MultiPartRequestWrapper wrapper = (MultiPartRequestWrapper) request;
        try {
            newThumbnail = wrapper.getFiles("newThumbnail")[0];
            newThumbnailContentType = wrapper.getContentTypes("newThumbnail")[0];
            newThumbnailFileName = wrapper.getFileSystemNames("newThumbnail")[0];
        } finally {
            newThumbnail.delete();
        }
        return "success";
    }

public void setServletRequest(HttpServletRequest request) {
        this.request = request;
    }

public void setNewThumbnailCaption(String newThumbnailCaption) {
        this.newThumbnailCaption = newThumbnailCaption;
    }

}


 All   Comments   Change History      Sort Order:
Andres March - [31/Jan/06 11:28 AM ]
I don't know why the form content is being written out at all. It shouldn't be necessary unless I'm missing something. I don't think this is a clean up issue.

Rainer Hermanns - [31/Jan/06 01:24 PM ]
Andres,

I think you ae right... Can you have a look at this and take care of this issue?

Andres March - [31/Jan/06 04:07 PM ]
won't be able to get to this for a few days at least but if I get the chance, I'll have a look.

Rainer Hermanns - [03/Feb/06 07:34 AM ]
Joe,

can you please show me the action mappings of your xwork.xml
and the webwork.properties. Are you using the jakarta parser?

Rainer

Rainer Hermanns - [03/Feb/06 09:02 AM ]
Joe,

this doesn't seem to be an issue with webwork...
Used your code and deployed it locally and all files where deleted as expected...

Have a look at the following output:

2006-02-03 15:59:33,184 INFO (com.opensymphony.webwork.dispatcher.DispatcherUtils:356) - Unable to find 'webwork.multipart.saveDir' property setting. Defaulting to javax.servlet.context.tempdir
2006-02-03 15:59:33,186 DEBUG (com.opensymphony.webwork.dispatcher.DispatcherUtils:370) - saveDir=/Developer/Java/apache-tomcat-5.5.12/work/Catalina/localhost/showcase
2006-02-03 15:59:33,187 DEBUG (com.opensymphony.webwork.dispatcher.DispatcherUtils:340) - maxSize=2097152
2006-02-03 15:59:33,271 DEBUG (com.opensymphony.webwork.dispatcher.multipart.MultiPartRequest:56) - Found item newThumbnail
2006-02-03 15:59:33,272 DEBUG (com.opensymphony.webwork.dispatcher.multipart.MultiPartRequest:80) - Item is a file upload
2006-02-03 15:59:33,272 DEBUG (com.opensymphony.webwork.dispatcher.multipart.MultiPartRequest:56) - Found item newThumbnailCaption
2006-02-03 15:59:33,273 DEBUG (com.opensymphony.webwork.dispatcher.multipart.MultiPartRequest:58) - Item is a normal form field
2006-02-03 15:59:33,292 ERROR (com.opensymphony.xwork.util.CompoundRootAccessor:66) - No object in the CompoundRoot has a property named 'newThumbnail'.
2006-02-03 15:59:33,322 ERROR (com.opensymphony.xwork.interceptor.ParametersInterceptor:143) - Developer Notification (set webwork.devMode to false to disable this message):
No object in the CompoundRoot has a property named 'newThumbnail'.
2006-02-03 15:59:33,362 DEBUG (com.opensymphony.webwork.dispatcher.ServletDispatcherResult:88) - Forwarding to location upload-success.jsp
2006-02-03 15:59:33,411 INFO (com.opensymphony.webwork.interceptor.FileUploadInterceptor:207) - removing file newThumbnail /Developer/Java/apache-tomcat-5.5.12/work/Catalina/localhost/showcase/upload_467dcc34_109306cd8fc__8000_00000000.tmp

Rainer Hermanns - [03/Feb/06 09:21 AM ]
Joe,
added a sample to the showcase webapp...
Please try this and tell me if you have issues with this as well.

Thanks,
Rainer