I have updated the Spring boot version from 2.7.14 to 3.2.4 in existing application. Rest everything remains same, but it is giving 415 unsupported media type.
I have spend days on this, but do not have any clue about it.
RestTemplate Configs –
@Configuartion
public class RestTemplateConfiguration {
@Bean
public RestTemplate restTemplate(RestTemplateFactory resTemplateFactory) {
RestTemplate resTemplate = resTemplateFactory.restTemplate();
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setOutputStreaming(false);
ClientRequestFactory factory = new BufferingClientHttpRequestFactory(requestFactory);
restTemplate.setRequestFactory(factory);
restTemplate.getInterceptors().add(new AddResponseBodyWrapperInterceptor());
return resTemplate;
}
}
Calling class –
@Service
@RequiredArgsConstructor
public class ExternalApiService {
private final RestTemplae restTemplate;
public ResponseEntity<JsonNode> exchange(URI uri, HttpMethod method, HttpEntity<JsonNode> httpEntity) {
try {
ResponseEntity<JsonNode> response = restTemplate.exchange(uri, method, httpEntity, JsonNode.class);
return ResponseEntity.status(response.getStatusCode())
.headers(//code here)
.body(response.getBody());
} catch (HttpStatusCodeException ex) {
// exception handling
}
}
}
I have tried adding logging in the interceptor. Both before and after updating the spring boot version have same request headers and payload.
accept: "application/json, text/plain, application/xml, application/*+json, application/*+xml, */*",
accep-encoding: "gzip, x-gzip, deflat",
content-length: "0",
host: "localhost:9060",
connection: "keep-alive",
user-agent: "Apache-HttpClient/5.2.3 (Java/17.0.10)"
The exact same code work with Spring boot 2.7.14, but fails with 3.2.4.
Any suggestion would be appreciated. Thanks in advance.