Thursday 21 June 2012

DPMailSniffer ~find out if your email has been read ~




Now you can find out when your email has been read by the recipient! No more guessing: "Has he or she read my email yet?".Use sniffer anytime on anyone: Your business contact, cheating girlfriend, ex-husband, stranger you met online, or just anyone who doesn't respond to your email and needs to be "verified." Just sniff them ;-)

There are already some sites providing this ,still you can develop your notification system very easily and customize as you wish.
Mail-sniffer a simple email tracking system that sends you a notification by email when the recipient opens your message.


Note : Both you and the recipient must use an HTML email, not plain-text or rich-text email.(yahoo,gmail,hotmail all the modern ones supports this)


The Simple logic behind this tracking is to have a image from your application being included to the mail being sent(of course secretly),so when the mail is opened the request comes to your application for downloading the secret(invisible) image which you have included in the  mail,now you can investigate the request and get the details.


Step 1: Have a form with from mail and the subject of the mail.


Step 2: Create a secret image (some white image ) or you can have some visible image backing your signature in the mail.Have your own logic to map the email id and subject entered in the above fields mapping to the image created.Image should be in your application running on the server(intranet or internet )

Step 3: Copy the image (select the image and CTRL+C) and paste it at some place in the mail being sent(CTRL+V) and send your mail as usually.

So when ever the recipient opens the mail,the image should be downloaded from your application running and the request comes to your application.

Say for example you have included some gif (secret empty)image in the mail.The following bits of code will help you in getting hold of the request.

web.xml 


<servlet>
<servlet-name>spy</servlet-name>
<servlet-class>com.dp.controller.SpyServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spy</servlet-name>
<url-pattern>*.gif
</url-pattern>
</servlet-mapping>


check the request and identify which image is being requested for.We have already stored the from id and the subject mapped to a particular image file in Step 2.Use this from id and the subject to notify that the particular mail sent is being opened by so and so using the following kind of  servlet.


SpyServlet :


/**
 * 
 * @author DurgaPrasad.K
 *
 */
public class SpyServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {

System.out.println(req.getRemoteAddr() + " - - " + req.getRemoteHost()
+ "- - " + req.getRemotePort() + "- - " + req.getRemoteUser()
+ "- - " + new Date(System.currentTimeMillis()));
//notify the user

}
}

Your app must be hosted to the intranet or internet as per your requirement.That's all for now.


Cheers...Thanks for reading   :-) :-)






Tuesday 17 April 2012

DataBase Normalization 3NF



DB Normalization is the process of organizing the columns and fields of a relational table to minimize the redundancy,complexity and dependency.


First Normalization Form( 1NF ) :


A table is said to be in  1nf when there are no repeating groups or  no repeating elements present.


Second Normalization Form ( 2NF):


A table is in 2NF if 


 a) the table satisfies the 1NF


 b) no partial dependencies on the primary key(may be compound primary key) [ remove subsets of data that apply to multiple rows of a table and place them in separate tables supplied with foreign key relation ]




Third Normalization Form(3NF)


A table is in 3NF if


a)already satisfied the 2NF 


b) all the attributes should be directly dependent on the primary key



Example:

Let's try  normalizing the following table



1nf :remove the attributes which are redundant class_1,class_2,class_3 in the above table and bring it on as below





 

2nf: No partial dependency of non-key attributes on the primary key and remove subsets of data consolidated as tables with foreign key relation

Considering student_id and Mentor as compound primary key, class is not a full dependent on the composite py key and on segregating will result in the tables as follows 


Add caption





3Nf : all the attributes should be directly dependent on the primary key

In the STUDENT_ID,MENTOR AND MENTOR_ROOM table mentor_room is no way dependent on the student_id  which is the py key so on consolidating 




Thanks for Reading.... cheers  :-) :-)

Saturday 24 March 2012

