/**
 * @author bbehling
 *
 * THE SAMPLE CODE AND OTHER INFORMATION PROVIDED IN THIS WHITE PAPER ARE EACH PROVIDED WITH NO WARRANTIES
 * OR SUPPORT WHATSOEVER, AND BMC, ITS AFFILIATES AND LICENSORS DISCLAIM ALL WARRANTIES, INCLUDING,
 * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
 * AND NON-INFRINGEMENT, AND ALL RESPONSIBILITY FOR SUPPORT AND/OR MAINTENANCE.
 * BMC DOES NOT WARRANT THAT THE OPERATION OF THE SAMPLE CODE WILL BE UNINTERRUPTED OR ERROR FREE.
 *
 */

This DebugServletFilter allows for the modification of HTTP requests and responses from the web application.

The current functionality of this Filter can add a 'RESPONSEHOSTIP' or 'JVMID' response header to every response issued by the web application. 
This header will provide the IP address of the actual host (RESPONSEHOSTIP) or unique JVMID that issued the response. 
This information is useful for troubleshooting load balancing issues with multiple web application servers or nodes (in a cluster). 

This Filter is not web application specific and can be added to any web application, such as Mid-Tier, SmartIT, etc. 
 
To install it and use is simple:

1)	Stop the web application engine (Tomcat, for example)
2)	Copy the 'DebugServletFilter.jar' into your web app's /WEB-INF/lib directory
3)	Rename the original 'web.xml' file (in /WEB-INF) to 'web.xml.bak' (for example) 
4)	Add the following <filter> and <filter-mapping> elements to your web.xml file (place it among the other <filter> elements), and start the web application engine

	<filter>
	  	<filter-name>DebugServletFilter</filter-name>
	  	<filter-class>com.bmc.support.util.filter.DebugServletFilter</filter-class>
	  	<init-param>
	    		<param-name>addresponsehostip</param-name>
	    		<param-value>true</param-value> <!-- *** Set this to 'false' to disable *** -->
	  	</init-param>
	  	<init-param>
	    		<param-name>jvmid</param-name>
	    		<param-value>jvm_1</param-value> <!-- *** Set this to a unique value for each Mid-Tier instance *** -->
	  	</init-param>	  	
	</filter>
    	<filter-mapping>
        	<filter-name>DebugServletFilter</filter-name>
        	<url-pattern>/*</url-pattern>
    	</filter-mapping>		

There will now be a 'RESPONSEHOSTIP' and 'JVMID' header on all responses from the web application server, for example:

RESPONSEHOSTIP: 123.45.67.890
JVMID: jvm_1

(NOTE: Use a unique "jvmid" for each instance of web applicaiton server (physical or clustered), for example: jvm_1, jmv_2, jvm_3)

(NOTE: You can use Fiddler (https://www.telerik.com/download/fiddler) to view these new HTTP headers)

To disable the filter, you can simply remove the 'DebugServletFilter.jar' and/or revert back to your backup copy of 'web.xml'. 
Or, you can remove the RESPONSEHOSTIP header by setting it's <param-value> to false (restart of web application server required)
