[
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.jspaFor more information on JIRA, see:
http://www.atlassian.com/software/jira---------------------------------------------------------------------
To unsubscribe, e-mail:
dev-unsubscribe@...
For additional commands, e-mail:
dev-help@...