This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Web Services and the fly likes Error while parsing simple plain text fields in multipart form at Restlet 1.1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Error while parsing simple plain text fields in multipart form at Restlet 1.1" Watch "Error while parsing simple plain text fields in multipart form at Restlet 1.1" New topic
Author

Error while parsing simple plain text fields in multipart form at Restlet 1.1

Igor Kravchenko
Greenhorn

Joined: Sep 07, 2010
Posts: 2
Hi everybody!
I have some troubles with parsing simple plain-text form fields in Restlet v1.1

The form looks like

I've tried to parse multipart request from my resource as in the example at http://wiki.restlet.org/docs_1.1/13-restlet/28-restlet/64-restlet.html page (with some simplification):



The following error occurs:

java.lang.NullPointerException
at org.apache.commons.fileupload.MultipartStream$ItemInputStream.makeAvailable(MultipartStream.java:976)
at org.apache.commons.fileupload.MultipartStream$ItemInputStream.read(MultipartStream.java:886)
at java.io.InputStream.read(Unknown Source)
at org.apache.commons.fileupload.util.Streams.copy(Streams.java:96)
at org.apache.commons.fileupload.util.Streams.copy(Streams.java:66)
at org.apache.commons.fileupload.MultipartStream.readBodyData(MultipartStream.java:592)
at org.apache.commons.fileupload.MultipartStream.discardBodyData(MultipartStream.java:618)
at org.apache.commons.fileupload.MultipartStream.skipPreamble(MultipartStream.java:637)
at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.findNextItem(FileUploadBase.java:984)
at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:965)
at org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:331)
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:351)
at org.restlet.ext.fileupload.RestletFileUpload.parseRequest(RestletFileUpload.java:104)
at myPackage.MyResource.myPostRepresentation(MyResource.java:LINE X)


Also, when I've tried pure Apache code as mentioned at http://commons.apache.org/fileupload/using.html page instead of code above:



, I have following error:

org.apache.commons.fileupload.FileUploadException: Stream closed
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:385)
at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
at myPackage.MyResource.myPostRepresentation(MyResource.java:LINE X)
...
Caused by: java.io.IOException: Stream closed
at org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:325)
at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:193)
at org.apache.commons.fileupload.MultipartStream$ItemInputStream.makeAvailable(MultipartStream.java:976)
at org.apache.commons.fileupload.MultipartStream$ItemInputStream.read(MultipartStream.java:886)
at java.io.InputStream.read(Unknown Source)
at org.apache.commons.fileupload.util.Streams.copy(Streams.java:96)
at org.apache.commons.fileupload.util.Streams.copy(Streams.java:66)
at org.apache.commons.fileupload.MultipartStream.readBodyData(MultipartStream.java:592)
at org.apache.commons.fileupload.MultipartStream.discardBodyData(MultipartStream.java:618)
at org.apache.commons.fileupload.MultipartStream.skipPreamble(MultipartStream.java:637)
at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.findNextItem(FileUploadBase.java:984)
at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:965)
at org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:331)
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:351)
... 54 more
Caused by:
java.io.IOException: Stream closed
at org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:325)
at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:193)
at org.apache.commons.fileupload.MultipartStream$ItemInputStream.makeAvailable(MultipartStream.java:976)
at org.apache.commons.fileupload.MultipartStream$ItemInputStream.read(MultipartStream.java:886)
at java.io.InputStream.read(Unknown Source)
at org.apache.commons.fileupload.util.Streams.copy(Streams.java:96)
at org.apache.commons.fileupload.util.Streams.copy(Streams.java:66)
at org.apache.commons.fileupload.MultipartStream.readBodyData(MultipartStream.java:592)
at org.apache.commons.fileupload.MultipartStream.discardBodyData(MultipartStream.java:618)
at org.apache.commons.fileupload.MultipartStream.skipPreamble(MultipartStream.java:637)
at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.findNextItem(FileUploadBase.java:984)
at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:965)
at org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:331)
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:351)
at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
at myPackage.MyResource.myPostRepresentation(MyResource.java:LINE X)


At the same time, i have successfully parsed the same request with the help of the simpliest servlet without Restlet wrapper.

My question is - Does Restlet 1.1 support parsing of simple text fields from forms encrypted as 'multipart/form-data'?
And if it does, any ideas what I have been doing wrong?

Thanks!
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Have you set the MIME type(content type on the Restlets page) of the HTTP request that contains the form to "multipart/form-data"?
Setting that type in the form is not enough.
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
Igor Kravchenko
Greenhorn

Joined: Sep 07, 2010
Posts: 2
Ivan Krizsan wrote:Hi!
Have you set the MIME type(content type on the Restlets page) of the HTTP request that contains the form to "multipart/form-data"?
Setting that type in the form is not enough.
Best wishes!

Thank you for your answer.
Not sure I understand.
I have mediaType from my request

equal to
multipart/form-data; boundary=---------------------------24464570528145
, where numbers of course vary from request to request.

I have the same content type when I test multipart form at simple servlet

Also,

returns true
, where ServletFileUpload is from org.apache.commons.fileupload.servlet package, and
ServletCall is from com.noelios.restlet.ext.servlet package.
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
It looks like the MIME type is correctly set.
Have you managed to successfully re-make the unchanged example to which you provided the link?
This sounds rather interesting and I hope I will have some time in the next few days to take a look. If I find something out, I will let you know.
Best wishes!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error while parsing simple plain text fields in multipart form at Restlet 1.1