Tuesday, 3 March 2015

eclipse shortcuts

Ctrl-Shift-O   Remove unused imports

Ctrl-Shift-R Open Resource

Ctrl-Shift-O  Open a resource search dialog to find any class


http://www.shortcutworld.com/en/win/Eclipse.html

UNIX sort

sortRequestFiles("/tmp/input");

sub sortRequestFiles {
$INPUT_DIR = $_[0];

my @files = glob( "$INPUT_DIR/request*" );

foreach (@files ){
   print "Sorting " . $_ . "\n";
   qx/head -n1 $_ > $_.tmp/;
    qx/tail -n +2 $_ | sort -k1,1 -nk2 >> $_.tmp/;
    qx/mv $_.tmp $_/;
  
    }

           }

Tuesday, 30 December 2014

GIT COMMANDS

Git is a distributed version control system with an emphasis on speed, data integrity and support for distributed and non linear work flows.

Below are some of the popular commands:


git status   # changed file in your working directory

git add .   #Add all changes to the next commit

git diff    #changes to tracked files

git branch <new branch>  # create a new branch based on your current head

git branch -d <branch>  #Delete a local branch

git pull --all

git log

git branch   # list all the existing branch

git stash

     git stash apply     # apply last stashed changes to working dir

     git stash list          # see your stashed changes

     git stash apply stash@{2}    # apply specific stashed changes.

git remote show origin          #to see the repository url


git reset HEAD^                  # remove commit locally
git push origin +HEAD       # force-push the new HEAD commit

Thursday, 30 October 2014

SPRING BATCH

Spring Batch, is an open source framework for batch processing – execution of a series of jobs. Spring Batch provides classes and APIs to read/write resources, transaction management, job processing statistics, job restart and partitioning techniques to process high-volume of data.


Spring Batch is a framework for batch processing – execution of a series of jobs. In Spring Batch, A job consists of many steps and each step consists of a READ-PROCESS-WRITE task or single operation task (tasklet).
  1. For “READ-PROCESS-WRITE” process, it means “read” data from the resources (csv, xml or database), “process” it and “write” it to other resources (csv, xml and database). For example, a step may read data from a CSV file, process it and write it into the database. Spring Batch provides many made Classes to read/write CSV, XML and database.
  2. For “single” operation task (tasklet), it means doing single task only, like clean up the resources after or before a step is started or completed.
  3. And the steps can be chained together to run as a job.
1 Job = Many Steps.
1 Step = 1 READ-PROCESS-WRITE or 1 Tasklet.
Job = {Step 1 -> Step 2 -> Step 3} (Chained together)

Spring Batch Examples

Consider following batch jobs :
  1. Step 1 – Read CSV files from folder A, process, write it to folder B. “READ-PROCESS-WRITE”
  2. Step 2 – Read CSV files from folder B, process, write it to the database. “READ-PROCESS-WRITE”
  3. Step 3 – Delete the CSB files from folder B. “Tasklet”
  4. Step 4 – Read data from a database, process and generate statistic report in XML format, write it to folder C. “READ-PROCESS-WRITE”
  5. Step 5 – Read the report and send it to manager email. “Tasklet”
In Spring Batch, we can declare like the following :


  <job id="abcJob" xmlns="http://www.springframework.org/schema/batch">
 <step id="step1" next="step2">
   <tasklet>
  <chunk reader="cvsItemReader" writer="cvsItemWriter"  
                    processor="itemProcesser" commit-interval="1" />
   </tasklet>
 </step>
 <step id="step2" next="step3">
   <tasklet>
  <chunk reader="cvsItemReader" writer="databaseItemWriter"  
                    processor="itemProcesser" commit-interval="1" />
   </tasklet>
 </step>
 <step id="step3" next="step4">
   <tasklet ref="fileDeletingTasklet" />
 </step>
 <step id="step4" next="step5">
   <tasklet>
  <chunk reader="databaseItemReader" writer="xmlItemWriter"  
                    processor="itemProcesser" commit-interval="1" />
   </tasklet>
 </step>
 <step id="step5">
  <tasklet ref="sendingEmailTasklet" />
 </step>
  </job>
The entire jobs and steps execution are stored in database, which make the failed step is able to restart at where it was failed, no need start over the entire job.

Monday, 20 October 2014

REST - Representational State Transfer

Monday, 8 September 2014

JSON vs XML

JSON JavaScript Object Notation
XML Extensive Markup Language

Following are key differences between JSON & XML, which will help to decide which content format one should use in there application :


  • Parsing and Generating JSON data is easier as compared to XML.
  • JSON has simpler structure than XML.
  •  In XML document manipulation is easy as compared to JSON.You can easily find/update nodes.You have XPath/XQuery for XML, Do we have it for JSON ? 
  • You can do lots of thing with XML for example converting XML to HTML using XLST, such tools not available for JSON.
  •  XML is more rich in features and you can have more control over data and do great amount of validation as compared to JSON.You can have DTD's for XML to specify validation in details 
  • Working with JSON is simpler, especially with Javascript, just by giving call to Eval will give you Javascript Object.
  • JSON is not in a document format neither it is markup language but XML is.
  • JSON has great language support as compared to XML.
  • JSON is best for simpler use/scenario, for better security,support and validation XML is better.

  • JSON is faster as compared to XML as it is less rich, there is less overhead of tags & there is simpler validation rules.    

REST vs SOAP

REST stands for REpresentational State Transfer (REST) which enforces a stateless client server design where web services are treated as resource and can be accessed and identified by there URL unlike SOAP web services which were defined by WSDL.
Web services written by applying REST Architectural concept are called RESTful web services which focus on System resources and how state of Resource should be transferred over http protocol.

SOAP
SOAP, originally defined as Simple Object Access Protocol, is a protocol specification for exchanging structured information in XML form.SOAP is protocol which relies on XML, that defines what is in the message and how to process it,set of encoding rules for data types, representation for procedure calls and responses.


REST vs SOAP

Before going for differences between two lets first see the differences in request header :

Sample SOAP & REST Request message for Weather Web Service :






 


SOAP vs REST Key Differences
Here are some of Key differences between SOAP and REST web Service :

  •  REST uses HTTP/HTTPS, SOAP can use almost any transport to send the request(for example we can have SOAP Messages over SMTP),  SOAP is a XML based messaging protocol.
  • REST is totally stateless operations where as SOAP supports statefull calls too. 
  • SOAP has more strict contract in the form of WSDL between applications, no such contract exists in case of REST.
  • AS REST APIs can be consumed using simple GET requests, REST response can be cached, this is not possible with SOAP.
  • REST is Lighter, SOAP requires an XML wrapper around every request and response(SOAP Headers, XML tags etc). Thats why REST is preferred choice in mobile devices and PDA's
  •  SOAP message format is restricted to XML only where as REST supports other formats too for example JSON.  
  • REST is simpler in terms of development as compared to SOAP.
  • Browsers can handle REST easily as compared to SOAP as REST is based on HTTP where SOAP is another wrapper over HTTP.

Why to use SOAP ?
SOAP provides some features like Security, Reliable Messaging, Atomic transaction which are not available in REST API.

  • WS-Security  & WS-SecureConversation  Provide support for using security tokens like Kerberos, and X.509.
  • WS-ReliableMessaging   Reliable messages delivery between distributed applications in case of failures.
  • WS-AtomicTransaction, two-phase commit across distributed transactional resources
  • In case where exact specification  of exchange format need to agreed between applications SOAP is better suitable.