Accessing Restful Services from Java Command Line Application`




In this small note, let us see the simple java command line programs to access RESTful Service.REST stands for Representational State Transfer(that is representation of resources is exchanged between client and server).I would be using( accessing :-) ) the Twitter WebService(Messaging API) and the Webservice URI for the same is


http://twitter.com/statuses/public_timeline.xml (for payload in xml format)
http://twitter.com/statuses/public_timeline.json(for payload in json format).



I've tried accessing the service in two simple ways


1.using java.net package
2.using jakarta Commons HttpClient.


1.Using java.net package






2.Using HttpClient : This method of accessing is also simple as first one,but is little sophisticated with the return status code check and granularity.
needed binaries
1.jakarta commons Httpclient 
2.jakarta commons codec
3.jakarta commons logging.






Cheers and Thanks for reading :-) :-)

Wednesday 25 January 2012

Separate Threads for Process Input and Error Stream ~CMD mode execution using java Runtime ~



I had to run a bat file from cmd(command) mode using java and flatten the output of the cmd mode to a text file for instance and my block of code looks as below and its quite simple as well.I've used the InputStream and ErrorStream to serve the purpose.


and a while loop to iterate and write to text file.




while ((s = stdError.readLine()) != null) {
//put to a file

}




while ((s = stdInput.readLine()) != null) {
//put to a file

}


But,I have ended up in a problem ,the thread seems to have ended up blocking and the bat file(which consists of triggering my web driver test cases)was also blocked.The quick work around was to have two anonymous inner class of Thread and it solved the problem.


This is only for quick work around before I look into non blocking io's.






Thanks for reading..... cheers :) :)



Friday 20 January 2012

Set With Cardinality



Java's Set interface  has 3  general purpose implementations,with differences in the purpose they serve (sorted,ordered,link mechanisms,bucketing formulae etc)


  1.HashSet
  2.TreeSet
  3.LinkedHashSet 


I was looking for some collection with  virtues like

  •  Indicating the collection has x number of  Y-type objects,n number of z-type objects.
  •  Remove n number of y-type objects from collection.
  •  Add 10 z-type objects to the collection etc
i.e collection which maintains some cardinality ,instead of just holding single instance of unique objects.
com.google.common.collect.HashMultiset Collection serves the purpose and it maintains the cardinality of the objects it is holding and the following is the simple block of code I've used to see how it works.






Thanks for reading.... cheers :-)


Saturday 7 January 2012

Unobtrusive JavaScript



Unobtrusive JavaScript is the practice of separating out any JavaScript behavior
code from your content structure and presentation.

<input type="button" onclick="validateDate()" id="_btn" />

The above line of  html content of a  button is some ways coupled to the behaviour of onclick.This can be decoupled by using Unobtrusive JavaScript paradigm.

Little modification to the above will set the things right :)

<input type="button"  id="_btn" />.

Instead of embedding the behavior in the markup,this can be segregated by moving the script to script block with in <head> tag else to the bottom of your document considering some performance stuff.

<script>
window.onload=function(){
document.getElementById"(_btn").onclick=function(){
//do the stuff here 
}
}
</script> 



The above lines of code is similar to $(document).ready (function()......) in jquery.This helps in clear seperation of behavior from structure.

Thanks for reading....cheers... :-) :-) :-)


Tuesday 3 January 2012

Web Driver Grid -forcing to run on a particular client node.



WebDriver is open source tool for automatic web application testing.

WebDriver Grid  concept is like a central hub will be started and the client machines will be
registered to the central hub.The client nodes will have different capabilities (capabilities here 
refer to browser version,os,platform etc).

Grid allows you to :
  • scale by distributing tests on several machines ( parallel execution )
  • manage multiple environments from a central point, making it easy to run the tests against a vast combination of browsers / OS.
  • minimize the maintenance time for the grid by allowing you to implement custom hooks to leverage virtual infrastructure for instance.

The central Webdriver hub will be instantiated using the remote webdriver  as
 webDriver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
and the  webDriver will be supplied with capability say for eg

capability.setBrowserName(“firefox ); 
capability.setPlatform(“LINUX”);  
capability.setVersion(“3.6”);
so ,the remote web driver will look for the nodes satisfying the supplied capability and run the tests on the particular node.So,if there are multiple nodes satisfying the capability and the pick is random

Let me brief how to set up a Gridstep 1: Start the hub using the following command on the central machine(say X).
java -jar selenium-server-standalone-2.14.0.jar -role hub
step 2: Register the node machine to the hub started in step 1
java -jar selenium-server-standalone-2.14.0.jar -role node  -hub http://X:4444/grid/register
The above are two steps to start a hub and register a client node.So there can be many client nodes listening to a single hub.
Step 3: Stepping to the test cases,the webDriver should be instantiated using the RemoteWebDriver on your hub.
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),capability);
driver.get("www.google.com");
driver.findElement(By.id(.....)) and the test cases go on.
So,if there are n node machines listening to the hub and when you execute the test case,the hub will pick the node which satisfies the capability set in the step 3 and run the tests on the particular machine.The client nodes capability can be passed along with the registering command as follows
java -jar selenium-server-standalone-2.14.0.jar -role node  -hub http://X:4444/grid/register  -browser "browserName=firefox,version=7.0,platform=windows" 

I was needed to develop a web app using this grid concept,so the client can access a url and start the test on the particular machine.The trick here to solve was if there are n nodes registered to the hub with same capabilities ,the hub may delegate the test case execution to any of the clients.So,the real user who started the test may not see it running on his machine,but may be as a surprise to some other client machine where the tests get executed launching the browser.

The way I used, to solve this is by customizing the browser version to the ip of the client machine,so the capability from the client machine will be unique,so hub will have to delegate the execution of testcase to the same machine from where the request is from.
I have done little dos scripting to identify the ip config of the machine while registering to the hub.
SETLOCAL
set host=%~1
set ip=
if "%host%"=="" ( for /f "tokens=2,* delims=:. " %%a in ('"ipconfig|find "IPv4 Address""') do set ip=%%b
) ELSE ( for /f "tokens=2 delims=[]" %%a in ('"ping /a /n 1 %host%|find "Pinging" 2>NUL"') do set ip=%%a)

java -jar selenium-server-standalone-2.14.0.jar -role node  -hub http://X:4444/grid/register -Dwebdriver.chrome.driver="chromedriver.exe" -browser "browserName=firefox,version=%ip%,platform=windows" 
and while instantiating the remote webdriver in the hub,I will be setting the capability as 
below
capability.setBrowserName(“firefox ); 
capability.setPlatform(“windows”);  
capability.setVersion(request.getRemoteHost());
You can download the required  selenium-server-standalone-*.jar from http://code.google.com/p/selenium/downloads/list.
Cheers..thnx for Reading :)