0

I know i am making a simple mistake but cannot figure out whats the mistake. I have an external API where I need to post certain parameters. I tested this API using Advanced Rest Client and it works fine. In my server side, i use

ResponseEntity<String> response = asyncRestTemplate.getRestOperations().postForEntity(URL, String.class);

But then this method always throws a exception for the particular URL that i am testing.

I tried other URLS and it works perfectly fine.

Is it possible that the connection reset might occur because the third party who provided me the URL is closing the connection. If it is so, how did Advanced Rest Client manage to get the result?

This is the stack Trace

org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://1984.carpal.me/api/v1/quote/":Connection reset; nested exception is java.net.SocketException: Connection reset
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:580)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:530)
at org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:357)
at sg.oddlefnb.common.helper.CarpalApiHelper.getRequestEntityForNewJob(CarpalApiHelper.java:115)
at sg.oddlefnb.common.helper.PartnerApiHelper.postNewJob(PartnerApiHelper.java:54)
at sg.oddlefnb.common.helper.PartnerApiHelper$$FastClassBySpringCGLIB$$b2958cff.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:717)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.aop.interceptor.AsyncExecutionInterceptor$1.call(AsyncExecutionInterceptor.java:110)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at org.springframework.core.task.SimpleAsyncTaskExecutor$ConcurrencyThrottlingRunnable.run(SimpleAsyncTaskExecutor.java:251)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:196)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)
at sun.security.ssl.InputRecord.read(InputRecord.java:480)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:934)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153)
at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:81)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:569)
... 12 more
Orest Hera
  • 6,706
  • 2
  • 21
  • 35
heshik nandan
  • 21
  • 1
  • 5
  • Post the *exact* error message, exception, and stack trace. Not a paraphrase. Never seen 'connection Error' in 18 years of Java. – user207421 Oct 14 '15 at 10:08
  • @EJP This is all the stack trace i got for that error. – heshik nandan Oct 14 '15 at 10:27
  • Do you see the difference between your imaginary 'connection Error' and 'connection reset'? – user207421 Oct 14 '15 at 11:01
  • Yes I am sorry for the wrong information - @EJP – heshik nandan Oct 15 '15 at 03:48
  • Reasons for connection reset: http://stackoverflow.com/questions/62929/java-net-socketexception-connection-reset, similar posts and comments: http://stackoverflow.com/questions/23346115/spring-resttemplate-connection-reset (issues with firewall), http://stackoverflow.com/questions/29509213/getting-connect-reset-exception – Orest Hera Oct 15 '15 at 15:06

0 Answers0