You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Calling the method org.springframework.http.client.ClientHttpResponse.getStatusCode() should work fine.
Actual Behavior
Calling the method org.springframework.http.client.ClientHttpResponse.getStatusCode() raises this error:
java.lang.AbstractMethodError: org.zalando.logbook.spring.BufferingClientHttpResponseWrapper.getStatusCode()Lorg/springframework/http/HttpStatus;
at eu.tasgroup.gpp.albo.credem.client.RestTemplateResponseErrorHandler.hasError(RestTemplateResponseErrorHandler.java:23) ~[classes/:na]
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:813) ~[spring-web-5.3.26.jar:5.3.26]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:783) ~[spring-web-5.3.26.jar:5.3.26]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:717) ~[spring-web-5.3.26.jar:5.3.26]
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:608) ~[spring-web-5.3.26.jar:5.3.26]
Steps to Reproduce
Register the LogbookClientHttpRequestInterceptor :
@Configuration
public class SpringArchetypeConfiguration {
/**
* Creates the RestTemplate Bean to be injected and used in the application.
*
* @param restTemplateBuilder
* @return
*/
@Bean
public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder,LogbookClientHttpRequestInterceptor logbookInterceptor) {
RestTemplate template = restTemplateBuilder
.additionalInterceptors(logbookInterceptor)
.build();
template.setErrorHandler(new RestTemplateResponseErrorHandler());
return template;
}
}
Register an org.springframework.web.client.ResponseErrorHandler bean:
@Component
public class RestTemplateResponseErrorHandler implements ResponseErrorHandler {
@Override
public boolean hasError(ClientHttpResponse httpResponse) throws IOException {
return httpResponse.getStatusCode() != HttpStatus.OK;
}
@Override
public void handleError(ClientHttpResponse httpResponse) throws IOException {
....
}
}
Send a Request
Error happens when the statement httpResponse.getStatusCode() in the method hasError is called
Context
The workaround is replacing the hasError method with this code:
But I'm worried because this error could happens elsewhere in the application code, for example if the getStatusCode() method is called by an exetranal library or Spring framework code.
Your Environment
Spring Boot 2.7.17
LogBook 3.8.0
The text was updated successfully, but these errors were encountered:
Description
Registering LogbookClientHttpRequestInterceptor to Spring RestTemplate, causes an error when the application code tries to call the method:
org.springframework.http.client.ClientHttpResponse.getStatusCode()
because the return type is changed in SpringBoot 6. In fact, in Spring Boot 5 this method returns:
org.springframework.http.HttpStatus
but in Spring Boot 6 it returns:
org.springframework.http.HttpStatusCode
This issue is related to: #1580
Expected Behavior
Calling the method org.springframework.http.client.ClientHttpResponse.getStatusCode() should work fine.
Actual Behavior
Calling the method org.springframework.http.client.ClientHttpResponse.getStatusCode() raises this error:
Steps to Reproduce
Context
The workaround is replacing the hasError method with this code:
But I'm worried because this error could happens elsewhere in the application code, for example if the getStatusCode() method is called by an exetranal library or Spring framework code.
Your Environment
Spring Boot 2.7.17
LogBook 3.8.0
The text was updated successfully, but these errors were encountered: