Return-Path: X-Original-To: apmail-hc-httpclient-users-archive@www.apache.org Delivered-To: apmail-hc-httpclient-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9D8C7FA2D for ; Mon, 1 Apr 2013 21:33:18 +0000 (UTC) Received: (qmail 95223 invoked by uid 500); 1 Apr 2013 21:33:17 -0000 Delivered-To: apmail-hc-httpclient-users-archive@hc.apache.org Received: (qmail 94681 invoked by uid 500); 1 Apr 2013 21:33:17 -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 94531 invoked by uid 99); 1 Apr 2013 21:33:16 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Apr 2013 21:33:16 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [209.85.220.179] (HELO mail-vc0-f179.google.com) (209.85.220.179) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Apr 2013 21:33:12 +0000 Received: by mail-vc0-f179.google.com with SMTP id gf12so2885411vcb.10 for ; Mon, 01 Apr 2013 14:32:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:content-type:content-transfer-encoding:subject :message-id:date:to:mime-version:x-mailer:x-gm-message-state; bh=xzR3Y7PldRpp19Ai4g7DBVTQ6nN6lJUHZWWfi0UhgDE=; b=o3WsRzXXQGM9b3MU1p0lblIXH47IVXTJuCXD0V3m6kSeiVhX3l7i93uYeP+sFADjQd uTj3mgD1DbBKB9aGJhwkucMWIrqQE89yoZIrVMD4E4HBnXIHJ90igeSK5yple0bzrjck obbJETt0fLqHGF5gMO0LIJeNjIBlITJuI/hWn7yfuQH2f9pvHS8yAmMPdw+uLwX8rHH3 CwHadGhFHzXX5+JFnUpYQWJGSXPRMN3fZeO5aa5XxUSpsKIb9S5kRZvc2doof1GdNLg+ OUI3SHLErw0aI31rBUgGppg6p1NZTvWKnv0yMn4G7O8KIJch2B3ruFrZE2tE+EfWaCJj 0gGQ== X-Received: by 10.58.169.102 with SMTP id ad6mr10402926vec.53.1364851970708; Mon, 01 Apr 2013 14:32:50 -0700 (PDT) Received: from [216.128.150.97] ([216.128.150.97]) by mx.google.com with ESMTPS id s20sm16070003vdg.2.2013.04.01.14.32.49 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 01 Apr 2013 14:32:49 -0700 (PDT) From: James Puckett Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Subject: inputStream.read() blocks at end of chunk Message-Id: <9FE5A679-A08B-4082-B428-A091B78B6164@e-c-group.com> Date: Mon, 1 Apr 2013 17:32:48 -0400 To: httpclient-users@hc.apache.org Mime-Version: 1.0 (Mac OS X Mail 6.3 \(1503\)) X-Mailer: Apple Mail (2.1503) X-Gm-Message-State: ALoCoQlD/bXvuFr9LTfeGZAa0NTJOTuSpd3ufT9kv2m1nEszfP9PTI8FhR+bwUar/C0Qz76JpYzI X-Virus-Checked: Checked by ClamAV on apache.org I need a persistent Http connection over which I will receive multiple = XML responses. Each XML response should be a chunk from the server. I'm using httpclient-4.2.3 and the following code. Currently, the = HttpClient blocks on the inputStream.read() on the character following = the of the chunk. The read eventually (~15 seconds) returns and things = continue. I should note that the first read() fills the buffer with the = 180 (b4) chars of the first chunk. It's the second read that blocks. Is there a way to get access to the chunk size prior to the read? In = the case capture in the DEBUG output below, it's 180 (b4) chars. Or is there a better way to read this full chunk, even if it spans = multiple buffers and therefore multiple reads? =3D=3D try { response =3D httpClient.execute(post); System.out.println("OUTPUT: " + = Runner.getURIBase() + request.getURIPath() + "\n" + postContent); HttpEntity entity =3D response.getEntity(); byte[] buffer =3D new byte[1024]; if (entity !=3D null) { InputStream inputStream =3D = entity.getContent(); try { while (!done) { StringBuilder sb =3D new = StringBuilder(); int bytesRead =3D 0; while ((bytesRead =3D = inputStream.read(buffer)) !=3D -1) { String chunk =3D = new String(buffer, 0, bytesRead); = System.out.println("CHUNK?: " + chunk); = sb.append(chunk); } =09 // TODO: Need to check = here for multiple messages in the same chunk if (sb.length() > 0) { = System.out.println("CHUNK: " + sb.toString()); = BroadWorksResponse broadworksResponse =3D BroadWorksResponse = .getResponse(sb.toString()); =09 =09 if = (broadworksResponse !=3D null) = broadworksResponse.fireNextEvent(); =09 sb.setLength(0); } // } } catch (Exception e) { e.printStackTrace(); } finally { try { inputStream.close(); } catch (Exception ignore) { } } } } catch (ClientProtocolException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } DEBUG [org.apache.http.impl.conn.DefaultClientConnection] Sending = request: POST /com.broadsoft.async/com.broadsoft.xsi-events/v2.0/channel = HTTP/1.1 DEBUG [org.apache.http.wire] >> "POST = /com.broadsoft.async/com.broadsoft.xsi-events/v2.0/channel = HTTP/1.1[\r][\n]" DEBUG [org.apache.http.wire] >> "Content-Length: 233[\r][\n]" DEBUG [org.apache.http.wire] >> "Content-Type: text/plain; = charset=3DISO-8859-1[\r][\n]" DEBUG [org.apache.http.wire] >> "Host: ews1.vwave.net:80[\r][\n]" DEBUG [org.apache.http.wire] >> "Connection: Keep-Alive[\r][\n]" DEBUG [org.apache.http.wire] >> "User-Agent: Apache-HttpClient/4.2.3 = (java 1.5)[\r][\n]" DEBUG [org.apache.http.wire] >> "Cookie: = JSESSIONID=3DC041612511AE5606103DC6CDB2C79973[\r][\n]" DEBUG [org.apache.http.wire] >> "Cookie2: $Version=3D1[\r][\n]" DEBUG [org.apache.http.wire] >> "Authorization: Basic = MjI5MzE2MDAxMkB2d2F2ZS5uZXQ6c2lnbmFsbWUwMQ=3D=3D[\r][\n]" DEBUG [org.apache.http.wire] >> "[\r][\n]" DEBUG [org.apache.http.headers] >> POST = /com.broadsoft.async/com.broadsoft.xsi-events/v2.0/channel HTTP/1.1 DEBUG [org.apache.http.headers] >> Content-Length: 233 DEBUG [org.apache.http.headers] >> Content-Type: text/plain; = charset=3DISO-8859-1 DEBUG [org.apache.http.headers] >> Host: ews1.vwave.net:80 DEBUG [org.apache.http.headers] >> Connection: Keep-Alive DEBUG [org.apache.http.headers] >> User-Agent: Apache-HttpClient/4.2.3 = (java 1.5) DEBUG [org.apache.http.headers] >> Cookie: = JSESSIONID=3DC041612511AE5606103DC6CDB2C79973 DEBUG [org.apache.http.headers] >> Cookie2: $Version=3D1 DEBUG [org.apache.http.headers] >> Authorization: Basic = MjI5MzE2MDAxMkB2d2F2ZS5uZXQ6c2lnbmFsbWUwMQ=3D=3D DEBUG [org.apache.http.wire] >> "[\n]" DEBUG [org.apache.http.wire] >> "[\n]" DEBUG [org.apache.http.wire] >> = "TempTestChannelSetId[\n]" DEBUG [org.apache.http.wire] >> "1[\n]" DEBUG [org.apache.http.wire] >> "50[\n]" DEBUG [org.apache.http.wire] >> "3600[\n]" DEBUG [org.apache.http.wire] >> "[\n]" DEBUG [org.apache.http.wire] << "HTTP/1.1 200 OK[\r][\n]" DEBUG [org.apache.http.wire] << "Date: Mon, 01 Apr 2013 21:21:46 = GMT[\r][\n]" DEBUG [org.apache.http.wire] << "Server: Apache-Coyote/1.1[\r][\n]" DEBUG [org.apache.http.wire] << "Expires: Thu, 01 Jan 1970 00:00:00 = GMT[\r][\n]" DEBUG [org.apache.http.wire] << "Content-Language: en-US[\r][\n]" DEBUG [org.apache.http.wire] << "Cache-Control: no-store[\r][\n]" DEBUG [org.apache.http.wire] << "Pragma: no-cache[\r][\n]" DEBUG [org.apache.http.wire] << "Content-Type: = application/xml;charset=3DUTF-8[\r][\n]" DEBUG [org.apache.http.wire] << "Set-Cookie: = JSESSIONID=3DBC1A855C506266CB346506641C735FFC; = Path=3D/com.broadsoft.xsi-events[\r][\n]" DEBUG [org.apache.http.wire] << "Keep-Alive: timeout=3D15, = max=3D98[\r][\n]" DEBUG [org.apache.http.wire] << "Connection: Keep-Alive[\r][\n]" DEBUG [org.apache.http.wire] << "Transfer-Encoding: chunked[\r][\n]" DEBUG [org.apache.http.wire] << "[\r][\n]" DEBUG [org.apache.http.impl.conn.DefaultClientConnection] Receiving = response: HTTP/1.1 200 OK DEBUG [org.apache.http.headers] << HTTP/1.1 200 OK DEBUG [org.apache.http.headers] << Date: Mon, 01 Apr 2013 21:21:46 GMT DEBUG [org.apache.http.headers] << Server: Apache-Coyote/1.1 DEBUG [org.apache.http.headers] << Expires: Thu, 01 Jan 1970 00:00:00 = GMT DEBUG [org.apache.http.headers] << Content-Language: en-US DEBUG [org.apache.http.headers] << Cache-Control: no-store DEBUG [org.apache.http.headers] << Pragma: no-cache DEBUG [org.apache.http.headers] << Content-Type: = application/xml;charset=3DUTF-8 DEBUG [org.apache.http.headers] << Set-Cookie: = JSESSIONID=3DBC1A855C506266CB346506641C735FFC; = Path=3D/com.broadsoft.xsi-events DEBUG [org.apache.http.headers] << Keep-Alive: timeout=3D15, max=3D98 DEBUG [org.apache.http.headers] << Connection: Keep-Alive DEBUG [org.apache.http.headers] << Transfer-Encoding: chunked WARN [org.apache.http.client.protocol.ResponseProcessCookies] Cookie = rejected: "[version: 0][name: JSESSIONID][value: = BC1A855C506266CB346506641C735FFC][domain: ews1.vwave.net][path: = /com.broadsoft.xsi-events][expiry: null]". Illegal path attribute = "/com.broadsoft.xsi-events". Path of origin: = "/com.broadsoft.async/com.broadsoft.xsi-events/v2.0/channel" DEBUG [org.apache.http.impl.client.DefaultHttpClient] Connection can be = kept alive for 15000 MILLISECONDS DEBUG [org.apache.http.impl.client.DefaultHttpClient] Authentication = succeeded DEBUG [org.apache.http.impl.client.TargetAuthenticationStrategy] Caching = 'basic' auth scheme for http://ews1.vwave.net:80 OUTPUT: = http://ews1.vwave.net:80/com.broadsoft.async/com.broadsoft.xsi-events/v2.0= /channel org.apache.http.entity.StringEntity@78c36c6f DEBUG [org.apache.http.wire] << "b4[\r][\n]" DEBUG [org.apache.http.wire] << "[\n]" DEBUG [org.apache.http.wire] << "c9d5b432-db96-4256-87= 71-cdb6e3a1e8973600" CHUNK?: c9d5b432-db96-4256-87= 71-cdb6e3a1e8973600 DEBUG [org.apache.http.wire] << "[\r][\n]"= --------------------------------------------------------------------- To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org For additional commands, e-mail: httpclient-users-help@hc.apache.org