CopyDisable

Monday 15 August 2011

Netscaler Load Balancer – Forwarding client IP to the Glassfish Server

In my two previous posts I wrote how to forward and capture the actual client IP in Apache and IIS web server. Please refer to my previous two posts before reading this post

Netscaler Load Balancer – Forwarding client IP to the IIS 7+ Web Server

Netscaler Load Balancer-Forwarding client IP to the Apche Web Server



Step1: Configuring Netscaler to insert client IP in a custom header

In admin console GUI, open the service for which you want to configure client IP forwarding. Go to the Advance tab and in Settings section, tick the Client IP checkbox and enter the name of the header field which will contain the actual client IP. In my case I named the header as Client-IP.


Same thing we can do from Netscaler command line:
> set service Solarex4_7777_service -cip ENABLED Client-IP
Repeat this step for all the services.


Step2: Configure Glassfish to log the custom header in access log
In my post Enabling HTTP access log in Glassfish, I wrote how to enable Glassfish HTTP access log and different Format options available for access log. Please refer to that post.
I searched a lot but could not find anything about how to capture a custom header in Glassfish HTTP log, so I decided to try some options.
First I tried the following format:
% Client-IP% %datetime% %request% %status% %response.length%

But could not find anything in the access log file, the % Client-IP% field was coming blank. I tried few other permutation combinations but that didn’t work.
When I read the available values for including in access log pattern I found one value %header.% and decided to give it a try. After playing a little with this finally I saw success. The value which worked for me was %header.Client-IP%
. So my Glassfish HTTP access log settings look like:


In the access log file I could see the actual client IP:
117.200.167.6” “20/Apr/2011:10:24:17 +0530″ “GET /EF/learner/form/showLearnerDesc.jsp?learnerId=w5CjCwLkW3SQmuil7xzFjZ HTTP/1.1″ 200 223

115.242.128.85” “20/Apr/2011:10:24:17 +0530″ “GET /EF/learner/InMarkLearnerDescripancy.jsp?lr=kW3SQmuw5jEwwcil7ZZ&cid=Mh2ZLw51TkW3SQmuilMh&bid=CcjSQmuil7xzFH06EobjN&crid=9LNMh2ZkW3SQmui88&returnPage=1 HTTP/1.1″ 200 37526

115.242.128.85” “20/Apr/2011:10:24:17 +0530″ “GET /EF/renderImg?cid=uil7xzFH06EobLw51TImh&bid=ZkW3SQmuilCcj7×3N&crid=Mh2ZkWL3SQmuil7xz28&img=1103270039_sign HTTP/1.1″ 200 1487

115.242.128.85” “20/Apr/2011:10:24:17 +0530″ “GET /EF/renderImg?cid=j89NMh2ZLw51TkW3SQmukh&bid=NCcjMh2ZkW3S8N&crid=uil7xzFHL0k8&img=1103270039_photo HTTP/1.1″ 200 2586

115.242.128.85” “20/Apr/2011:10:24:17 +0530″ “GET /EF/common/jsp/getMenu.jsp HTTP/1.1″ 200 13771



জয় আই অসম,
প্রণব শর্মা

No comments:

Post a Comment