rynam0 - 2009-05-19

Hi folks:
     I have tried just about everything I can think of and am at wits end with this... Hoping someone has encountered the same issue and is willing to share the solution.

I am testing a file upload form that submits to a servlet... I've got everything working just fine except for when setting a file parameter or calling request.selectFile.  Below is the stacktrace and my unit test code.  Any help would be greatly appreciated.  BTW: I've tried this with the same results in both 1.6.2 and in the 1.7 release.

        WebConversation wc = new WebConversation();
        WebRequest req = new GetMethodWebRequest(formFile.toURI().toString());

        WebResponse resp = wc.getResponse(req);
        WebForm form = resp.getFormWithID("uploadForm");

        ServletUnitClient sc = sr.newClient();

        WebRequest request = form.getRequest( "submit", "Upload" );
        request.selectFile("attachment", uploadFile);

        InvocationContext ic = sc.newInvocation(request);

        WebResponse response = sc.getResponse(ic);
        response = sc.getResponse(request);

java.io.IOException: Read error
    at java.io.FileInputStream.readBytes(Native Method)
    at java.io.FileInputStream.read(FileInputStream.java:199)
    at com.meterware.httpunit.protocol.MimeEncodedMessageBody$MimeEncoding.addFile(MimeEncodedMessageBody.java:137)
    at com.meterware.httpunit.FileSubmitFormControl.addValues(FormControl.java:981)
    at com.meterware.httpunit.WebForm.recordParameters(WebForm.java:604)
    at com.meterware.httpunit.protocol.MimeEncodedMessageBody.writeTo(MimeEncodedMessageBody.java:51)
    at com.meterware.httpunit.MessageBodyWebRequest.writeMessageBody(MessageBodyWebRequest.java:107)
    at com.meterware.httpunit.WebClient.writeMessageBody(WebClient.java:434)
    at com.meterware.servletunit.ServletUnitClient.getMessageBody(ServletUnitClient.java:88)
    at com.meterware.servletunit.ServletUnitClient.newInvocation(ServletUnitClient.java:81)
    at com.meterware.servletunit.ServletUnitClient.newResponse(ServletUnitClient.java:125)
    at com.meterware.httpunit.WebClient.createResponse(WebClient.java:647)
    at com.meterware.httpunit.WebWindow.getResource(WebWindow.java:220)
    at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:181)
    at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:158)
    at com.meterware.httpunit.WebClient.getResponse(WebClient.java:122)
    at gov.vermont.dcf.fsdnet.uploads.UploadServletTest.testForm(UploadServletTest.java:83)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)