Hi have 2springboot applications running on ports 8085 and 8084. When I try to use RestTemplate to try to connect from one service to another, I get a BadGateway 502 exception.

Below is the stacktrace

head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.17.9</center>
</body>
</html>
]] with root cause

org.springframework.web.client.HttpServerErrorException$BadGateway: 502 Bad Gateway: [<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.17.9</center>
</body>
</html>
]
    at org.springframework.web.client.HttpServerErrorException.create(HttpServerErrorException.java:108) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:186) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:125) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:782) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:740) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:674) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:612) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]

Any reason why I might be getting this.

Below is the method call to the service

   ResponseEntity<List<String>> quoteResponse = restTemplate.exchange("http://localhost:8085/rest/db" + userName, HttpMethod.GET,
                null,
                new ParameterizedTypeReference<List<String>>() {
                });

Looks like there is no route between my local port 8084 and 8085. When I use 8082 or 8081, I do not get the same error

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.