You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Aniceto Pérez y Madrid (Created JIRA)" <ji...@apache.org> on 2012/02/29 11:03:57 UTC
[jira] [Created] (HTTPCLIENT-1170) Incomplete data received from
servlet
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: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] [Commented] (HTTPCLIENT-1170) Incomplete data received from
servlet
Posted by "Mayank Nakrani (Commented) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1170?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13249804#comment-13249804 ]
Mayank Nakrani commented on HTTPCLIENT-1170:
--------------------------------------------
Actually even im facing the exact issue. Im using HttpClient for android. God know y the hell my http client is downloading exactly half the content expected from the server. The browser shows the full page. I used http sniffers to confirm the same..Please somebody try to fix it.
> 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: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] [Issue Comment Edited] (HTTPCLIENT-1170) Incomplete data
received from servlet
Posted by "Aniceto Pérez y Madrid (Issue Comment Edited JIRA)" <ji...@apache.org>.
[ 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 edited comment on HTTPCLIENT-1170 at 2/29/12 12:50 PM:
------------------------------------------------------------------------------
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 when 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
was (Author: aperezymadrid):
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: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] [Resolved] (HTTPCLIENT-1170) Incomplete data received from
servlet
Posted by "Oleg Kalnichevski (Resolved) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1170?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Oleg Kalnichevski resolved HTTPCLIENT-1170.
-------------------------------------------
Resolution: Invalid
Unfortunately just your saying is not enough. If there is no more bytes available in the input stream the most likely explanation is that the server is simply is not sending any.
(1) Please remove your custom code and change your code to use a standard route to consume response content such as those provided HttpUtils. Once you get it to work you can change your application code to use whatever custom routine you see fit.
(2) Please provide a _complete_ wire / context log of the session [1].
If you re-open this issue without providing sufficient evidence the alleged bug, I'll close it without giving any additional explanations.
Oleg
[1] http://hc.apache.org/httpcomponents-client-ga/logging.html
> 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: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] [Commented] (HTTPCLIENT-1170) Incomplete data received from
servlet
Posted by "Aniceto Pérez y Madrid (Commented JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1170?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13219193#comment-13219193 ]
Aniceto Pérez y Madrid commented on HTTPCLIENT-1170:
----------------------------------------------------
I had forgotten to put a exception stack dump in the server at the finnally clause
ServletOutputStream out = null;
try {
// Get the bytes of the serialized object
byte[] buf = respObject.stringBinSerialize();
System.out.println("length " + buf.length);
response.setContentType(APPLICATION_OCTET_STREAM);
response.setContentLength(buf.length);
response.setStatus(HttpServletResponse.SC_OK);
out = response.getOutputStream();
int escritos = 0;
while (escritos < buf.length) {
int tramo = 4096;
if (tramo + escritos > buf.length) {
tramo = buf.length - escritos;
}
out.write(buf, escritos, tramo);
escritos += tramo;
System.out.println("escritos " + tramo + " van " + escritos);
}
} catch (Exception ee) {
ee.printStackTrace();
} finally {
try {
// out.flush();
response.flushBuffer();
} catch (Exception ee) {
ee.printStackTrace();
}
And when the client gets stopped, if I stop the client session I get this trace
ClientAbortException: java.net.SocketException: Connection reset by peer: socket write error
at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:333)
at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:299)
at org.apache.catalina.connector.Response.flushBuffer(Response.java:560)
at org.apache.catalina.connector.ResponseFacade.flushBuffer(ResponseFacade.java:303)
at com.innovasoftps.impl.ComRPCresponder3Impl.sendResponse(ComRPCresponder3Impl.java:105)
This also happens when flushing the output stream intead of the response.
What I think it's happening is that flow control is not working.
> 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: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] [Commented] (HTTPCLIENT-1170) Incomplete data received from
servlet
Posted by "Aniceto Pérez y Madrid (Commented JIRA)" <ji...@apache.org>.
[ 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: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] [Commented] (HTTPCLIENT-1170) Incomplete data received from
servlet
Posted by "Oleg Kalnichevski (Commented) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1170?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13219179#comment-13219179 ]
Oleg Kalnichevski commented on HTTPCLIENT-1170:
-----------------------------------------------
And what does this tell you? HttpClient uses Content-Length value specified in the response head to delineate message body. Apparently the server is sending fewer bytes that declared by the Content-Length causing HttpClient to block in a read operation while expecting more data. Your own code behaves exactly the same way.
There can be several possibilities for such behavior. (1) The content-length value is miscalculated on the server side. Common browsers seem to have special logic that enables them to detect and recover from such situations. (2) The server fails to send enough content for some reason.
You can see what physically gets sent across the wire by using a packet sniffer such Wireshark. If you are still convinced the problem is on the client side please create a _self-contained_ web application I could deploy locally _and_ a client side test case that can be used to reproduce the problem against a local servlet engine, then re-open the issue and attach both artifacts to it.
Oleg
> 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: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] [Commented] (HTTPCLIENT-1170) Incomplete data received from
servlet
Posted by "Aniceto Pérez y Madrid (Commented JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1170?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13219194#comment-13219194 ]
Aniceto Pérez y Madrid commented on HTTPCLIENT-1170:
----------------------------------------------------
Oleg
I've put log messages in the server and the number of bytes written to the outputstream is correct. The problem is that for some reason thery are no fully sent.
Thanks
> 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: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] [Commented] (HTTPCLIENT-1170) Incomplete data received from
servlet
Posted by "Aniceto Pérez y Madrid (Commented JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1170?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13220175#comment-13220175 ]
Aniceto Pérez y Madrid commented on HTTPCLIENT-1170:
----------------------------------------------------
It seems related with my machine. I thought it was "clean", but it seems not.
> 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: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] [Resolved] (HTTPCLIENT-1170) Incomplete data received from
servlet
Posted by "Oleg Kalnichevski (Resolved) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1170?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Oleg Kalnichevski resolved HTTPCLIENT-1170.
-------------------------------------------
Resolution: Invalid
I see no evidence of this being a bug in HttpClient. If you need help writing code that correctly reads and deserializes entity content please post your code to the user list, ideally with a wire / context log of the session.
Oleg
> 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: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
[jira] [Reopened] (HTTPCLIENT-1170) Incomplete data received from
servlet
Posted by "Aniceto Pérez y Madrid (Reopened JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1170?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Aniceto Pérez y Madrid reopened HTTPCLIENT-1170:
------------------------------------------------
The problem is not the serializing or deserializing an object. The problem is servlet is sending 30KB of binary data and httpclient only receives 17KB. With less than 14KB it works fine. But a browser receives the full content. So I say there is a bug.
When the servlet says length 30830, I get this from the client log
readline4096 van 4096
sz 30830
readline4096 van 8192
sz 30830
readline653 van 8845
sz 30830
readline4096 van 12941
sz 30830
readline4096 van 17037
sz 30830
readline808 van 17845
sz 30830
and here it gets stuck because no more bytes are available from the inputStream.
Thanks
> 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: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org