title: RestTemplate Spring SocketTimeoutException
body: <p>We get Socket Exception sometimes when i call the API through post through RestTemplate.</p>
  
  <p>We are not using setConnectionTimeout and setReadTimeout for the RestTemplate.</p>
  
  <p>Most of the time(99%), API executes successfully without socket connection issue. But, sometime(1%) we get SocketException.</p>
  
  <p>I done analysis to understand what is the default readtimeout &amp; conntimeout for HttpUrlConnection. I see both timeout is 0 and in-definite timeout.</p>
  
  <p>Here there is no firewall issue because API executes successfully most of the time 99%.</p>
  
  <p>How to debug this issue? Is default readtimeout and connectiontimeout is 0 for HttpUrlConnection?</p>
  
  <pre><code>org.springframework.web.client.ResourceAccessException: I/O error on POST request for "{API url}": Connection reset; nested exception is java.net.SocketException: Connection reset
  at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:633) ~[spring-web-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
      at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:595) ~[spring-web-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
      at org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:423) ~[spring-web-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
  Caused by: java.net.SocketException: Connection reset
      at java.net.SocketInputStream.read(SocketInputStream.java:209) ~[?:1.8.0_45]
      at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[?:1.8.0_45]
      at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) ~[?:1.8.0_45]
      at java.io.BufferedInputStream.read1(BufferedInputStream.java:286) ~[?:1.8.0_45]
      at java.io.BufferedInputStream.read(BufferedInputStream.java:345) ~[?:1.8.0_45]
      at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:704) ~[?:1.8.0_45]
      at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647) ~[?:1.8.0_45]
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1535) ~[?:1.8.0_45]
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440) ~[?:1.8.0_45]
      at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480) ~[?:1.8.0_45]
      at org.springframework.http.client.SimpleClientHttpResponse.getRawStatusCode(SimpleClientHttpResponse.java:52) ~[spring-web-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
  </code></pre>