我正在从spring应用程序中调用外部服务,这是我的代码
return webClient.get()
.uri(builder ->
buildURI(builder))
.accept(MediaType.APPLICATION_JSON)
.headers(httpHeaders ->
buildHeaders(httpHeaders))
.retrieve()
.onStatus(httpStatus -> httpStatus.series().value()== HttpStatus.UNAUTHORIZED.value(),
clientResponse ->
throwError(clientResponse))
.bodyToMono(
A.class);
外部路径返回200,并返回一个json响应。一切正常。 但是在特定情况下,对于无效的凭证,外部服务将返回401并返回一个具有application / xml; chatset = UTF-8的响应。
我的代码由于以下异常而失败 org.springframework.web.reactive.function.UnsupportedMediaTypeException:内容类型'application / xml; charset = UTF-8'不支持
我无法控制外部服务。如何在我的应用程序中处理此问题?