Salesforce

How to add interceptors when using Web Service Consumer (ws:consumer)

« Go Back

Information

 
Content
Since the WS Consumer uses CXF, you can specify a CXF configuration file to enable logging capabilities or to add interceptors. To do so, you need to create a cxf.xml file and place it under src/main/resources.

Example cxf.xml file:

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:cxf="http://cxf.apache.org/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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 class="org.apache.cxf.interceptor.LoggingInInterceptor" id="logInbound"/> <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor" id="logOutbound"/> <cxf:bus> <cxf:features> <cxf:logging/> </cxf:features> <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>
The above example shows
1. How to enable the logging using the <cxf:feature>.
2. How to register interceptors (standard or custom).
If you are only interested in enabling the CXF logging capabilities, defining the logging feature will be enough. Just make sure to set the org.apache.cxf package with the appropriate log level in your log4j configuration file.

E.g. for log4j (Mule ESB up to version 3.5):

log4j.logger.org.apache.cxf=INFO

E.g for log4j2 (Mule ESB 3.6+):

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

Please note that this approach is setting the configuration in the CXF level, which will affect all the apps using CXF deployed in the same Mule server.

Please refer to the following documentation page for further information on how to configure CXF.

http://cxf.apache.org/docs/configuration.html

Attachments

Powered by