我有用于发送和接收SOAP的Spring WebService。这是Impl类的示例:
@Override
@LoggingRequest(serviceName = "test")
public String getReport(String url, GetReport getReport, CigWsHeader cigWsHeader) {
AtomicReference<String> responseStr = new AtomicReference<>();
webServiceTemplateMbki.sendAndReceive(url,
(request) -> {
SoapMessage soapMessage = (SoapMessage) request;
soapMessage.setSoapAction("http://test");
addAuthHeader(cigWsHeader, soapMessage);
String body = toXmlString(objectFactory.createGetReport(getReport));
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(new StringSource(body), request.getPayloadResult());
SoapEnvelope envelope = soapMessage.getEnvelope();
envelope.addNamespaceDeclaration("ws", "http://test/");
}, (response) -> {
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.writeTo(out);
String s = new String(out.toByteArray());
responseStr.set(s);
});
return handleGetReportResponse(responseStr.get());
}
我还具有要登录此服务的Aspect:
@Around("@annotation(com.datastech.cra.aop.annotation.LoggingRequest)")
public Object loggingRequestToExternalServices(ProceedingJoinPoint pjp) throws Throwable {
log.info("Logging external service");
MethodSignature signature = (MethodSignature) pjp.getSignature();
Method method = signature.getMethod();
ElasticLogDTO elasticLogDTO = new ElasticLogDTO();
elasticLogDTO.setTimeStamp(new Date());
elasticLogDTO.setMetricValue(System.nanoTime());
elasticLogDTO.setType(Type.BUSINESS.name());
elasticLogDTO.setLevel(Level.INFO.name());
elasticLogDTO.setModule(Module.CLIENT.name());
}
我找到了ClientInterceptor,但不知道如何将其与AOP连接。 如何记录AOP请求和SOAP服务的响应?