I have a service rest and I want to do a POST to a URL. When I check with POSTMAN this url works.
With POSTMAN, the request is
{
"username": "RenfeInbound",
"password": "renfeinbound"
}
This is my spring service rest
@Override
public RespuestaTransfesaBean peticionLogin(PeticionLoginTransfesa datosLogin) {
RespuestaTransfesaBean res = null;
try {
RestTemplate restTemplate = new RestTemplate();
HttpEntity<PeticionLoginTransfesa> request = new HttpEntity<>(datosLogin, getHttpHeaders());
res = restTemplate.postForObject(TRANSFESA_URL, request, RespuestaTransfesaBean.class);
TRANSFESA_URL is the URL where I want to do the request.
datosLogin are the request values
Method getHttpHeaders() is
private HttpHeaders getHttpHeaders() {
if (headers == null) {
headers = new HttpHeaders();
// headers.add("username", TRANSFESA_USER);
// headers.add("password", TRANSFESA_PASS);
headers.add("Content-Type", "application/json");
}
return headers;
}
When I execute the request, I get the following error on the console
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://cloud-uat.transfesa.com/renfe-int-api/login": Connection timed out: connect; nested exception is java.net.ConnectException: Connection timed out: connect
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:743)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:669)
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:413)
at com.renfe.bcm.externas.transfesa.service.TransfesaServiceImpl.peticionLogin(TransfesaServiceImpl.java:35)
at com.renfe.bcm.externas.transfesa.restcontroller.TransfesaRestController.loginTransfesa(TransfesaRestController.java:23)
at com.renfe.bcm.externas.transfesa.restcontroller.TransfesaRestController$$FastClassBySpringCGLIB$$9aa75999.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)