Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SpringSOAPWebService在日志中屏蔽XML请求有效负载的元素_Java_Xml_Spring_Soap_Jaxb - Fatal编程技术网

Java SpringSOAPWebService在日志中屏蔽XML请求有效负载的元素

Java SpringSOAPWebService在日志中屏蔽XML请求有效负载的元素,java,xml,spring,soap,jaxb,Java,Xml,Spring,Soap,Jaxb,作为安全需求的一部分,我需要在使用log4j记录XML SOAP请求负载时屏蔽敏感字段值,如creditcard number等。 目前,我正在使用以下代码记录XML请求负载: public void printDebugXMLPayload(MyWSRequest request) throws JAXBException { StringWriter sw = new StringWriter(); JAXBContext jaxbContext = JAXBContext

作为安全需求的一部分,我需要在使用log4j记录XML SOAP请求负载时屏蔽敏感字段值,如creditcard number等。 目前,我正在使用以下代码记录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请求负载,但我需要屏蔽敏感字段。 请你给我引路好吗。非常感谢!
注意:我找不到@xmlement级别的任何配置来屏蔽字段

一种方法是创建自定义注释并使用反射类查看是否需要屏蔽字段。 这是一个简单的例子

@Retention(RetentionPolicy.RUNTIME)
public @interface Mask {
}

谢谢,请告诉我们jaxb中是否有使用xmlelement屏蔽字段的方法
public class MyWSRequest {
    @Mask
    private String item1;
}
public void printDebugXMLPayload(MyWSRequest request) throws JAXBException {
    for (Field f : request.getClass().getDeclaredFields()) {
        if (f.isAnnotationPresent(Mask.class)) {
            logger.debug("***");
        } else {
            f.setAccessible(true);
            logger.debug(f.get(request));
        }
    } 
}