I am getting a Connection refused exception when two spring boot embedded tomcat servers are trying to communicate via localhost (127.0.0.1) on different ports.
# spring boot
Prox PreserveHost On
RequestHeader set X-Forwarded-Proto https
RequestHeader set X-Forwarded-Port 443
ProxyPass / http://127.0.0.1:9201/
ProxyPassReverse / http://127.0.0.1:9201/
server.port=9200
server.port=9201
server.use-forward-headers=true
...
core.service.baseUrl=http://127.0.0.1:9200
core.service.protocol=http
core.service.ip=127.0.0.1
core.service.portNumber=9200
Caused by: org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://127.0.0.1:9200/api/v1/doSomething": Connect to 127.0.0.1:9200 [/127.0.0.1] failed: Connection refused (Connection refused); nested exception is org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:9200 [/127.0.0.1] failed: Connection refused (Connection refused)
at
org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:666) ~[spring-web-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at
org.springframework.web.client.RestTemplate.execute(RestTemplate.java:613) ~[spring-web-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:287) ~[spring-web-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
@Component
public class RestTemplateFactory implements FactoryBean<RestTemplate>, InitializingBean {
@Value("${core.service.username}")
private String username;
@Value("${core.service.password}")
private String password;
@Value("${core.service.ip}")
private String ipAddress;
@Value("${core.service.portNumber}")
private Integer portNumber;
@Value("${core.service.protocol}")
private String protocol;
private RestTemplate restTemplate;
public RestTemplate getObject() {
restTemplate.getInterceptors().add(new BasicAuthorizationInterceptor(username, password));
return restTemplate;
}
public Class<RestTemplate> getObjectType() {
return RestTemplate.class;
}
public boolean isSingleton() {
return true;
}
public void afterPropertiesSet() {
HttpHost host = new HttpHost(ipAddress, portNumber, protocol);
restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactoryBasicAuth(host));
}
}
I've been troubleshooting this for over a day now and not making a lot of headway. Any ideas would be welcome.
I should point out this works as expected on my local machine. The issues occur when trying to deploy onto the public server.
THANKS!