Friday, 13 September 2013

Textual description of firstImageUrl

Jersey Rest Service : Stream Already Closed Error

Creating File Upload functionality in WebServices using Jersey is very simple , you can go through this post to create file upload functionality in Jersey Rest Service. However , you may get an exception like this , if you are using Buffered Reader to read the uploaded file stream.
 java.lang.IllegalStateException: Stream already closed
 at org.jvnet.mimepull.DataHead$ReadMultiStream.fetch(DataHead.java:237)
 at org.jvnet.mimepull.DataHead$ReadMultiStream.read(DataHead.java:212)
 at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
 at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
 at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
 at java.io.InputStreamReader.read(InputStreamReader.java:184)
 at java.io.BufferedReader.fill(BufferedReader.java:154)
 at java.io.BufferedReader.readLine(BufferedReader.java:317)
 at java.io.BufferedReader.readLine(BufferedReader.java:382)

This is a known issue in mimepull version 1.6 , which we are using along with jersey multi part jar . Try using mimepull version 1.9 and you will not see this error any more .

Jersey Multipart 1.6 depends on MimePull 1.4 . First exclude the 1.4 and include this dependency explicitly like this :
<dependency>
   <groupId>com.sun.jersey.contribs</groupId>
   <artifactId>jersey-multipart</artifactId>
   <version>1.6</version>
   <exclusions>
 <exclusion>
    <groupId>org.jvnet</groupId>
    <artifactId>mimepull</artifactId>
 </exclusion>
   </exclusions>
</dependency>
<dependency>
 <groupId>org.jvnet.mimepull</groupId>
 <artifactId>mimepull</artifactId>
 <version>1.9</version>
</dependency>

Post Comments and Suggestions !!