Pawan
Pawan

Reputation: 32331

How to make CXF SOAP Request to be printed under log file

@InInterceptors(interceptors = "org.apache.cxf.interceptor.LoggingInInterceptor"  )
@OutInterceptors(interceptors = "org.apache.cxf.interceptor.LoggingOutInterceptor")

public class SKTWeb implements SKTWebService {

// method logic goes here 

}

Hi , after adding these two lines inside the CXF Method Implementation . I could get whip of SOAP Requestand Response under tomcat server console

see a instance of SOAP Request Printed under Tomcat console

INFO: Inbound Message
----------------------------
ID: 1
Address: /Sktweb-33.0/services/SKTWeb
Encoding: UTF-8
Content-Type: text/xml; charset=UTF-8
Headers: {cache-control=[no-cache], content-type=[text/xml; charset=UTF-8], connection=[keep-alive], host=[local
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns4:strategy xmlns:ns

Could anybody please tell me how can get this inside my Log file (Log4j)

Currently this is my log4j.properties file

log4j.rootCategory=INFO, A1

# A1 is a DailyRollingFileAppender

log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A1.file=/Haieeee.log
log4j.appender.A1.datePattern='.'yyyy-MM-dd
log4j.appender.A1.append=true
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-22d{dd/MMM/yyyy HH:mm:ss} - %m%n

And also i have META-INF\cxf\org\apache\cxf\Logger Log4jLogger.class inside the Web Application . And also i kept

<cxf:bus>
<cxf:features>
<cxf:logging/>
</cxf:features>
</cxf:bus> 

Inside the endpoints.xml file

Any help please

Upvotes: 0

Views: 6054

Answers (3)

sskumar86
sskumar86

Reputation: 161

Always go with interceptors...Add slf4j-log4j12-1.6.1.jar,slf4j-api-1.6.1.jar and commons-logging-1.1.1.jar. Paste the following code in your cxf.xml...

<bean class="org.apache.cxf.interceptor.LoggingInInterceptor" id="loggingInInterceptor" />
    <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor" id="logOutInterceptor" />
    <cxf:bus>
        <cxf:inInterceptors>
            <ref bean="loggingInInterceptor" />
        </cxf:inInterceptors>
        <cxf:outInterceptors>
            <ref bean="logOutInterceptor" />
        </cxf:outInterceptors>
    </cxf:bus>

Upvotes: 0

Donal Fellows
Donal Fellows

Reputation: 137777

A slight bit of confusion it seems. You need your assembled application to have a locatable file META-INF/cxf/org.apache.cxf.Logger (yes, those are dots! It's not a .java or .class file) and it should have the contents:

org.apache.cxf.common.logging.Log4jLogger

I use exactly the above in my code and it works like a charm. (I don't use it with the message logging feature though; too much traffic when deployed for my taste…)

Upvotes: 2

Ganesh
Ganesh

Reputation: 1654

Basically you want your properties file to be picked by CXF then it use this properties file instead of CXF's. I am using spring configuration in my CXF application. If you are not using any Spring config then you create a new config and load it on start up using spring context listener, then you can add the below code in your XML file.

<bean id="log4jInitialization"
        class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetClass" value="org.springframework.util.Log4jConfigurer" />
        <property name="targetMethod" value="initLogging" />
        <property name="arguments">
            <list>
                <value>file:fullpath/filename.properties</value>
            </list>
        </property>
    </bean>

You can also have classpath:filename.properties in the <list> </list>. The logging implemented in Spring framework will be used to log all the request and response. You can also use the same logging implementation to use in your application.

Upvotes: 0

Related Questions