Код: Выделить всё
WebClient webLCient = WebClient.create();
webClient.get()
.uri(url, params)
.accept(MediaType.APPLICATION.XML)
.exchange()
.flatMap(response -> {
return response.body(new BodyExtractor());
})
Код: Выделить всё
@Override
public Mono extract(ClientHttpResponse response, BodyExtractor.Context context) {
Flux 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();
}
Я новичок в реакторе, поэтому не знаю многих трюков с потоком/ моно.
Подробнее здесь: https://stackoverflow.com/questions/464 ... nputstream