gpt4 book ai didi

java - 禁用 SOAP 服务日志跟踪中的打印凭据

转载 作者:行者123 更新时间:2023-11-30 06:41:22 25 4
gpt4 key购买 nike

SOAP 服务由 SpringBoot 应用程序使用,并且应用程序正在 *.log 文件中记录详细信息。SOAP 请求在 xml 中包含请求的用户名和密码,如何禁用在日志文件中打印的凭据。应用程序使用 logback-spring.xml 进行日志记录配置。我想要日志中的 SOAP 请求 xml,但不需要用户名和密码。

在 *.log 中包含用户名和密码的 SOAP 请求

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<wsse:Security soap:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-sometokenvalue">
<wsse:Username>Username</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
<soap:Body>
<ns2:GetRequest xmlns="http://serviceapi.userwebsite.com/common/v1/serviceHeader" xmlns:ns2="http://serviceapi.userwebsite.com/service/v1" >
<RequestHeader>
<ServiceVersion>0.0.0</ServiceVersion>
<UserID>userID</UserID>
</RequestHeader>
<ns2:UserInfo StartAt="">
<ns2:ID>P/O</ns2:ID>
</ns2:UserInfo>
</ns2:GetRequest>
</soap:Body>
</soap:Envelope>

logback-spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />

<springProperty name="logsPath" source="app.logs.path" />

<springProfile name="test,dev">

<appender name="dailyRollingFileAppender"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${logsPath}UserApp%d{MMddyyyy}.log
</FileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>

<encoder>
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{35}-%msg %n</Pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="dailyRollingFileAppender" />
</root>
</springProfile>

Gradle 依赖项:

apply plugin: "no.nils.wsdl2java"

wsdl2javaExt {
cxfVersion = "3.1.7"
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-batch")
compile("org.springframework.boot:spring-boot-starter-mail")
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.5'
compile group: 'org.apache.cxf', name: 'cxf-spring-boot-starter-jaxws', version: '3.1.10'
compile group: 'org.apache.cxf', name: 'cxf-rt-ws-security', version: '3.1.10'
testCompile('org.springframework.boot:spring-boot-starter-test')
}

最佳答案

您可以实现自定义 SOAPHandler 来访问 SoapMessage 并根据需要转换输出日志消息。

@Override
public boolean handleMessage(SOAPMessageContext arg0) {
SOAPMessage message = arg0.getMessage();
boolean isOutboundMessage = (Boolean) arg0.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (isOutboundMessage) {
System.out.println("OUTBOUND MESSAGE");
} else {
System.out.println("INBOUND MESSAGE");
}
try {
Source source = message.getSOAPPart().getContent();

Transformer transformer = TransformerFactory.newInstance().newTransformer();

transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

transformer.transform(source, new StreamResult(System.out));
} catch (Exception e) {
e.printStackTrace();
}
return true;
}

参见here

关于java - 禁用 SOAP 服务日志跟踪中的打印凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44324376/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com