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 Sagi Mann <sa...@gmail.com> on 2008/10/13 15:07:00 UTC
NoHttpResponseException second time around...
Hi all,
I have an issue trying to test a primitive proprietary http server with
HttpClient 3.1. I start the "server", accepting sockets on port 9090. I then
run the client command line, which sends a simple GET message to the server,
expecting a 200 status reply. All works well, the 200 reply arrives at the
client side, and the client app exits (but the server remains running and
listening).
I then re-run the client with the same cmdline. The server receives the
request, but on the client side, instead of a 200 reply, I get an exception
(see below). No exception is thrown on the server side at this point. I keep
re-running the client and get the same exception. If I restart the server,
and re-run the client - same thing: first time works fine, then the rest of
the times I get the exception again. Seems like the server can only handle
one request, before going crazy.
Can someone maybe help diagnose this?
The exception on the client side is:
Oct 13, 2008 2:37:11 PM org.apache.commons.httpclient.HttpMethodDirector
executeWithRetry
INFO: I/O exception (org.apache.commons.httpclient.NoHttpResponseException)
caught when processing request: The server host7 failed to respond
Oct 13, 2008 2:37:11 PM org.apache.commons.httpclient.HttpMethodDirector
executeWithRetry
INFO: Retrying request
Oct 13, 2008 2:37:11 PM org.apache.commons.httpclient.HttpMethodDirector
executeWithRetry
INFO: I/O exception (org.apache.commons.httpclient.NoHttpResponseException)
caught when processing request: The server host7 failed to respond
Oct 13, 2008 2:37:11 PM org.apache.commons.httpclient.HttpMethodDirector
executeWithRetry
INFO: Retrying request
Oct 13, 2008 2:37:11 PM org.apache.commons.httpclient.HttpMethodDirector
executeWithRetry
INFO: I/O exception (org.apache.commons.httpclient.NoHttpResponseException)
caught when processing request: The server host7 failed to respond
Oct 13, 2008 2:37:11 PM org.apache.commons.httpclient.HttpMethodDirector
executeWithRetry
INFO: Retrying request
org.apache.commons.httpclient.NoHttpResponseException: The server host7
failed to respond
at
org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1835)
at
org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1590)
at
org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:995)
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 servletclient.Main.main(Main.java:72)
My client code is below, and I run it with the param:
http://host7:9090/ui?text=hello
URL url = new URL(args[0]);
HttpClient hc = new HttpClient();
GetMethod method = new GetMethod(url.toURI().toString());
try {
int result = hc.executeMethod(method);
String responseStr = method.getResponseBodyAsString();
System.out.println("--- Incoming response
-------------------");
System.out.println(responseStr);
System.out.println("--- Total length: " +
responseStr.length() + " ----------------");
System.out.println("result=" + result);
} finally {
method.releaseConnection();
}
My server code is:
try {
ServerSocketChannel ssc = ServerSocketChannel.open();
ssc.socket().bind(new InetSocketAddress(address, port));
boolean b = true;
while (b) {
SocketChannel ch = ssc.accept();
process(ch); // see process() below
}
} catch (ClosedByInterruptException ex) {
System.out.println("Shutting down listener");
} catch (Throwable ex) {
ex.printStackTrace();
}
process() code:
public static void process(SocketChannel ch) {
try {
ch.configureBlocking(true);
try {
ByteBuffer buf = ByteBuffer.allocate(4096);
StringBuffer sb = new StringBuffer();
ByteArrayOutputStream baos = new
ByteArrayOutputStream();
int result, total = 0;
System.out.println("\n--- Incoming message
-------------------");
buf.clear();
while ((result = ch.read(buf)) > 0) {
total += result;
baos.write(buf.array(), 0, result);
buf.rewind();
if (result < buf.capacity()) break;
}
String s = new String(
baos.toByteArray(),
"ISO-8859-1");
System.out.print(s);
System.out.println ("--- Read total " + total + " bytes
---------------");
ch.write(response); //see response value below
ch.finishConnect();
} finally {
ch.close();
}
} catch (Throwable ex) {
ex.printStackTrace();
}
}
static ByteBuffer response;
static {
String responseStr =
"HTTP/1.1 200 OK\r\n" +
"X-Powered-By: Servlet/2.5\r\n" +
"Content-Type: text/html;charset=ISO-8859-1\r\n" +
"Content-Length: 0\r\n" +
"Date: " + new Date() + "\r\n" +
"Server: mysrv\r\n" +
"Connection: close\r\n\r\n";
try {
response =
ByteBuffer.wrap(responseStr.getBytes("ISO-8859-1"));
} catch (Throwable ex) {
ex.printStackTrace();
}
}
--
View this message in context: http://www.nabble.com/NoHttpResponseException-second-time-around...-tp19954586p19954586.html
Sent from the HttpClient-User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org