我正在为我的 spring-boot 应用程序使用WebClient
和自定义类BodyExtractor
WebClient webLCient = WebClient.create();
webClient.get()
.uri(url, params)
.accept(MediaType.APPLICATION.XML)
.exchange()
.flatMap(response -> {
return response.body(new BodyExtractor());
})
BodyExtractor.java
@Override
public Mono<T> extract(ClientHttpResponse response, BodyExtractor.Context context) {
Flux<DataBuffer> body = response.getBody();
body.map(dataBuffer -> {
try {
JaxBContext jc = JaxBContext.newInstance(SomeClass.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
return (T) unmarshaller.unmarshal(dataBuffer.asInputStream())
} catch(Exception e){
return null;
}
}).next();
}
上面的代码适用于小有效载荷,但不适用于大有效载荷,我认为这是因为我只读取单个通量值next
我不确定如何组合和读取所有dataBuffer
.
我是反应堆的新手,所以我不知道很多关于通量/单声道的技巧。