CXF:无法记录soap消息

时间:2012-10-26 22:18:55

标签: logging soap cxf config

在标准的eclipse java项目中,cxf.xml配置文件的正确位置在哪里?我正在尝试在独立的jar格式客户端和消费者上启用soap消息。使用wsdltojava实用程序生成工件并使用自动生成的起始点测试客户端,它工作得非常好。 我根据文档创建了配置文件但在我的consolle中我没有看到任何事情。 这是我的cxf.xml文件内容:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:cxf="http://cxf.apache.org/core"
      xsi:schemaLocation=" 
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<bean id="abstractLoggingInterceptor" abstract="true">
    <property name="prettyLogging" value="true"/>
</bean>
<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>  

</beans>

我试着把它放在项目根目录下,但是在src下却没有。我错过了什么?

我的客户端代码如下:

公共决赛班ClientMHttps {

private static final QName SERVICE_NAME = new       QName("http://thecompany/service-b", "myendpoint-v1");

private  myendpointPortType port ;

public ClientMHttps() throws java.lang.Exception {
    URL wsdlURL = myendpointV1.WSDL_LOCATION;

    myendpointV1 ss = new myendpointV1(wsdlURL, SERVICE_NAME);
    port = ss.getmyendpointPortTypeEndpointHttpsM(); 




}

    public DeleteMarkedStatusResponse do_DeleteMarkedStatus(DeleteMarkedStatusRequest  _deleteMarkedStatus_body) throws java.lang.Exception
    {
    System.out.println("Invoking deleteMarkedStatus...");
    javax.xml.ws.Holder<HeaderType> _header =  this.HeaderFarm();
    DeleteMarkedStatusResponse _deleteMarkedStatus__return = port.deleteMarkedStatus(_deleteMarkedStatus_body, _header);
    System.out.println("deleteMarkedStatus.result=" + _deleteMarkedStatus__return);
    return _deleteMarkedStatus__return;


    }

3 个答案:

答案 0 :(得分:0)

我相信只需要修复bean名称和cxf.xml位置。

在src / main / resources / cxf.xml中,您可以使用这样的cxf.xml文件来记录所有CXF消息:

<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:cxf="http://cxf.apache.org/core"
      xsi:schemaLocation="
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

    <bean id="logInbound" class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
    <bean id="logOutbound" class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>

    <cxf:bus>
        <cxf:inInterceptors>
            <ref bean="logInbound"/>
        </cxf:inInterceptors>
        <cxf:outInterceptors>
            <ref bean="logOutbound"/>
        </cxf:outInterceptors>
        <cxf:outFaultInterceptors>
            <ref bean="logOutbound"/>
        </cxf:outFaultInterceptors>
        <cxf:inFaultInterceptors>
            <ref bean="logInbound"/>
        </cxf:inFaultInterceptors>
    </cxf:bus> 
</beans>

答案 1 :(得分:0)

应将<jaxws:client>元素添加到将创建CXF Web服务客户端的Spring配置文件(cxf.xml)中。然后,您需要在代码中使用此客户端bean来调用Web服务。

根据您要使用的日志记录框架,您可能需要按照here所述配置META-INF/cxf/org.apache.cxf.Logger

我创建了博客文章,详细解释了如何为log4jlogbacklog4j2配置CXF。

请注意,您还可以使用更简洁的CXF日志记录功能。

答案 2 :(得分:0)

尝试为&#39; org.apache.cxf.services&#39;添加过滤器。

<logger level="INFO" name="org.apache.cxf.services"/>

不会为实现服务类的包生成日志记录,而是在自定义位置生成日志。