我必须记录clientresponse的响应,我编写了以下函数:
protected Mono<ClientResponse> logResponse(ContextService ctx,ClientResponse resp, String method){
return resp.bodyToMono(String.class)
.map(responseBody -> {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try {
builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(responseBody)));
NodeList uploadDate = document.getElementsByTagName("uploadDate");
NodeList outcome = document.getElementsByTagName("outcome");
NodeList userPdaId = document.getElementsByTagName("userPdaId");
NodeList errorCode = document.getElementsByTagName("errorCode");
NodeList errorMessage = document.getElementsByTagName("errorMessage");
StringBuilder message = new StringBuilder(" \n");
message.append(uploadDate.item(0).getTextContent() + " \n");
message.append(outcome.item(0).getTextContent()+ " \n");
message.append(userPdaId.item(0).getTextContent()+ " \n");
message.append(errorCode.item(0).getTextContent()+ " \n");
message.append(errorMessage.item(0).getTextContent()+ " \n");
logService.logInfo(ctx,applicationName,getClass().getSimpleName()+ ":" + method,null,message.toString(),null,null);
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return resp;
});
}
我在得到响应后调用函数:
bucketService.uploadDocumentAsync(Mono.just(doc))
.flatMap(clientResponse -> logResponse(ctx,clientResponse,"uploadSync"))
.flatMap(resp -> {
if (resp.statusCode().equals(HttpStatus.BAD_REQUEST)){
return manageNotStructuredResponse(resp);
}else {
return ServerResponse
.status(resp.statusCode())
.headers(fromClientResponse(resp))
.body(BodyInserters.fromDataBuffers(resp.bodyToFlux(DataBuffer.class)));
}
}
)
).switchIfEmpty(ServerResponse.badRequest().build())
问题是,我被困在我的功能,我从来没有离开过它(在 Postman ,我对stasys,我从来没有得到回应)。有人能帮我吗?我认为身体内部的Map是问题所在,但我不知道如何提取响应。我不能使用subscribe(),因为有另一个活动的,不能使用block()。
如您所见,在我的日志之后,clientresponse将生成一个serverresponse。也许我可以从服务器响应中提取响应体?接受任何建议
暂无答案!
目前还没有任何答案,快来回答吧!