我在春季启动中创建了一个SOAP客户端,并且正在记录所有SOAP消息,但是新版本的LoggingFeature(org.apache.cxf.ext.logging.LoggingFeature)在一行上显示了有效负载使用 prettyLogging 和不推荐使用的此类(org.apache.cxf.feature.LoggingFeature)版本在使用 prettyLogging 时会格式化有效负载。
当使用过时的类的版本-我想要的格式(随机示例):
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Envelope xmlns="URL" xmlns:ns2="URL">
<Service ID="SERVICE"/>
<Inquirer ID="ID" CorrelationID="ID" Version="1.0" Timestamp="Timestamp"/>
<Data Content="xml">
<ns2:Request>
<ns2:FILE>ID</ns2:FILE>
<ns2:ACTION>ACTION</ns2:ACTION>
</ns2:Request>
</Data>
<File>
<FileDescription ID="ID"/>
</File>
</Envelope>
</soap:Body>
</soap:Envelope>
使用新版本时:
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><Envelope xmlns="URL" xmlns:ns2="URL"><Service ID="SERVICE"/><Inquirer ID="ID" CorrelationID="ID" Version="1.0" Timestamp="Timestamp"/><Data Content="xml"><ns2:Request><ns2:FILE>ID</ns2:FILE> <ns2:ACTION>ACTION</ns2:ACTION></ns2:Request></Data><File><FileDescription ID="ID"/></File></Envelope></soap:Body></soap:Envelope>
我的配置类:
import javax.annotation.PostConstruct;
import org.apache.cxf.ext.logging.AbstractLoggingInterceptor;
import org.apache.cxf.ext.logging.LoggingFeature;
import org.apache.cxf.ext.logging.LoggingInInterceptor;
import org.apache.cxf.ext.logging.LoggingOutInterceptor;
import org.apache.cxf.bus.spring.SpringBus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class CxfConfig {
@Autowired
private SpringBus springBus;
@PostConstruct
public void activateLoggingFeature() {
springBus.getInInterceptors().add(logInInterceptor());
springBus.getInFaultInterceptors().add(logInInterceptor());
springBus.getOutInterceptors().add(logOutInterceptor());
springBus.getOutFaultInterceptors().add(logOutInterceptor());
}
@Bean
public LoggingFeature loggingFeature() {
LoggingFeature logFeature = new LoggingFeature();
logFeature.setPrettyLogging(true);
logFeature.initialize(springBus);
springBus.getFeatures().add(logFeature);
return logFeature;
}
public AbstractLoggingInterceptor logInInterceptor() {
LoggingInInterceptor logInInterceptor = new LoggingInInterceptor();
logInInterceptor.setLimit(-1);
logInInterceptor.setPrettyLogging(true);
logInInterceptor.setLogBinary(true);
logInInterceptor.setLogMultipart(true);
return logInInterceptor;
}
public AbstractLoggingInterceptor logOutInterceptor() {
LoggingOutInterceptor logOutInterceptor = new LoggingOutInterceptor();
logOutInterceptor.setPrettyLogging(true);
logOutInterceptor.setLimit(-1);
logOutInterceptor.setLogBinary(true);
logOutInterceptor.setLogMultipart(true);
return logOutInterceptor;
}
}