[ 
https://issues.apache.org/jira/browse/HTTPCLIENT-1170?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13219155#comment-13219155
 ] 

Aniceto Pérez y Madrid commented on HTTPCLIENT-1170:
----------------------------------------------------

This is a faulty conversation using byte[]  completo = 
EntityUtils.toByteArray(entity); to extract content
----------------------------------------------------------------------------------------------------------------------------------------------------
DEBUG [org.apache.http.impl.conn.SingleClientConnManager] Get connection for 
route HttpRoute[{}->http://localhost:8080]
DEBUG [org.apache.http.impl.conn.DefaultClientConnectionOperator] Connecting to 
localhost:8080
DEBUG [org.apache.http.client.protocol.RequestAddCookies] CookieSpec selected: 
best-match
DEBUG [org.apache.http.client.protocol.RequestAuthCache] Auth cache not set in 
the context
DEBUG [org.apache.http.impl.client.DefaultHttpClient] Attempt 1 to execute 
request
DEBUG [org.apache.http.impl.conn.DefaultClientConnection] Sending request: GET 
/GerensDocs/BuzonProyectoRPC?ComRPC_version=2.0&Selector=crpl&ComRPC_WrappedContent=rO0ABXNyACRjb20uaW5ub3Zhc29mdHBzLmltcGwuQ29tUlBDV3JhcHBlcjLYplP02gce7wIAA0wA+CGNsaWVudElkdAASTGphdmEvbGFuZy9TdHJpbmc7TAAGb2JqZXRvdAASTGphdmEvbGFuZy9PYmpl+Y3Q7TAAJb3Bjb3VudGVydAATTGphdmEvbGFuZy9JbnRlZ2VyO3hwcHNyACdnZXJlbnNkb2NzLmNv+bXVudXBsb2FkZXIuUmVxUHJvamVjdExpc3T_QN4G5Yx0bwIABEwABWVtYWlscQB-AAFMAAVmaXJt+YXEAfgABTAACaHNxAH4AAUwABGluZm9xAH4AAXhwdAAXYXBlcmV6QGlubm92YXNvZnRwcy5jb210+ACg3MzZiOTA3YzkyYzQzODA3Yjg1OWNlNWVjM2Y1MThjZTA1MGUxZDI0dAAoNGExZGM3NTM4ODg0+OGNmZTRkZGMzZWEwNDczOTY1YmFmMmZiNDBkNXQAJ2I3ZjI4NGQ5YTRhNjdkNTNkY2RjMjdlMWM1+YWM5ODMzYjRmNDlkMHA%3D&ComRPC_AllHash_NAME=92939388e44a7aeb170a53ec2ac6299f6f745633
 HTTP/1.1
DEBUG [org.apache.http.headers] >> GET 
/GerensDocs/BuzonProyectoRPC?ComRPC_version=2.0&Selector=crpl&ComRPC_WrappedContent=rO0ABXNyACRjb20uaW5ub3Zhc29mdHBzLmltcGwuQ29tUlBDV3JhcHBlcjLYplP02gce7wIAA0wA+CGNsaWVudElkdAASTGphdmEvbGFuZy9TdHJpbmc7TAAGb2JqZXRvdAASTGphdmEvbGFuZy9PYmpl+Y3Q7TAAJb3Bjb3VudGVydAATTGphdmEvbGFuZy9JbnRlZ2VyO3hwcHNyACdnZXJlbnNkb2NzLmNv+bXVudXBsb2FkZXIuUmVxUHJvamVjdExpc3T_QN4G5Yx0bwIABEwABWVtYWlscQB-AAFMAAVmaXJt+YXEAfgABTAACaHNxAH4AAUwABGluZm9xAH4AAXhwdAAXYXBlcmV6QGlubm92YXNvZnRwcy5jb210+ACg3MzZiOTA3YzkyYzQzODA3Yjg1OWNlNWVjM2Y1MThjZTA1MGUxZDI0dAAoNGExZGM3NTM4ODg0+OGNmZTRkZGMzZWEwNDczOTY1YmFmMmZiNDBkNXQAJ2I3ZjI4NGQ5YTRhNjdkNTNkY2RjMjdlMWM1+YWM5ODMzYjRmNDlkMHA%3D&ComRPC_AllHash_NAME=92939388e44a7aeb170a53ec2ac6299f6f745633
 HTTP/1.1
DEBUG [org.apache.http.headers] >> Host: localhost:8080
DEBUG [org.apache.http.headers] >> Connection: Keep-Alive
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] << Server: Apache-Coyote/1.1
DEBUG [org.apache.http.headers] << Content-Type: 
application/octet-stream;charset=UTF-8
DEBUG [org.apache.http.headers] << Content-Length: 30828
DEBUG [org.apache.http.headers] << Date: Wed, 29 Feb 2012 12:32:33 GMT
DEBUG [org.apache.http.impl.client.DefaultHttpClient] Connection can be kept 
alive indefinitely

