Capture Reqest and Response in Tomcat7

Install Logback

Download the logback distribution and  place the files logback-core-1.1.3.jar and logback-access-1.1.3.jar under $TOMCAT_HOME/lib/ directory.

Add LogbackValve

Add the below line in <Host/> tag of $TOMCAT_HOME/conf/server.xml

<Valve className="ch.qos.logback.access.tomcat.LogbackValve"/>

Add LogbackConfiguration File

Add logback-access.xml file in $TOMCAT_HOME/conf folder withr below content

<configuration>
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
 <encoder> 
 <pattern>%fullRequest%n%n%fullResponse</pattern>
 </encoder>
 </appender>
 
 <appender-ref ref="STDOUT" />

</configuration>

Add TeeFilter

Add the below filter in $TOMCAT_HOME/conf/web.xml

<filter>
  <filter-name>TeeFilter</filter-name>
  <filter-class>ch.qos.logback.access.servlet.TeeFilter</filter-class>
</filter>

<filter-mapping>
  <filter-name>TeeFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

Start tomcat in Shell

$TOMCAT_HOME/bin/catalina.sh run

Reference

http://logback.qos.ch/access.html

You can use Advanced rest client to send request to server.


Advertisements

2 thoughts on “Capture Reqest and Response in Tomcat7

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s