Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > multipart/form-data POST Request

Reply
Thread Tools

multipart/form-data POST Request

 
 
dhtml
Guest
Posts: n/a
 
      07-14-2008
Can't get my multipart/form-data processed. Error: "Stream ended
unexpectedly"

The post body is sent over XMLHttpRequest. (the submission works fine
if sent via "normal" form submission). There seems to be a problem
with the request. Bad headers, or content-length incorrect? I can't
spot the error.

Stacktrace:

org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:
515)

org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:
40
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:
320)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
com.jspinsider.jspkit.gzip.GZIPFilter.doFilter(Unk nown Source)
</pre></p><p><b>root cause</b> <pre>javax.servlet.ServletException:
org.apache.commons.fileupload.FileUploadException

: Processing of multipart/form-data request failed.
Stream ended unexpectedly
^^^^^^^^^^^^^^^^^^^^^^^^^^^

page /ape/release/example/form/process.jsp at line 10
7: // Create a new file upload handler
8: ServletFileUpload upload = new ServletFileUpload(factory);
9:
10: List&lt;FileItem&gt; items = upload.parseRequest(request);
11: response.setContentType(&quot;text/plain&quot;
12: out.write(items.toString());
13:

Is an incorrect content-length causing this?

Here is the first request, via XMLHttpRequest form submission:
----------------------------------------------------------
http://localhost/ape/release/example/form/process.jsp



POST /ape/release/example/form/process.jsp HTTP/1.1

Host: localhost

User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.4; en-US; rv:
1.9) Gecko/2008061004 Firefox/3.0

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/
*;q=0.8

Accept-Language: en-us,en;q=0.5

Accept-Encoding: gzip,deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive: 300

Connection: keep-alive

Content-Type: multipart/form-data; charset=UTF-8;
boundary=DATA1215979532633

Referer: http://localhost/ape/release/example/form/Form.html

Content-Length: 91

Cookie: JSESSIONID=242B477B4C9455A201CF1BF7D5CFCE16

Pragma: no-cache

Cache-Control: no-cache


--DATA1215979532633
Content-Disposition: form-data; name="name";

a
--DATA1215979532633--


HTTP/1.x 500 Internal Server Error

Server: Apache-Coyote/1.1

Content-Type: text/html;charset=utf-8

Content-Length: 3840

Date: Sun, 13 Jul 2008 20:05:32 GMT

Connection: close

----------------------------------------------------------



Here is the second request, via "normal" form submission:
----------------------------------------------------------

http://localhost/ape/release/example/form/process.jsp



POST /ape/release/example/form/process.jsp HTTP/1.1

Host: localhost

User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.4; en-US; rv:
1.9) Gecko/2008061004 Firefox/3.0

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/
*;q=0.8

Accept-Language: en-us,en;q=0.5

Accept-Encoding: gzip,deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive: 300

Connection: keep-alive

Referer: http://localhost/ape/release/example/form/Form.html

Cookie: JSESSIONID=242B477B4C9455A201CF1BF7D5CFCE16

Content-Type: multipart/form-data;
boundary=---------------------------1055457295855832845137158309

Content-Length: 170

-----------------------------1055457295855832845137158309

Content-Disposition: form-data; name="name"



a

-----------------------------1055457295855832845137158309--



HTTP/1.x 200 OK

Server: Apache-Coyote/1.1

Content-Encoding: gzip

Content-Type: text/plain

Transfer-Encoding: chunked

Date: Sun, 13 Jul 2008 20:10:15 GMT

----------------------------------------------------------


The java code:
// Create a factory for disk-based file items
FileItemFactory factory = new DiskFileItemFactory();

// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);

List<FileItem> items = upload.parseRequest(request);
response.setContentType("text/plain");
out.write(items.toString());

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Just got two emails: 1. your request for a new Access Code and 2. Request for my MCP ID# What's going on??!! belfast-biker Microsoft Certification 0 01-14-2006 12:49 PM
Post post post. Shel-hed Computer Support 2 11-08-2003 07:41 AM
Re: Accessing Request.InputStream / Request.BinaryRead *as the request is occuring*: How??? Brian Birtle ASP .Net 2 10-16-2003 02:11 PM
Re: difference bet. request.querystring and Request.Params Daniel Bass ASP .Net 2 07-04-2003 12:12 PM
System.Web.HttpException: Request timed out - [HttpException (0x80004005): Request timed out.] Steve ASP .Net 0 07-01-2003 12:11 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57