java.io.IOException: Read error using file parameter on webform

Ryan Connolly <[email protected]> Tue, 19 May 2009 15:56:50 -0400
Newsgroups gmane.comp.web.httpunit.devel
Message-ID <[email protected]>
Hi folks:
     I posted this message to the help forum and noticed a post regarding
low readership by the developers so I thought it best to send this along to
the list...

I have tried just about everything I can think of and am 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: Always with a
java.io.IOException: Read error.


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)



-- 
®¥@N

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables 
unlimited royalty-free distribution of the report engine 
for externally facing server and web deployment. 
http://p.sf.net/sfu/businessobjects

_______________________________________________
Httpunit-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/httpunit-develop