Spring RestTemplate call fails intermittently with 'SocketException: Connection reset' - spring

The following exception i am getting when our application is consuming the Rest endpoint using spring boot RestTemplate.
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://xxxxxxxxxx:123456/xxxxx/xxxxx/xxxxxx/xxxx":
Connection has been shutdown: javax.net.ssl.SSLException: java.net.SocketException: Connection reset; nested exception is javax.net.ssl.SSLException:
Connection has been shutdown: javax.net.ssl.SSLException: java.net.SocketException: Connection reset
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:741)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:684)
at org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:466)
This issue we are getting intermittently. some time more than 2 to 3 times.
I couldn't find any information specific to this issue ?
Does any one faced same issue and how its resolved?

Do the CURL on the endpoint you are trying to access using RESTTemplate and see if your machine has access to that URL?
If Yes-->Let me know and still getting an error, Let me know I will update the answer:)
If No-->that the problem I had the same issue for facebook API.

Related

In Spring boot running in ECS getting connection reset - using restTemplate

I deployed the spring boot in AWS ECS
When making api using restetemplate ,it is giving the below error
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "THE URL": Connection reset; nested exception is java.net.SocketException: Connection reset
But this error is occurring intermediate only , how to resolve this issue

Feign Client with PCF internal route

With Feign client I couldn't connect to an api endpoint hosted on internal route in PCF. Getting connection refused exception like below. Any advise on resolving this issue?
feign.RetryableException: Connection refused (Connection refused) executing POST http://dev-myapp.apps.internal:8080/sendorder
2019-03-12T10:40:20.85+0800 OUT at feign.FeignException.errorExecuting(FeignException.java:67) ~[feign-core-9.5.1.jar!/:na]
Code
#FeignClient(name = "myapp", url = "http://dev-myapp.apps.internal:8080")
public interface Client {
Issue resolved. Not an issue with the code. In PCF routing between the micro services were not configured. Once its done, it works

Spring Boot - webservice: Connection Refused

I am trying to implement spring boot webservice application as given in spring docs :
https://spring.io/guides/gs/consuming-web-service/
Build was successful, request and response java files was created and , but when executed spring-boot:run , it gives
Caused by: org.springframework.ws.client.WebServiceIOException: I/O error: Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:561)
at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:390)
at hello.WeatherClient.getCityForecastByZip(WeatherClient.java:30)
at hello.Application.main(Application.java:20)
But the URL is accessible via web browser in eclipse. Kindly help me solve this issue
Make sure all your tests declared with same #SpringBootTest annotation parameters.
I had same issue because of different parameters in two tests. Problem gone when I made all annotations same:
#SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT))
The web Service URL you are trying to call may be not reachable or it gets timeout. Ensure the web Service URL path is correct and is listening. also verify the timeout duration set and the time taken from your request.
PS. Also check if there is some firewall issue at Server side.
For firewall issue, you might need to provide proxy details(proxyHost and proxyPort) In client code.
EDIT:
I am not able to find appropriate blog or something which explains it better. but found one question on stackoverflow which has similar answer : here

Getting com.ibm.wsspi.sib.core.exception.SIConnectionDroppedException in WAS 8.5

Our application uses WAS SIB for JMS implementation and while posting to a queue on WAS 8.5, getting following exception
javax.jms.JMSException: CWSIA0067E: An exception was received during the call to the method JmsMsgProducerImpl.: com.ibm.wsspi.sib.core.exception.SIConnectionDroppedException: CWSIJ0047E: An operation was attempted on a connection that is already closed..
at com.ibm.ws.sib.api.jms.impl.JmsMsgProducerImpl.(JmsMsgProducerImpl.java:456)
at com.ibm.ws.sib.api.jms.impl.JmsQueueSenderImpl.(JmsQueueSenderImpl.java:60)
at com.ibm.ws.sib.api.jms.impl.JmsQueueSessionImpl.instantiateProducer(JmsQueueSessionImpl.java:224)
We face the same issue.
Assumption: You are holding a connection longer than you should. In our case I suspect the persistent messaging as cause. If the underlying DB connection is dropped and you hold the JMS connection longer then this error appears.

WebSockets (wss) and Proxy Server with AsyncHttpClient

I am trying to use AsyncHttpClient with a proxy server configuration to connect using wss and am having no luck. I've been using async-http-client 1.7.5 and grizzly-websockets 2.2.13 My first attempt
AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()
.setSSLContext(sc)
.setProxyServer(
new ProxyServer(Protocol.HTTP, "192.168.1.130", 3128))
.build();
NettyWebSocket w = (NettyWebSocket)c.prepareGet("wss://192.168.1.124/atmosphere-chat/chat")
.execute(handler).get();
using the default netty configuration fails to work, This attempt appears to at least go through the proxy and connect to the remote server. The exception I get there is
java.lang.IllegalArgumentException: unsupported message type: class org.jboss.netty.handler.codec.http.websocketx.TextWebSocketFrame
When I switch to using grizzly through
AsyncHttpClient c = new AsyncHttpClient(new GrizzlyAsyncHttpProvider(config), config);
Things are better/worse. In this instance it appears that grizzly fails to send the connect verb through the http proxy, and instantly starts communicating via ssl, which fails. I would think this would be a well supported situation because of the increased likelyhood that a websocket connection would work through a proxy when using SSL. ]
Exception in thread "main" java.util.concurrent.ExecutionException: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
Am I way outside the bounds of what should be working?
Turns out this was a bug in AHC ( https://github.com/sonatype/async-http-client/issues/131#issuecomment-7745037 ) That gets fixed in 1.8.0.

Resources