我使用apache cxf编写了一个示例soap服务项目,并在此应用程序中使用log4j进行日志记录。我可以将soap原始请求和响应记录到服务器控制台,但我无法将其记录到日志文件或stingBuilder。和我的 像这样的cxf-beans.xml
**
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:cxf="http://cxf.apache.org/core"
xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint xmlns:tns="http://source.sprint.com/"
id="accountinfoservice" implementor="com.sprint.source.AccountInfoServiceImpl"
wsdlLocation="wsdl/accountinfoserviceimpl.wsdl" endpointName="tns:AccountInfoServiceImplPort"
serviceName="tns:AccountInfoServiceImplService" address="/AccountInfoServiceImplPort">
<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxws:features>
</jaxws:endpoint>
</beans>**
客户端类
AccountInfoServiceImplService service= new AccountInfoServiceImplService();
com.sprint.stubs.AccountInfoService op=service.getAccountInfoServiceImplPort();
//System.out.println(op.getAccountInfo("123").getSuspendInd());
logger.info("hello");
Client client = ClientProxy.getClient(op);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
logger.info("response "+client.getInInterceptors().add(new LoggingInInterceptor()));
logger.info("request "+client.getInInterceptors().add(new LoggingInInterceptor()));
System.out.println(op.getAccountInfo("123").getFirstName());
logger.info(“request”+ client.getInInterceptors()。add(new LoggingInInterceptor()));这种代码的和平在日志记录文件中记录为true。如果我使用此配置文件并使用客户端java类,我可以将原始请求和响应记录到控制台,但我无法创建日志文件,然后我搜索.. 我像这样更改了配置文件
<bean id="abstractLoggingInterceptor" class="org.apache.cxf.interceptor.AbstractLoggingInterceptor" abstract="true" />
<bean id="loggingInInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor" parent="abstractLoggingInterceptor" />
<bean id="loggingOutInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor" parent="abstractLoggingInterceptor" />
<cxf:bus>
<cxf:inInterceptors>
<ref bean="loggingInInterceptor" />
</cxf:inInterceptors>
<cxf:outInterceptors>
<ref bean="loggingOutInterceptor" />
</cxf:outInterceptors>
<cxf:outFaultInterceptors>
<ref bean="loggingOutInterceptor" />
</cxf:outFaultInterceptors>
<cxf:inFaultInterceptors>
<ref bean="loggingInInterceptor" />
</cxf:inFaultInterceptors>
</cxf:bus>
<jaxws:endpoint xmlns:tns="http://source.sprint.com/"
id="accountinfoservice" implementor="com.sprint.source.AccountInfoServiceImpl"
wsdlLocation="wsdl/accountinfoserviceimpl.wsdl" endpointName="tns:AccountInfoServiceImplPort"
serviceName="tns:AccountInfoServiceImplService" address="/AccountInfoServiceImplPort">
<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxws:features>
</jaxws:endpoint>
</beans>
更改配置文件后,我得到"org.apache.cxf.interceptor.Fault: Could not send Message. at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:64)"
我通过网络搜索这个解决方案,但我无法做到?任何人都可以帮助我摆脱这个
答案 0 :(得分:0)
在dependecies中使用org.slf4j:slf4j-log4j12而不是log4j:log4j,检查log4j.xml中的logger级别:
<logger name="org.apache.cxf">
<level value="info"/>
</logger>