The Solutions:
Solution 1: Predicate Type mismatch
In the provided code, the `onStatus` method expects a `Predicate
// send getMap WMS to geoserver
public Mono<byte[]> getMap(String requestURL) {
return geoserverWebClient
.get()
.uri(requestURL)
.retrieve()
.onStatus(HttpStatusCode::is4xxClientError,
error -> Mono.error(new RuntimeException("API not found")))
.bodyToMono(byte[].class);
}
Q&A
Why did the Java Code have an error message “The method onStatus(Predicate
The type parameter in the Predicate (first argument to onStatus(...)
) is not of type org.springframework.http.HttpStatus
, but of type org.springframework.http.HttpStatusCode
(which happens to be an interface that the HttpStatus
enum implements).
How to fix Spring Webclient error message: “The method onStatus(Predicate
Switch the method reference from HttpStatus::is4xxClientError
to HttpStatusCode::is4xxClientError