You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Pierre-Alain RIVIERE <pa...@ippon.fr> on 2008/02/23 18:15:54 UTC

java.io.IOException: Stream closed

Hello,

I'm trying to stream a GET response directly to a PUT method but I get a
"java.io.IOException: Stream closed" exception in order to synchronize 2
DAV repositories. I would like to avoid to deal with temporary files.

I found the FileRequestEntity implementation on the httpclient website :
http://hc.apache.org/httpclient-3.x/performance.html#Request_Response_entity_streaming

You can found my attempt here : http://pastebin.com/f5cef9454

Can somebody point me where I'm wrong?

Thanks for help.


StackTrace
-----------------------------
Exception in thread "main" java.io.IOException: Stream closed
	at
java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:145)
	at java.io.BufferedInputStream.read(BufferedInputStream.java:308)
	at java.io.FilterInputStream.read(FilterInputStream.java:90)
	at fr.ippon.webdav.Test$FileRequestEntity.writeRequest(Test.java:66)
	at
org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:495)
	at
org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:1973)
	at
org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:993)
	at
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:397)
	at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
	at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
	at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
	at fr.ippon.webdav.Test.main(Test.java:34)


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: java.io.IOException: Stream closed

Posted by Pierre-Alain RIVIERE <pa...@ippon.fr>.
Hello,

Thanks for your help Roland. A solution but also a clear explanation.
It's indeed much better when using MultiThreadedHttpConnectionManager.
I'm going to take a look to the threading guide.


On Sat, 2008-02-23 at 19:41 +0100, Roland Weber wrote:
> Hi Pierre-Alain,
> 
> > I'm trying to stream a GET response directly to a PUT method but I get a
> > "java.io.IOException: Stream closed" exception in order to synchronize 2
> > DAV repositories. I would like to avoid to deal with temporary files.
> > 
> > You can found my attempt here : http://pastebin.com/f5cef9454
> > 
> > Can somebody point me where I'm wrong?
> 
> You are using a single HttpClient with the default connection manager
> to do two things at the same time. That cannot work. The default is
> SimpleHttpConnectionManager [1], which always has only one connection.
> First, you use that connection to execute the GET and obtain the result.
> But when you try to use that same connection for sending the PUT, it
> gets closed and re-opened to the new target. Then when it is time to
> read from the GET, the stream is detected as closed.
> 
> Use two different HttpClient objects for the two requests, or create
> one HttpClient object with a MultiThreadedHttpConnectionManager [2].
> You might want to study the Threading Guide [3] first.
> 
> cheers,
>    Roland
> 
> [1] 
> http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/SimpleHttpConnectionManager.html
> [2] 
> http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.html
> [3] http://hc.apache.org/httpclient-3.x/threading.html
> 
> 
> > 
> > Thanks for help.
> > 
> > 
> > StackTrace
> > -----------------------------
> > Exception in thread "main" java.io.IOException: Stream closed
> > 	at
> > java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:145)
> > 	at java.io.BufferedInputStream.read(BufferedInputStream.java:308)
> > 	at java.io.FilterInputStream.read(FilterInputStream.java:90)
> > 	at fr.ippon.webdav.Test$FileRequestEntity.writeRequest(Test.java:66)
> > 	at
> > org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:495)
> > 	at
> > org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:1973)
> > 	at
> > org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:993)
> > 	at
> > org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:397)
> > 	at
> > org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
> > 	at
> > org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
> > 	at
> > org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
> > 	at fr.ippon.webdav.Test.main(Test.java:34)
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: java.io.IOException: Stream closed

Posted by Roland Weber <os...@dubioso.net>.
Hi Pierre-Alain,

> I'm trying to stream a GET response directly to a PUT method but I get a
> "java.io.IOException: Stream closed" exception in order to synchronize 2
> DAV repositories. I would like to avoid to deal with temporary files.
> 
> You can found my attempt here : http://pastebin.com/f5cef9454
> 
> Can somebody point me where I'm wrong?

You are using a single HttpClient with the default connection manager
to do two things at the same time. That cannot work. The default is
SimpleHttpConnectionManager [1], which always has only one connection.
First, you use that connection to execute the GET and obtain the result.
But when you try to use that same connection for sending the PUT, it
gets closed and re-opened to the new target. Then when it is time to
read from the GET, the stream is detected as closed.

Use two different HttpClient objects for the two requests, or create
one HttpClient object with a MultiThreadedHttpConnectionManager [2].
You might want to study the Threading Guide [3] first.

cheers,
   Roland

[1] 
http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/SimpleHttpConnectionManager.html
[2] 
http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.html
[3] http://hc.apache.org/httpclient-3.x/threading.html


> 
> Thanks for help.
> 
> 
> StackTrace
> -----------------------------
> Exception in thread "main" java.io.IOException: Stream closed
> 	at
> java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:145)
> 	at java.io.BufferedInputStream.read(BufferedInputStream.java:308)
> 	at java.io.FilterInputStream.read(FilterInputStream.java:90)
> 	at fr.ippon.webdav.Test$FileRequestEntity.writeRequest(Test.java:66)
> 	at
> org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:495)
> 	at
> org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:1973)
> 	at
> org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:993)
> 	at
> org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:397)
> 	at
> org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
> 	at
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
> 	at
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
> 	at fr.ippon.webdav.Test.main(Test.java:34)
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org