Oleg,
> > > > SocketInputStream.socketRead0(FileDescriptor, byte[], int, int, int)
> > > > line: not available [native method] [local variables unavailable]
> > >
> > > The thread is blocked in the socket read operation. This is perfectly
> > > normal. If you do not want the operation to block indefinitely you
> > > should set a timeout for it.
> >
> > But that read operation never ends even if the remote http server is
> > normally responsive.
>
> The client gets blocked in a _native_ method managed by the JVM. It is
> entirely out of HttpClient control. If the method does not return, that
> means that the server is not sending any data.
That's not truth. The HttpClient is responsible for reading from socket and it
seems it violence the HTTP protocol as it is reading from the remote HTTP
server that is not in the state to output any data to the client.
> > So I think there is bug in HTTP client. I'll try to prepare a testcase
>
> Sure thing.
Attached. Enjoy! :-)
BR
--
Martin Zdila
CTO
M-Way Solutions Slovakia s.r.o.
Letna 27, 040 01 Kosice
Slovakia
tel:+421-908-363-848
mailto:[EMAIL PROTECTED]
http://www.mwaysolutions.com
xmpp:[EMAIL PROTECTED] (Jabber)
skype:m.zdila
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.params.ClientParamBean;
import org.apache.http.client.params.HttpClientParams;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.params.ConnManagerParams;
import org.apache.http.conn.params.ConnPerRouteBean;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
import org.apache.http.protocol.HTTP;
public class SocketLockOnPostTestCase {
// if 10 then everything is OK
// if 60 then i see in the logs (INFO):
// org.apache.http.impl.client.DefaultClientRequestDirector - I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond
// org.apache.http.impl.client.DefaultClientRequestDirector - Retrying request
private static final int WAIT_SECONDS = 60;
// using worse alternative the execution gets blocked on the socket forever if WAIT_SECONDS = 60
// otherwise i only see I/O exception log message
private static final boolean WORSE_ALTERNATIVE = true;
public static void main(final String[] args) throws Exception {
final HttpParams params = new BasicHttpParams();
ConnManagerParams.setMaxTotalConnections(params, 100);
ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(20));
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpClientParams.setRedirecting(params, false);
final ClientParamBean paramBean = new ClientParamBean(params);
paramBean.setAllowCircularRedirects(true);
paramBean.setHandleAuthentication(false);
paramBean.setHandleRedirects(false);
// Create and initialize scheme registry
final SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
final ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(params, schemeRegistry);
final HttpClient client = new DefaultHttpClient(connectionManager, params);
((DefaultHttpClient) client).setCookieStore(null);
((DefaultHttpClient) client).setCookieSpecs(null);
System.out.println("Executing GET");
{
final HttpPost getMethod = new HttpPost("http://www.zdila.sk/post.html");
final HttpResponse httpResponse = client.execute(getMethod);
final InputStream inputStream = httpResponse.getEntity().getContent();
IOUtils.copy(inputStream, System.out);
inputStream.close();
}
System.out.println("Waiting " + WAIT_SECONDS + " seconds");
Thread.sleep(WAIT_SECONDS * 1000);
System.out.println("Continuing with POST");
{
final HttpPost postMethod = new HttpPost("http://www.zdila.sk/post.html");
if (WORSE_ALTERNATIVE) {
postMethod.setEntity(new InputStreamEntity(new ByteArrayInputStream("submit=submit".getBytes()), 13));
} else {
final List<NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("submit", "submit"));
postMethod.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
}
final HttpResponse httpResponse = client.execute(postMethod);
final InputStream inputStream = httpResponse.getEntity().getContent();
IOUtils.copy(inputStream, System.out);
inputStream.close();
}
System.out.println("Finished.");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]