and here it stops then doing  completo = EntityUtils.toByteArray(entity);

And this is a working one
------------------------------------
DEBUG [org.apache.http.impl.conn.SingleClientConnManager] Get connection for 
route HttpRoute[{}->http://localhost:8080]
DEBUG [org.apache.http.impl.conn.DefaultClientConnectionOperator] Connecting to 
localhost:8080
DEBUG [org.apache.http.client.protocol.RequestAddCookies] CookieSpec selected: 
best-match
DEBUG [org.apache.http.client.protocol.RequestAuthCache] Auth cache not set in 
the context
DEBUG [org.apache.http.impl.client.DefaultHttpClient] Attempt 1 to execute 
request
DEBUG [org.apache.http.impl.conn.DefaultClientConnection] Sending request: GET 
/GerensDocs/BuzonProyectoRPC?ComRPC_version=2.0&Selector=crping&ComRPC_WrappedContent=rO0ABXNyACRjb20uaW5ub3Zhc29mdHBzLmltcGwuQ29tUlBDV3JhcHBlcjLYplP02gce7wIAA0wA+CGNsaWVudElkdAASTGphdmEvbGFuZy9TdHJpbmc7TAAGb2JqZXRvdAASTGphdmEvbGFuZy9PYmpl+Y3Q7TAAJb3Bjb3VudGVydAATTGphdmEvbGFuZy9JbnRlZ2VyO3hwcHNyACBnZXJlbnNkb2NzLmNv+bXVudXBsb2FkZXIuUmVxUGluZ0HkEJQWJCPlAgADWgALaXNVcGxvYWRpbmdMAAVlbWFpbHEAfgAB+TAACaHNxAH4AAXhwAHB0ACg4MTU1MDJjZDQ4NjcyMmFjYWRjYWI1NTg3YzU4NGI3Y2EyNDA3MTY5+cA%3D%3D&ComRPC_AllHash_NAME=58705d496ea65c65f670eb45bbca1bbc6c64110e
 HTTP/1.1
DEBUG [org.apache.http.headers] >> GET 
/GerensDocs/BuzonProyectoRPC?ComRPC_version=2.0&Selector=crping&ComRPC_WrappedContent=rO0ABXNyACRjb20uaW5ub3Zhc29mdHBzLmltcGwuQ29tUlBDV3JhcHBlcjLYplP02gce7wIAA0wA+CGNsaWVudElkdAASTGphdmEvbGFuZy9TdHJpbmc7TAAGb2JqZXRvdAASTGphdmEvbGFuZy9PYmpl+Y3Q7TAAJb3Bjb3VudGVydAATTGphdmEvbGFuZy9JbnRlZ2VyO3hwcHNyACBnZXJlbnNkb2NzLmNv+bXVudXBsb2FkZXIuUmVxUGluZ0HkEJQWJCPlAgADWgALaXNVcGxvYWRpbmdMAAVlbWFpbHEAfgAB+TAACaHNxAH4AAXhwAHB0ACg4MTU1MDJjZDQ4NjcyMmFjYWRjYWI1NTg3YzU4NGI3Y2EyNDA3MTY5+cA%3D%3D&ComRPC_AllHash_NAME=58705d496ea65c65f670eb45bbca1bbc6c64110e
 HTTP/1.1
DEBUG [org.apache.http.headers] >> Host: localhost:8080
DEBUG [org.apache.http.headers] >> Connection: Keep-Alive
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] << Server: Apache-Coyote/1.1
DEBUG [org.apache.http.headers] << Content-Type: 
application/octet-stream;charset=UTF-8
DEBUG [org.apache.http.headers] << Content-Length: 360
DEBUG [org.apache.http.headers] << Date: Wed, 29 Feb 2012 12:29:38 GMT
DEBUG [org.apache.http.impl.client.DefaultHttpClient] Connection can be kept 
alive indefinitely
DEBUG [org.apache.http.impl.conn.SingleClientConnManager] Releasing connection 
org.apache.http.impl.conn.SingleClientConnManager$ConnAdapter@26c5920f
DEBUG [org.apache.http.impl.conn.DefaultClientConnection] Connection shut down

                
> Incomplete data received from servlet
> -------------------------------------
>
>                 Key: HTTPCLIENT-1170
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1170
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1.3
>         Environment: java 1.7.0_0, Windows 7 x 64, Apache 7.0.22, connections 
> are made throug http://localhost
>            Reporter: Aniceto Pérez y Madrid
>            Priority: Blocker
>
> Hi
> I have this servlet that generates on the fly a binary response by 
> serializing an object. buf size is about 30 KB. I've been using this code to 
> serve files for a long time. If I access that servlet using any web browser, 
> the received file is OK.
>                       byte[] buf = respObject.stringBinSerialize();
>                       response.setContentLength(buf.length);
>                       response.setContentType("binary/octet-stream");
>                       response.setStatus(HttpServletResponse.SC_OK);
>                       OutputStream out = response.getOutputStream();
>                       out.write(buf);
>                       out.flush();
> Now I have this client code and it doesn't receive the full response. 
>                 byte[] completo = new byte[0], temporal;
>                 byte[] cbuf = new byte[4096];
>                 int cuenta = 0, esta = 0;
>                 HttpParams params = new SyncBasicHttpParams();
>                 HttpConnectionParams.setSocketBufferSize(params, 64000);
>                 HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
>                 HttpClient httpclient = new DefaultHttpClient(params);
>                 try {
>                     HttpPost httpost = new HttpPost(targetURLinclServletName);
>                     HttpGet httpget = new 
> HttpGet("http://localhost:8080/myservlet";);
>                     HttpResponse response = httpclient.execute(httpget);
>                     HttpEntity entity = response.getEntity();
>                     if (entity != null) {
>                         System.out.println("ent sz " + 
> entity.getContentLength() + " chk " + entity.isChunked() + " is rept " + 
> entity.isRepeatable() + "  str " + entity.isStreaming());
> //                        completo = EntityUtils.toByteArray(entity);
>                         System.out.println("bytearrayed " + completo.length);
>                         InputStream instream = entity.getContent();
>                         while (completo.length != entity.getContentLength() 
> && (esta = instream.read(cbuf)) != -1) {
>                             if (selector.equals(RPCdefs.SELECTOR_PROYLIST) || 
> true) {
>                                 cuenta += esta;
>                                 System.out.println("readline" + esta + "  van 
> " + cuenta);
>                                 System.out.println("sz " + 
> entity.getContentLength());
>                             }
>                             temporal = new byte[completo.length + esta];
>                             System.arraycopy(completo, 0, temporal, 0, 
> completo.length);
>                             System.arraycopy(cbuf, 0, temporal, 
> completo.length, esta);
>                             completo = temporal;
>                             temporal = null;
>                         }
>                     }
>                     EntityUtils.consume(entity);
>                 } finally {
>                     httpclient.getConnectionManager().shutdown();
>                 }
> The simplest way to receive is  EntityUtils.toByteArray(entity), but it gets 
> hung. The loop for partial copy is to know how may bytes are received. They 
> are about 17845. The initial params were added to check if the issue was 
> related to flow control, but with 64 KB buffers it doesn't changes anything. 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to