Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

urgent help - java.net.SocketException: Connection reset by peer: socket write error

 
mudit khandelwal
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Strangely and unluckily, I have a problem that's happening only in PRODUCTION env and not on DEVELOPMENT/CERT :-(

When I make an Http request to a server (using java.net.URL and URLConnection classes) which sends a pdf as a response, I get the response and read it in a BufferedInputStream. Then in order to display the pdf on my browser, am trying to write bytes to ServletOutputStream using byte array:
bis is the BufferedInputStream;

byte[] buff = new byte[1024];
int bytesRead;
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))){
out.write(buff, 0, bytesRead);
}

Many a times it works properly and the pdf is rendered but sometimes I get 'java.net.SocketException: Connection reset by peer: socket write error' exception while trying to write to the ServletOutputStream in the while loop - out.write(buff, 0, bytesRead);

(Am using weblogc 8.1 sp2)

error log:
java.net.SocketException: Connection reset by peer: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at weblogic.servlet.internal.ChunkUtils.writeChunkTransfer(ChunkUtils.java:247)
at weblogic.servlet.internal.ChunkUtils.writeChunks(ChunkUtils.java:223)
at weblogic.servlet.internal.ChunkOutput.flush(ChunkOutput.java:296)
at weblogic.servlet.internal.ChunkOutput.checkForFlush(ChunkOutput.java:371)
at weblogic.servlet.internal.ChunkOutput.write(ChunkOutput.java:241)
at weblogic.servlet.internal.ChunkOutputWrapper.write(ChunkOutputWrapper.java:113)
at weblogic.servlet.internal.ServletOutputStreamImpl.write(ServletOutputStreamImpl.java:184)
at tavant.olympus.common.utils.ServletHelper.writeToServletOutputStream(ServletHelper.java:48)
at tavant.olympus.base.GenericRetrievalServlet.sendRequestAndPrintTheResponse(GenericRetrievalServlet.java:90)
at

tavant.olympus.client.aereports.AEStaticReportsRetrievalServlet.serviceRequest(AEStaticReportsRetrievalServlet.java:34)
at tavant.olympus.base.GenericRetrievalServlet.doPost(GenericRetrievalServlet.java:57)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6350)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)

Any kinna help will be highly appreciated !!
Thanx in advance.
Mudit
 
Vijay Vaddem
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Please go through the below given link. Could be helpful to you...

Connection Reset

Go through the response given by Kartik Ruppa and the link being provided.

Vijay
 
yerri swamy moke
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am also facing same issue, please give me the solution for this issue.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The same issue? So you are using WebLogic v8.1 and are streaming a PDF to the client?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just dont worry about it.

The client side closed the connection for some reason, nothing can be done on the server side to prevent this.

You could catch the Exception in your servlet method if you need to log that the transfer was incomplete.

Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic