Sunday, October 26, 2014

Get original hash code of a Object after overriding the equals and hash code methods

When we writing programs, there are some which we override the hash code and the equals method of a object in java. But sometimes, when debugging purposes, we always needs to get the original hash code of a object. This is where we can use interesting method to takeout the actual hash code of the object.

System.identityHashCode(object)

Sunday, October 19, 2014

How to change the logging pattern of Nginx

Some time you may needs to filter out requests and responses coming to Nginx with more details wich requires specify customize log level in Nginx. Assume you may needs to find out the JSESSIONID of a request coming to the Nginx. Here is the way to have the customize log with Nginx.

Specify following logging format in the nginx.conf and refer it in the access log.

log_format   main '$remote_addr - $remote_user [$time_local]''"$request" $status $body_bytes_sent''"$http_referer" "$http_user_agent" - "$http_cookie"';


access_log /var/log/nginx/access.log main;

You will see out put similar to follow.

10.100.5.81 - - [29/Sep/2014:15:44:06 +0530]  "GET /gad_test/index.jsp HTTP/1.1" 200 147 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36" - "JSESSIONID=A2EADE2B419119B8D6184D2B403EC1F1; menuPanel=visible; menuPanelType=main; MSG14119741284050.4971712792784695=true; MSG14119785293260.851528721338783=true; MSG14119793691950.3470202483511987=true; MSG14119793844710.6098322352974117=true; requestedURI=\x22../../carbon/webapp-mgt/upload.jsp?region=region1&item=webapps_add\x22; current-breadcrumb=manage_menu%2Cwebapps_menu%2Cwebapps_list_menu%23webapp-list+webapp_info.jsp*; JSESSIONID=AB2D16E5754D07F20584BBC58119B466"
Also you can enable debug logs of Nginx as follow
error_log path_to_the_log_file debug;

Saturday, October 11, 2014

Find files which don't have a keyword

In our normal day to day activities, we often needs to search for files looking for some keyword. But when you need to search for files which don't have a specific keyword in linux. Below I gave the answer for it. This search for java files which don't have the keyword WARRANTIES. -L flag in grep gives this functionality.

grep -rL "WARRANTIES" --include=*.java  *