While I'm subscribed to this list I would like to submit this method
for logging forwarded IP addresses when Tomcat is behind a proxy.
Replace the simple request.getRemoteAddr(); call in the invoke method
of AccessLogValve with getClientIp(ServletRequest).
Hope this may be useful. If you need a more formal assignment to
Apache, please let me know.
Best regards,
Phil
/**
* Get a forwarded client IP address if available.
* @param The servlet request object.
* @return The HTTP <code>X-Forwarded-For</code> header value if
present,
* or the default remote address if not.
*/
private final String getClientIp(final ServletRequest request) {
try {
HttpServletRequest httpRequest = (HttpServletRequest) request;
String forwardedIp = httpRequest.getHeader("X-Forwarded-For");
if (forwardedIp != null) {
return forwardedIp;
}
else {
return request.getRemoteAddr();
}
}
catch (ClassCastException cce) {
return request.getRemoteAddr();
}
}
--
http://www.codestyle.org/ Web font statistics and developer FAQs
http://www.metacentric.net/ Automated news feeds for your Web site
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]