Tuesday 17 September 2013

Running tomcat in debug mode linux

Probelm: How can I run tomcat in debug mode in Linux

Solution:
Naviagate to tomcat bin directory



 
#cd /opt/webservers/tomcat/bin
//Execute below script
#export JPDA_ADDRESS=8000
#export JPDA_TRANSPORT=dt_socket
#export JPDA_SUSPEND=n
#./catalina.sh jpda start

Hint: Connect to 8000 port for debugging the application

Monday 16 September 2013

Dynamically change request cookie name apache


Problem:
I want to dynamically replace cookie name coming from browser to Apache web server.

Solution: The below example will replace all the incoming requests that has cookie name as "SESSION" to "LUCKY.SESSION"

Edit:  httpd.conf

 
RequestHeader edit Cookie "SESSION" "LUCKY.SESSION"
Hint: Please include headers module to work. For ex: Uncomment "LoadModule headers_module modules/mod_headers.so" in httpd.conf

Send Cookie and custom HTTP header using java.net.URLConnection

Problem: Often sites accepts custom http headers and cookies to get data from them. In below example we are going to read data from URL by send http cookie and header.

Solution:

 
package com;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
/**
 * It reads data from a site by sending cookie and custom http header
 * @author lucky academy
 *
 */

public class URLReaderDemo {
public static void main(String[] args)throws Exception {
 //URL of the site
 URL site = new URL("http://www.luckyacademy.com/services/odata/Person");
 //Open Connection
 URLConnection uc = site.openConnection();
 //Set Cookie
 uc.setRequestProperty("Cookie", "JSESSIONID=F2845FC15FCF6660EB093D00DAE73BB2; rememberMe=false");
 //Set custom http header
 uc.setRequestProperty("tenantId","ebay");
 //read data from the site
 //Setting http headers after opening input stream will not have any effect
 BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
 String inputLine;
 while ((inputLine = in.readLine()) != null) {
  System.out.println(inputLine);
 }

 in.close();

 
}
}

Wednesday 11 September 2013

Find and Replace a string in a file

Problem: In linux I want to find a string and replace it with other string in a file.

Solution:  Use the below command.

 
find . -type f  -print | xargs sed -i 's/abc/123/g'

The above command will recursively searches for all the files in current working directory and it replaces all the occurrences of abc with 123 in the found files.

Sunday 8 September 2013

Unable to detect Bluetooth for HP Pavilion g6-2010ax in Windows7


Problem: I am unable to bind any of the Bluetooth devices to my laptop though it says blue tooth is on.

Reason: By default Microsoft Bluetooth drivers are getting installed and they doesn’t work well with the hardware.

Solution:
1.       Install “Atheros Wireless LAN Driver” from http://ftp.hp.com/pub/softpaq/sp56501-57000/sp56572.exe
2.       Install  “Atheros Bluetooth 4.0 + HS Driver” from http://ftp.hp.com/pub/softpaq/sp56501-57000/sp56573.exe
3.       Restart the machine.

Hopefully the above steps should solve the problem.