Return-Path: Delivered-To: apmail-hc-httpclient-users-archive@www.apache.org Received: (qmail 97726 invoked from network); 13 Oct 2008 13:07:32 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 13 Oct 2008 13:07:32 -0000 Received: (qmail 92959 invoked by uid 500); 13 Oct 2008 13:07:32 -0000 Delivered-To: apmail-hc-httpclient-users-archive@hc.apache.org Received: (qmail 92930 invoked by uid 500); 13 Oct 2008 13:07:31 -0000 Mailing-List: contact httpclient-users-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpClient User Discussion" Delivered-To: mailing list httpclient-users@hc.apache.org Received: (qmail 92919 invoked by uid 99); 13 Oct 2008 13:07:31 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Oct 2008 06:07:31 -0700 X-ASF-Spam-Status: No, hits=4.1 required=10.0 tests=DNS_FROM_OPENWHOIS,SPF_HELO_PASS,SPF_PASS,WEIRD_PORT,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of lists@nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Oct 2008 13:06:24 +0000 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1KpN8W-0003n3-Lt for httpclient-users@hc.apache.org; Mon, 13 Oct 2008 06:07:00 -0700 Message-ID: <19954586.post@talk.nabble.com> Date: Mon, 13 Oct 2008 06:07:00 -0700 (PDT) From: Sagi Mann To: httpclient-users@hc.apache.org Subject: NoHttpResponseException second time around... MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: sagimann@gmail.com X-Virus-Checked: Checked by ClamAV on apache.org 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