java - Intermittent "Socket closed" exception with HttpUrlConnection -
i have servlet application running under jboss 7.1.1/java 1.7 sends http requests server. works fine of time, (from 1 couple of times day) “socket closed” exception. i’ve been trying find out might causing far i’ve been unsuccessful. way, has been happening while application running under older versions of jboss/java versions might not relevant.
here’s excerpt method happens:
. . . . .
try { httpurlconnection conn = (httpurlconnection) urlendpoint.openconnection(); conn.setrequestmethod("post"); conn.setdoinput(true); conn.setdooutput(true); conn.setrequestproperty("content-type", "text/xml; charset=utf-8"); conn.setrequestproperty("charset", "utf-8"); dataoutputstream out = new dataoutputstream(conn.getoutputstream()); out.write(env.getbytes("utf-8")); out.flush(); out.close(); inputstream iss = null; conn.connect(); try { iss = conn.getinputstream(); // exception caught
. . . . . .
and here’s exception looks like:
. . . . . .
java.net.socketexception: socket closed @ java.net.socketinputstream.socketread0(native method) @ java.net.socketinputstream.read(socketinputstream.java:150) @ java.net.socketinputstream.read(socketinputstream.java:121) @ java.io.bufferedinputstream.fill(bufferedinputstream.java:235) @ java.io.bufferedinputstream.read1(bufferedinputstream.java:275) @ java.io.bufferedinputstream.read(bufferedinputstream.java:334) @ sun.net.www.http.httpclient.parsehttpheader(httpclient.java:633) @ sun.net.www.http.httpclient.parsehttp(httpclient.java:579) @ sun.net.www.protocol.http.httpurlconnection.getinputstream(httpurlconnection.java:1322)
. . . . . .
i came across posts mentioning sockets pool http connection keeping, i’m not sure whether , how can me solve problem have.
i’ve exhausted ideas had , grateful help.
it make more sense call conn.connect()
before doing i/o. doesn't make sense @ afterwards. don't need close output stream.
Comments
Post a Comment