【发布时间】:2021-02-07 01:26:25
【问题描述】:
作为安全要求的一部分,我需要在使用 log4j 记录 XML SOAP 请求负载时屏蔽敏感字段值,例如信用卡号等。 目前我正在使用以下代码来记录 XML 请求负载:
public void printDebugXMLPayload(MyWSRequest request) throws JAXBException
{
StringWriter sw = new StringWriter();
JAXBContext jaxbContext = JAXBContext.newInstance(MyWSRequest .class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(request, new StreamResult(sw));
logger.debug(sw.toString());
}
上面的代码记录了完整的 XML 请求负载,但我需要屏蔽敏感字段。 能否请您指导。非常感谢! 注意:我在 @XmlElement 级别找不到任何配置来屏蔽字段
【问题讨论】: