Saturday, 10 September 2016

Textual description of firstImageUrl

How to Create Documentation of JAX-RS Web Services

In this post i will describe how to create a html document from you rest jersey class , which can be used by web sevices consumers easily .

First you need to install raml-for-jax-rs plugin in your eclipse or anypoint studio .

Once you start it properly , and go to your rest service JAX-RS class , and right click on it , you should be able to see "Generate raml for class" option . You click on it and provide name and location of your generated raml file .

Now you have your generated automatically by this awesome plugin , you need to convert it to html document . For that , you have to install raml to html plugin which is written in node.js . install this plugin and go to the location where you have generated the raml file .Now you have to just use following command :
raml2html RestServices.raml -o doc.html
Now your rest class is converted in good looking one page html document which you can expose on your web server .

Friday, 12 August 2016

Textual description of firstImageUrl

Download WebMaster Tool Data using Casper JS

This is a simple casper js script to automate your process of downloading webmaster tools reports .

Google Webmaster does not provide any api to download the data .

This simple casperjs script will allow you to download the data and automate the process .

please change the google account credentials and also the time period for which you want to download the report .
var page = require('webpage').create();
var xpath = require('casper').selectXPath;
var casper = require('casper').create({   
    verbose: true, 
    logLevel: 'debug',
    pageSettings: {
         loadImages:  false,         // The WebPage instance used by Casper will
         loadPlugins: false,         // use these settings
         userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4'

// print out all the messages in the headless browser context
casper.on('remote.message', function(msg) {
    this.echo('remote message caught: ' + msg);

// print out all the messages in the headless browser context
casper.on("page.error", function(msg, trace) {
    this.echo("Page Error: " + msg, "ERROR");

var url = '';

casper.start(url, function() {
   // search for 'casperjs' from google form
   console.log("page loaded");
   this.fill('form#gaia_loginform', { 
    }, true);

   console.log("Page Title " + document.title);
var url = '';
casper.thenOpen(url ,function (status) {
    /*var js = page.evaluate(function () {
        return document;
    console.log(JSON.stringify(js)); */
 console.log(" trrsadsadsssssss");

casper.then(function() {
 console.log(" clickingggg first time ");'#tsq-table-download > div:nth-child(1)');
 //'//*[@class="goog-inline-block jfk-button jfk-button-standard"]'));

//casper.waitForSelector(xpath('/html/body/div[11]/div[3]/button[1]'), function() {
 casper.waitForSelector('.goog-buttonset-default', function() {

  this.capture('abc.png', undefined, {
             format: 'png',
            quality: 100

casper.then(function() {
 console.log(" clickingggg");

casper.on('resource.received', function(resource) {
  if(resource.url.indexOf("/top-search-queries-dl") > -1)
   console.log(" resource url is " + resource.url);
   console.log("Downloading csv file");, 'ExportData.csv');
Post Comments and suggestions !!!!

Thursday, 4 August 2016

Textual description of firstImageUrl

How to migrate from SVN to GIT repository

This post describes step by step guide to migrate your svn repository to git repository.
First , lets have a look as why git is better than svn .

1) GIT is distributed, SVN is not.
 2) GIT stores content as metadata, SVN stores just files.
3) GIT branches are not the same as SVN branches.
4) GIT does not have a global revision no. like SVN do.
5) GIT’s content integrity is better than SVN.

Now we see the different structures of both these .

->Extra DIR


->Single Working Directory
.git directory stores binary format of branches , tags and other details.


1. Download Subgit from above link
2. Make Sure you have java version >= 1.7
3. Note Down the SVN URL & Git Remotes
4. Extract the Downloaded archive.
5. Execute the below Commands
6. ~/Softwares/subgit-3.2.0/bin/subgit configure --layout auto dsc.git
7. The above command will detect the latest revision , history , branches, tags and configure authors.
8.  Once Done execute
9.  ~/Softwares/subgit-3.2.0/bin/subgit install dsc.git/  This would take some time depending on the revisions and the no of time file got modified to convert revision to git commits. Have Patience.
10. git clone dsc.git
11. This Would create your dsc git project with all tags , branches etc…
12. cd dsc && git branch –ar would list all the branches. You can also use git log to see the revisions converted to GIT Commits.
13. IMP:  git remote –v would saw you locat path which need to be changed to GIT Remote.
14. In mycase : In file .git/config , url = /Users/mohantysan/workspace/GitMigration/dsc.git 
We need to Change it to Git URL else if you make any commits and push it will push to SVN REPO.
Change the url to something like this :
url =
Now Your SVN Repo is Converted and ready to be published.
 git push origin –all # will push your code with all svn converted revision to GIT and you can use it as usual.
For Publishing Branches and Tags checkout branches and tags locally and push 
Happy Migration , Thank You

This post is created by Santosh Mohanty . You can contact him for any questions at or message him on his linkedIn profile .

Friday, 8 July 2016

Textual description of firstImageUrl

Jav 8 FlatMap Explained Stream API

In this short example , i will explain where we can use flatMap function of java stream api .

Suppose you have a multi level list where many objects are stored , and you want to convert it to a single list of objects . We can use flatmap which will flatten the list easily .

FlatMap basically first applies the transformation , and then then flatten the result in a single collection .

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

 * Created by abhishek.somani on 8/7/16.
public class JavarootsFlatMapExample {

    public static void main(String[] args) {
        String[] arr = {"abhishekl","somani"};
        String[] arr2 = {"java","example","1.8","stream"};
        List<List<String>> list = new ArrayList<>();
        final List<String> strings = ->;

Post Comments And Suggestions !!!

Tuesday, 5 April 2016

Textual description of firstImageUrl

Mule HttpListener Example

Mule Runtime 3.6 and later version have deprecated old Http Connector with , new Http Listener Config . Let's take an example to see how we can use it .This example also demonstrates how to get a particular xml element without using JAXB .

This example app will listen to a particular host and port , for post method , and parses the request xml using xpath . Based on the xml , we return the response based on the input xml received in request .

This is our mule config xml :
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="" xmlns="" xmlns:doc=""
 xmlns:spring="" version="CE-3.6.1"

<http:listener-config port="8081" host="" name="myRequestConfig" >
 <http:worker-threading-profile maxThreadsActive="15"/>

<flow name="SimpleTest" >
<http:listener path="/abc" config-ref="myRequestConfig" allowedMethods="PATCH"/>
<logger category="d" level="ERROR" message="xpath: #[xpath3('/isCancelled')]"/>

<choice >
<when expression="#[xpath3('/isCancelled') == 'true']">
 <set-payload value="SUCCESSS"></set-payload>
 <set-payload value="FAIL"></set-payload>

Now we can see that traditional http inbound endpoint and http connector is replaced with Http Listener and Http Listener Config respectively . The major difference is that we can not use service overrides in Http listener config like we used to do in http connector , also http listener does not return MULE_SESSION in response headers .If we use http listener , all outbound property will automatically be converted in http response headers . You can use allowedMethods attribute to configure different Http methods . We can have multiple http listener , referencing to same listener config . Multiple flows with same path but different methods is also allowed .

Post Comments And Suggestions .!!!

Wednesday, 9 December 2015

Textual description of firstImageUrl

How to Generate Barcode 128 In Java

For generating Barcodes , we can use Barcode4j library , which is opensource and free library . Let's look at some java code to generate barcode as image in java .

First of all , enter following dependency in your pom.xml.

You can also download the jar from here if you are using it in a standalone java program .

Now here is the sample java program which generates the barcode 128 with codeset B and save it as a png file.

import java.awt.image.BufferedImage;

import org.krysalis.barcode4j.impl.code128.Code128Bean;
import org.krysalis.barcode4j.impl.code128.Code128Constants;
import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider;

public class MainClass2 {
  public static void main(String[] args) throws IOException {
    String barcodeString = "4888575";
    Code128Bean barcode128Bean = new Code128Bean();
    final int dpi = 100;

  //Configure the barcode generator
    //adjust barcode width here
  barcode128Bean.setModuleWidth(UnitConv.in2mm(5.0f / dpi)); 

  //Open output file
  File outputFile = new File("G:/barcode.png");
  OutputStream out = new FileOutputStream(outputFile);
      BitmapCanvasProvider canvasProvider = new BitmapCanvasProvider(
              out, "image/x-png", dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0);




Barcode4J supports other formats like EAN-128, GS1-128 , Code 39 etc as well .

Provide comments and suggestions !!!

Sunday, 22 November 2015

Textual description of firstImageUrl


NFS mount is used to share a directory between several servers, It saves the disk Space and is Useful for a Infrastructure where a application shares a common directory and is hosted in multiple instances.

Lets think we have a Rails application where we upload a csv file and save it a directory in server with file name to DB .

On the other hand a Rake Task/ Cron Job runs every two minutes that polls DB for file name and proccess the CSV file to get the desired response.

It works fine when we have a single instance hosted in server, think if we have two instances of Rails in different Server and is managed by a Load balancer to server request.

When a File Upload Request comes to ELB , it directs to instance1 with file1 and the second request to instance 2 with file2, The cron job in instance 2 picks the file name file1 from DB and doesnot found any matching file and Marks FILE NOT FOUND IN DB , where as file is present in instance1.

To avoid this type of issues we can use S3 which we can get py paying few amount, the Opensource way is Using NFS Mount, Lets Check how to Configure NFS.

Lets Say we have two instances with IP:

Lets Configure
NFS-Master :
NFS - Client :

Execute the following Commands:
sudo su 
yum install nfs-utils nfs-utils-lib
Startup Scripts :

chkconfig nfs on 
service rpcbind start 
service nfs start

EXPORT the Shared Directory :

Suppose we want the directory /home/rails/upload_dir , to be shared between the instances.

Open vi /etc/exports
Add the following lines at EOF
then execute :
exportfs -a
service nfs restart
SSH to server

Execute following commands:

yum install nfs-utils nfs-utils-lib
#Assuming the upload_dir path is same as instance1
mkdir -p /home/rails/upload_dir
mount /home/rails/upload_dir

You Can verify it by typing:
df –h
Filesystem            Size  Used Avail Use% Mounted on /dev/sda               20G  783M   18G   5% / 20G  785M   18G   5% /home/rails/upload_dir
nano /etc/fstab
Add the following line:  /home/rails/upload_dir nfs      defaults,_nfs_shared 0 0
Try creating a file in instace1 of shared dir and check it should be populated in instance2 of shared dir(/home/rails/upload_dir)

Keep in Mind Once the NFS Mount is unmounted all the data will be lost from the mounted instance , but data will be safe in Master instance.

This post is created by Santosh Mohanty . You can contact him for any questions at or message him on his linkedIn profile .