'Stack over flow Error occurring when an internal API called from spring-boot
A Spring boot web application running in tomcat server suddenly encountered a stack over flow error. The error occurred seems to be due to spring-boot recursively trying to add authentication header to the spring boot to an internal API call
headers.set('Authorization', headerValue);
ResponseEntity<JsonNode> response = null;
AccountView reqData = new AccountView(Account, getAccountState(Account));
HttpEntity<AccountView> request = new HttpEntity<>(reqData, headers);
response = restTemplate.postForEntity(apiUrl + "/v1/fetch/clients", request, JsonNode.class);
LOG
Feb 1 11:44:27 dev-server-1: 2021-02-01 11:44:27,260 INFO
com.sample.service.impl.FetchDataServiceImpl [http-nio-8080-exec-4]
update api start
Feb 1 11:44:27 dev-server-1: 2021-02-01 11:44:27,278 INFO com.sample.service.impl.FetchDataServiceImpl
[http-nio-8080-exec-4] Update client
Feb 1 11:44:27 dev-server-1: 2021-02-01 11:44:27,279 INFO com.sample.service.impl.FetchDataServiceImpl [http-nio-8080-exec-4]
sending an fetch data api to get client details
Feb 1 11:44:27 dev-server-1: 2021-02-01 11:44:27,292 ERROR
org.springframework.boot.web.servlet.support.ErrorPageFilter
[http-nio-8080-exec-4] Forwarding to error page from request
[/api/businessAccount/busi_00000000000048] due to exception [null]
Feb 1 11:44:27 dev-server-1: java.lang.StackOverflowError: null
Feb 1 11:44:27 dev-server-1:
org.springframework.util.LinkedCaseInsensitiveMap.convertKey(LinkedCaseInsensitiveMap.java:283)
Feb 1 11:44:27 dev-server-1: t
org.springframework.util.LinkedCaseInsensitiveMap.containsKey(LinkedCaseInsensitiveMap.java:135)
Feb 1 11:44:27 dev-server-1:
org.springframework.util.CollectionUtils$MultiValueMapAdapter.containsKey(CollectionUtils.java:507)
Feb 1 11:44:27 dev-server-1:
org.springframework.http.HttpHeaders.containsKey(HttpHeaders.java:1535)
Feb 1 11:44:27 dev-server-1: org.springframework.http.client.support.BasicAuthenticationInterceptor.intercept(BasicAuthenticationInterceptor.java:81)
Feb 1 11:44:27 dev-server-1: org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:92)
Feb 1 11:44:27 dev-server-1: org.springframework.http.client.support.BasicAuthenticationInterceptor.intercept(BasicAuthenticationInterceptor.java:84)
Feb 1 11:44:27 dev-server-1: org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:92)
Feb 1 11:44:27 dev-server-1: org.springframework.http.client.support.BasicAuthenticationInterceptor.intercept(BasicAuthenticationInterceptor.java:84)
Feb 1 11:44:27 dev-server-1: org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:92)
Feb 1 11:44:27 dev-server-1: org.springframework.http.client.support.BasicAuthenticationInterceptor.intercept(BasicAuthenticationInterceptor.java:84)
Feb 1 11:44:27 dev-server-1: org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:92)
.......
The AccountView.java file
public class AccountView {
private String parentId;
private String accountName;
private String companyName;
private String state;
public AccountView(Account account, String state) {
this.parentId = account.getClientId();
this.accountName = account.getAccountName();
this.companyName = account.getCompanyName();
this.state = state;
}
public String getParentId() {
return parentId;
}
public String getAccountName() {
return accountName;
}
public String getCompanyName() {
return companyName;
}
public String getState() {
return state;
}
public void setId(String id) {
this.parentId = id;
}
}
The issue reoccurred whenever an internal API was called again from Application. After restarting the application the issue stopped occurring. Can someone please tell me why such an issue occurred and possible solution for this issue.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|