Monday, June 20, 2011

How to use Apache Benchmarking tool

Apache Benchmarking tool is used for doing load test for web applications.
Below is an example of using it :

ab -n 1000 -c 100 "http://ip:port/test"

-n - number of requests
-c - number of concurrency requests

Wednesday, June 8, 2011

Import a .js file in another js file

function inc(filename)
{
var body = document.getElementsByTagName('head')[0];
script = document.createElement('script');
script.src = filename;
script.type = 'text/javascript';
body.appendChild(script);
}

inc("jscripts/HelpWindow.js");
inc("jscripts/shortcut.js");

Thursday, April 21, 2011

Https Configuration in Tomcat

How to configure SSL on Tomcat
Steps to create keystore file.
1. >cd $CATALINA_HOME
2. > $JAVA_HOME/keytool -genkey -alias tomcat -keyalg RSA -keystore mycert.jks
3. Enter keystore password: changeit
4. What is your first and last name? [Unknown]: Company
5. What is the name of your organizational unit? [Unknown]: IT
6. What is the name of your organization? [Unknown]: My Comp.
7. What is the name of your City or Locality? [Unknown]: KL
8. What is the name of your State or Province? [Unknown]: KL
9. What is the two-letter country code for this unit? [Unknown]: MY
10. US Is CN= Company, OU=IT, O=”My Comp.”, L=KL, ST=KL, C=MY correct? [no]: yes
11. Enter key password for (RETURN if same as keystore password): Hit Enter.
Tomcat will assume the password is “changeit” by default so it’s advised to leave it that way.
Steps to configure Tomcat to use the keystore file.
1,cd $CATALINA_HOME/conf/
2,vi server.xml
3,Look for “ Define a SSL HTTP/1.1 Connector on port 8443 ”. Remove the comments indicator and add the keystore info.

Define a SSL HTTP/1.1 Connector on port 8443
Connector port="443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" keystoreFile="/app/interface/ui/mycert.jks" sslProtocol="TLS"

4,Make sure redirect port is set as 443 as below in server.xml.
Connector port="9090" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="443"

5,In Application’s web.xml following lines need to be added.
security-constraint




6,Restart Tomcat server and test.

Wednesday, April 20, 2011

Eclipse Issue "An internal error occurred during: "Items filtering". Class file name must end with .class"

Deleting the corrupted search index which is explained in Eclipse bug’s #269820 comment.

How to delete the search index:

1. Close Eclipse
2. Delete workspace/.metadata/.plugins/org.eclipse.jdt.core/*.index
3. Delete workspace/.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt
4. Start Eclipse again

This fixed the issue for me.

Thursday, March 24, 2011

POST Method request Using JavaScript



How to simulate the below in javascript ?

action=http://example.com/ method=POST
input type=hidden name=q value=a
How to call the javascript function :

post_to_url
('http://example.com/', {'q':'a'});

function post_to_url(path, params, method) {
method = method || "post"; // Set method to post by default, if not specified.

// The rest of this code assumes you are not using a library.
// It can be made less wordy if you use one.
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);

for(var key in params) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);

form.appendChild(hiddenField);
}

document.body.appendChild(form); // Not entirely sure if this is necessary
form.submit();
}


Hope this helped someone.



Thursday, December 2, 2010

Daemon Threads

Daemon Threads are generally taken to consideration in Application development when there is some task to be done, however of not much priority. Say like U have an GUI application whose task is to get User Name & Password & validate it....however, U would like to put up few ads/JPGS on the screen .... In such a case we will associating a main thread to validate UID/PWD & daemon threads to show or change the ads.... In the above example there's no use of the GUI with just ads & without the UID/PWD screen & validator. So JVM can make the daemon thread exit. Generally Daemon threads are used when there are some not-so-important task to done along with the main task.

Timer scheduler = new Timer(isDaemon); //for creating domean threads isDaemon = true

scheduler.cancel(); //cancel the assigned tasks
scheduler.purge(); //remove the tasks in queue so that it can be garbage collected.