On Tue, 2011-10-04 at 01:40 -0700, errdos wrote: > hey, > i have a little problem. > i have a server that doesn't support well the 100 CONTINUE protocol and im > trying to post a big file. > the problem is that sometimes the request is not valid and i want to return > an error response but i dont want to read the whole file being sent in order > to do it. so i response and close the connection. > problem is since HTTPCLIENT still trying to write he fails and throws and IO > exception and in that state i cannot retrieve and response. > im not sure even if the protocol should support something like that but i > can say that i managed to do it with the simple HttpsURLConnection although > it takes about 30-40 seconds to receive the status. > > i wonder if there is a possible way to create that flow with httpclient. > i cant understand why if the the socket was close suddenly i cannot read the > info that was sent before the close. >
Blocking i/o model HttpClient and HttpUrlConnection are based on makes it difficult to use HTTP connections in a full duplex mode while utilizing only one execution thread. It is a general limitation of classic (blocking) i/o in Java. Basically it is almost impossible to read and write from a blocking socket at the same time. This is the reason all blocking i/o HTTP agents are likely to have difficulties handling premature (out of sequence) HTTP responses. > i would really appreciate any kind of help > The asynchronous sibling of HttpClient called HttpAsyncClient [1] is based on a non-blocking i/o model (NIO) and does not suffer from the same limitation. Give it a try. You might also benefit from using zero-copy upload / download support provided by HttpAsyncClient [2]. Hope this helps Oleg [1] http://hc.apache.org/httpcomponents-asyncclient-dev/index.html [2] http://hc.apache.org/httpcomponents-asyncclient-dev/examples.html --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
