Sunday 24 March 2013

Salt n Pepper Image Noise Reduction



Noise reduction

Noise reduction is the process of removing noise from a signal. Noise reduction techniques are conceptually very similar regardless of the signal being processed, however a priori knowledge of the characteristics of an expected signal can mean the implementations of these techniques vary greatly depending on the type of signal.

All recording devices, both analogue and digital, have traits which make them susceptible to noise. Noise can be random or white noise with no coherence or coherent noise introduced by the devices mechanism or processing algorithms. In electronic recording devices, a major form of noise is hiss caused by random electrons that, heavily influenced by heat, stray from their designated path. These stray electrons influence the voltage of the output signal and thus create detectable noise.

In the case of photographic film and magnetic tape, noise (both visible and audible) is introduced due to the grain structure of the medium. In photographic film, the size of the grains in the film determines the film's sensitivity, more sensitive film having larger sized grains. In magnetic tape, the larger the grains of the magnetic particles (usually ferric oxide or magnetite), the more prone the medium is to noise.
Images taken with both digital cameras and conventional film cameras will pick up noise from a variety of sources. Many further uses of these images require that the noise will be (partially) removed - for aesthetic purposes as in artistic work or marketing, or for practical purposes such as computer vision.


Types
In salt and pepper noise (sparse light and dark disturbances), pixels in the image are very different in color or intensity from their surrounding pixels; the defining characteristic is that the value of a noisy pixel bears no relation to the color of surrounding pixels. Generally this type of noise will only affect a small number of image pixels. When viewed, the image contains dark and white dots, hence the term salt and pepper noise. Typical sources include flecks of dust inside the camera, or with digital cameras, faulty CCD elements.
Images with Salt and Pepper Noise


With 10% noise


With 75% noise


In Gaussian noise, each pixel in the image will be changed from its original value by a (usually) small amount. A histogram, a plot of the amount of distortion of a pixel value against the frequency with which it occurs, shows a normal distribution of noise. While other distributions are possible, the Gaussian (normal) distribution is usually a good model, due to the central limit theorem that says that the sum of different noises tends to approach a Gaussian distribution.
In either case, the noises at different pixels can be either correlated or uncorrelated; in many cases, noise values at different pixels are modelled as being independent and identically distributed, and hence uncorrelated. Most of these noise reduction techniques assume the presence of salt and pepper type of impulse noise. The detection of salt and pepper type of noise is relatively easy as there are only two intensity levels in the noisy pixels.


Median filter

In signal processing, it is often desirable to be able to perform some kind of noise reduction on an image or signal. The median filter is a nonlinear digital filtering technique, often used to remove noise. Such noise reduction is a typical pre-processing step to improve the results of later processing. Median filtering is very widely used in digital image processing because under certain conditions, it preserves edges whilst removing noise.

Median filtering is a nonlinear process useful in reducing impulsive or salt-and-pepper noise. It is also useful in preserving edges in an image while reducing random noise. Impulsive or salt-and pepper noise can occur due to a random bit error in a communication channel. In a median filter, a window slides along the image, and the median intensity value of the pixels within the window becomes the output intensity of the pixel being processed. For example, suppose the pixel values within a window are 5, 6, 55, 10 and 15, and the pixel being processed has a value of 55. The output of the median filter an the current pixel location is 10, which is the median of the five values.


Progressive Switching Median Filter for the Removal of Impulse Noise from Highly Corrupted Images
A new median-based filter, progressive switching median (PSM) filter, is proposed to restore images corrupted by salt–pepper . A general framework of switching scheme-based image filters. impulse noise.
The algorithm is developed by the following two main points:
1) switching scheme—an impulse detection algorithm is used free image should be locally smoothly varying, and is separated by before filtering, thus only a proportion of all the pixels will be filtered edges [4]. The noise considered by our algorithm is only salt–pepper
2) progressive methods—both the impulse detection and the noise filtering procedures are progressively applied through several iterations. Simulation results demonstrate that the proposed algorithm is better than traditional median-based filters and is particularly effective for the cases where the images are very highly corrupted. impulsive noise which means:
1) only a proportion of all the image pixels are corrupted while other pixels are noise-free .
2) a noise pixel takes either a very large value as a positive impulse or a very small value as a negative impulse.
The progressive switching median (PSM) filter implements a noise detection algorithm before filtering. Both noise detection and filtering procedures are progressively repeated for a number of iterations

An Improved PSM Filter for Removing Impulse Noise
 
A new impulse-noise removing filter, which is composed of a improved PSM noise detector and a spline filter, is proposed. Using this filter, undetection of the noises can be avoided by controling the judgement value which is around maximum or minimum pixel value. In addition, it can also be possible to reduce mis-detection of the noises because the noise detecting threshold value can be set to a larger value. As a result of reducing both of undetection and mis-detection, proposed filtering method provides a good performance to remove impulsive noises. And the validity of the proposed method has been confirmed by computer simulations.

This algorithm sets a limit on the number of good pixels used in determine median and mean values, and substitute impulse pixel with half of the value of the summation of median and mean value. Experimental results show that the proposed algorithm performs a better noise filtering ability as the images are highly corrupted.

Thursday 21 March 2013

GWT Slider



GWT Slider


How to implement slide-bar in GWT is discussed over here. Side bar is of two type Horizontal and Vertical Slider-bars. Each Slider-Bar build using different widgets, some are required and other is optional. Required widgets are Drag widget and Scale widget, and optional are less widget and more widget. Slider-Bar may include only one drag element and only one scale element. Slider-Bar may include zero or more 'less' and 'more' elements. 



This can be simple achieved by following 3 steps:


STEP 1:

Download JAR from sidebar https://code.google.com/p/gwt-slider-bar/downloads/detail?name=gwt-slider-bar-1.0.jar
Add the jar to your GWT project build path
Add this line to your *.gwt.xml file
<inherits name="com.kiouri.sliderbar.SliderBarMVP" />

STEP 2:

Create a class which extends SliderBarHorizontal or SliderBarVertical, up on your need.
WaterTalkHorizontalSlider class is given below.

import com.google.gwt.user.client.ui.Image;
import com.kiouri.sliderbar.client.view.SliderBarHorizontal;
public class WaterTalkHorizontalSlider extends SliderBarHorizontal{
         public WaterTalkHorizontalSlider (int maxValue, String width) {
          setLessWidget(new Image("img/slid/less.png"));
          setMoreWidget(new Image("img/slid/more.png"));
          setScaleWidget(new Image("img/slid/scale.png"), 100);
          setMoreWidget(new Image("img/slid/more.png"));
          setDragWidget(new Image("img/slid/drag.png"));
          this.setWidth(width);
          this.setMaxValue(maxValue);        
      }
}



Use custom images or widgets over here it make it more intuitive and user friendly.
You can set the less widget, More widget, Scale widget, drag widget, width and max value etc.


STEP 3:

Create instance of above class and customize it and use it where ever you needed.

WaterTalkHorizontalSlider sliderBar = new WaterTalkHorizontalSlider(50, "600px");
sliderBar.drawMarks("white",50);
              sliderBar.setMinMarkStep(3);
              sliderBar.setNotSelectedInFocus();
              sliderBar.setValue(5);
              container.add(sliderBar);
      
That’s it.

Tuesday 19 March 2013

Downloading file from GWT



Downloading file from GWT

Last time I was discussed about how to create an app to host in google appspot.com, which provides to upload file and show it up on request. In this post I covered first portion, GWT file uploading and saving it to database as a blob object, in this section  I 
would like to show how can we download the file using persistence manager factory.

Configuration to be done are discussed in the previous section(Link).

what additionally needed is adding a doGet() method and its defenision, also a client side mechanism to request the file.

STEP 1: add doGet() body in "WaterTalkUploadService.java"

 doGet(req,resp){
     resp.setContentType("text/plain");
     resp.setHeader("Content-Disposition", "attachment; filename=output.txt");
     PrintWriter out = resp.getWriter();
     out.println("This is the output content");
     out.println("Probably something dynamic should go in here:::::");


     PersistenceManager pm = null;
         try {
                pm = PMF.get().getPersistenceManager();
                javax.jdo.Transaction transaction = pm.currentTransaction();
                Extent e = pm.getExtent(WaterTalkFiles.class, true);
                Iterator iter = e.iterator();
                String returns = "";
                WaterTalkFiles file  =  (WaterTalkFiles)iter.next();
                Blob blob = file.getData();
                byte[] buffer = blob.getBytes();
                String s = new String(buffer);
                out.println(s);
         } catch (Exception e) {
                e.printStackTrace();
         } finally {
                if (null != pm)
                      pm.close();
         }
 }



 STEP 2: Create a WaterTalkFileDownloading.java class

 add this to its body

    final String url = "/FileUploadByWaterTalks";
    String name = "output.txt";

    Anchor link1 = new Anchor(name);
    RootPanel.get().add(link1);
    link1.addClickHandler(new ClickHandler() {
      public void onClick(ClickEvent event) {
        Window.open(url, "_blank", "");
      }
    });

    Anchor link2 = new Anchor(name);
    RootPanel.get().add(link2);
    link2.addClickHandler(new ClickHandler() {
      public void onClick(ClickEvent event) {
        Frame f = new Frame(url);
        f.setSize("600px", "400px");
        f.getElement().getStyle().setBorderWidth(0, Unit.PX);
        RootPanel.get().add(f);
      }
    });
    
    Hope all other configuration explained in uploading section is kept as it was. 
    Thanks :)
    

Sunday 17 March 2013

ഗോവണി [Language Malayalam]

ഗോവണി 

2006 കെമിസ്ട്രി ബ്ലോക്ക്‌ ഗോവണി 
സമയം : 1.35 പകൽ 
ഞാൻ ആദ്യം:
നെറ്റിയിൽ ,
പിന്നെ കവിളിൽ . . . ഇടതും വലതും 
വീണ്ടും നെറ്റിയിൽ ...
പകച്ചു നിന്നു...
പിന്നെ രണ്ടും കല്പിച്ചു ചുണ്ടിലെക്.

.... 
പിന്നെ , 
ഫുൾ സ്റ്റോപ്പ്‌ ആണെന്ന് കരുതിയത്‌ കോമ ആയിരുന്നു ...
അവിചാരിതം.
ആകസ്മികം.
നിശബ്ദം.
എന്തും പറയാം...

...
പിന്നെ, 
കലടിയോച്ചകൾ
ഞങ്ങൾ ഓടി മറിഞ്ഞു...

Saturday 16 March 2013

GWT File uploading and save it to DB


File uploading in GWT, and save it to DB

How to create an app to host in google appspot.com, which provides to upload file and show it upone request from client side. Kind of tricky things to develop some diffrent apps :), we too found it will help to develop some good apps, so decided to post how we done it  by using jdo.

4 steps todo it.

STEP 1:

Create an app and add commons-fileupload-1.2.2.jar and commons-io-1.4.jar to project build path.

STEP 2:

In server side:

  1.  Create a Persistance Manager Factory provider class "PMF.java"
  2.  Create a file storing entity class "WaterTalkFiles.java"
  3.  Create file uploader service name it "WaterTalkUploadService.java"
---------------------------------------------------------PMF.java----------------------------------------------------------
package com.de.watertalks.server;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManagerFactory;

public final class PMF {
private static final PersistenceManagerFactory pmfInstance = JDOHelper.getPersistenceManagerFactory("transactions-optional");//"transactions-optional"

private PMF() {
}

public static PersistenceManagerFactory get() {
return pmfInstance;
}
}
----------------------------------------------------WaterTalkFiles.jav------------------------------------------------
package com.de.watertalks.server;

import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Blob;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class WaterTalkFiles {
@PrimaryKey
String filename;
Blob data;
public WaterTalkFiles(String fname,byte[] b){
filename = fname;
data = new Blob(b);
}
}
-------------------------------------------WaterTalkUploadService.java----------------------------------------

package com.de.watertalks.server;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.jdo.PersistenceManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItemIterator;
import org.apache.commons.fileupload.FileItemStream;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

@SuppressWarnings("serial")
public class WaterTalkUploadService extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ServletFileUpload upload = new ServletFileUpload();

try {
FileItemIterator iter = upload.getItemIterator(request);

while (iter.hasNext()) {
FileItemStream item = iter.next();

String name = item.getFieldName();
InputStream stream = item.openStream();

// Process the input stream
ByteArrayOutputStream out = new ByteArrayOutputStream();
int len;
byte[] buffer = new byte[8192];
while ((len = stream.read(buffer, 0, buffer.length)) != -1) {
out.write(buffer, 0, len);
}
//save file
WaterTalkFiles file = new WaterTalkFiles(name, buffer);
PersistenceManager pm = null;
             try {
                    pm = PMF.get().getPersistenceManager();
                    javax.jdo.Transaction transaction = pm.currentTransaction();
                    transaction.begin();
                    WaterTalkFiles guest = new WaterTalkFiles(name,buffer);
                    pm.makePersistent(guest);
                    transaction.commit();
             } catch (Exception e) {
                    e.printStackTrace();
             } finally {
                    if (null != pm)
                          pm.close();
             }
}
} catch (Exception e) {
throw new RuntimeException(e);
}

}
}



STEP 3:


  • In client side, create file uploading composite component class "WaterTalksFileUploadingComponent.java"


package com.de.watertalks.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FileUpload;
import com.google.gwt.user.client.ui.FormPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class WaterTalksFileUploadingComponent extends Composite{

final FormPanel form = new FormPanel();
VerticalPanel vPanel = new VerticalPanel(); 
FileUpload fileUpload = new FileUpload();
Label maxUpload =new Label();
 
public WaterTalksFileUploadingComponent(){

form.setMethod(FormPanel.METHOD_POST);
   form.setEncoding(FormPanel.ENCODING_MULTIPART); //  multipart MIME encoding
   form.setAction("/FileUploadByWaterTalks"); // The servlet FileUploadGreeting
   form.setWidget(vPanel);
   fileUpload.setName("uploader"); // Very important    
   vPanel.add(fileUpload);    
   maxUpload.setText("Maximum upload file size: 1MB");
   vPanel.add(maxUpload);
   vPanel.add(new Button("Submit", new ClickHandler() {
       public void onClick(ClickEvent event) {
               form.submit();
       }
   }));
   initWidget(form);

}
}




STEP 4: 

Add the following snippet to web.xml in 

<!-- de-water-talks file uploader service -->
<servlet>
 <servlet-name>
  FileUploadByWaterTalks
 </servlet-name>
 <servlet-class>
  com.de.watertalks.server.WaterTalkUploadService
 </servlet-class>
 </servlet>
 <servlet-mapping>
 <servlet-name>
  FileUploadByWaterTalks
 </servlet-name>
 <url-pattern>
  /FileUploadByWaterTalks
 </url-pattern>
</servlet-mapping>


Now create an instance of file uploader component you created and add it  to proper location in your module and run the onModule class. So far uploading is compleate. Now downloading :) Will our next post.





Generate all combinations by java Program



Generate all combinations by java Program

In this post we are going to brief you, how to disclose all combination of passwords or you want all combinations of some numbers or words or characters  for some programming or gaming logic this is the best function we think can be used for. As usual before going to source code, simple intro to combinations and permutations :)

 it's few points to be noted:
If the order does matter it is a Permutation and order doesn't its Combinations.

What's the Difference?
In English we use the word "combination" loosely, without thinking if the order of things is important. In other words:

"My fruit salad is a combination of apples, grapes and bananas" We don't care what order the fruits are in, they could also be "bananas, grapes and apples" or "grapes, apples and bananas", its the same fruit salad.
   
"The combination to the safe was 472". Now we do care about the order. "724" would not work, nor would "247". It has to be exactly 4-7-2.
So, in Mathematics we use more precise language:
If the order doesn't matter, it is a Combination.
If the order does matter it is a Permutation.
Now what we brief here is a solution for this  :
"Generate  all combination of '123456asdqwezxc' of lenth=3, with out repetation"



  private void permutation(String prefix, String str,int length) {
        int n = str.length();
        if (prefix.length()==length) {
            System.out.println(prefix);
        } else {
            for (int i = 0; i < n; i++) {
                permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i + 1, n),length);
            }
        }
  }

for our solution we call this method like this:  permutation("", "123456asdqwezxc",3) 


And the result is:


run:
123
124
125
126...


Friday 15 March 2013

File to Byte Array and vice verse



FILE TO BYTE & BYTE TO FILE

Converting a file to byte array and retrieving it from that, mostly used in programming world especially in case of storage purposes. Here we show how simply we can achieve it with java File Stream operators - "FileInputStream, FileOutputStream".
     
     Source Code:


public static void main(String[] args) {
        System.out.println("START");
        byte[] byteArray = null;
        FileInputStream fin = null;
        FileOutputStream fout = null; 
        try {
            fout = new FileOutputStream("D:\\WaterTalksOut.pdf");
            fin = new FileInputStream("D:\\WaterTalksIn.pdf");
            byteArray= new byte[fin.available()];
            fin.read(byteArray);
            fout.write(byteArray);
        System.out.println("END");    
        } catch (Exception ex) {
            Logger.getLogger(FileOperations.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println("END WITH ERROR");
        }
}

Thursday 14 March 2013

5 GWT 2.5 new features




2.5 Features

  1. Super Dev Mode (experimental)
  2. Elemental (experimental)
  3. New compiler optimizations
  4. Updated ARIA support
  5. UIBinder Enhancements
  6. Validation Enhancement

Super Dev Mode (experimental)

Super Dev Mode is an experimental replacement for Development Mode.

Elemental (experimental)
Elemental is an experimental new library for fast, lightweight, and "to the metal" web programming in GWT. It's intended for developers who are comfortable working with the browser API's that JavaScript programmers use.

New compiler optimizations

The GWT compiler can optionally use the Closure compiler to provide additional JavaScript optimizations. The Closure compiler has a collection of Javascript optimizations that can benefit code size, including a graph-coloring-based variable allocator, comprehensive JavaScript function and variable inlining, cross-module code motion, statement fusing, name shadowing and many more. However, this makes the GWT compiler slower, so it's not enabled by default. Simply add the -XenableClosureCompiler to the list of compiler flags to enable optimization.
Large projects that use Code Splitting and have many split points can take advantage of Fragment Merging. The GWT compiler can automatically merge fragments to reduce the size of the "leftover" fragment.


Updated ARIA support
Added a new accessibility ARIA library that has a full coverage of the W3C ARIA standard. This makes it easier to correctly set ARIA roles, states, and properties on DOM elements. 


UIBinder Enhancements
GWT 2.5 adds extensions to UiBinder that allow it to support Cell rendering and event handling. In particular, this design enables UiBinder to generate a UiRenderer implementation to assist with rendering SafeHtml, and dispatching events to methods specified by @UiHandler tags. Also introduced the IsRenderable/RenderablePanel types. When used by an application instead of HTMLPanel, they can significantly improve rendering time and reduce the latency of complex UiBinder UIs.


Validation Enhancements
GWT 2.5 adds support for more features of JSR-303 Bean Validation specification and this support is no longer considered "experimental".

Testing GWT App with Junit GWTTestCase


Testing GWT App with Junit GWTTestCase

           Testing GWT App with Junit GWTTestCase GWT provides excellent support for automated testing of client side code using JUnit testing framework. How it is done and how do I made it happen, are demonstrated in this post. Hope even if I may use it for my future reference. :) 

           Before starting I had to to download the jar of JUnit which helps test GWT apps. Download JUnit archive from JUnit Official Site: http://www.junit.org (Download JUnit-4.10.jar). GWT provides GWTTestCase base class which provides JUnit integration. Running a compiled class which extends GWTTestCase under JUnit launches, the GWTTestCase is a derived class from JUnit's TestCase and it can be run using JUnit Test runner.

Let's demonstrate it with a simple class 
 
/** 
* GWT JUnit tests must extend GWTTestCase. 
*/ 
public class WaterTalkTest extends GWTTestCase{ 
/** 
* must refer to a valid module that sources this class. 
*/
           public String getModuleName(){ 
                       return"com.water.talks.WaterTalk"; 
           } 
           public void testMethodName(){ 
                       /** 
                       * tests the FieldVerifier. 
                       * test functionality of composite components 
                       * test service calls and verify it with the result values 
                       * use assert method to show separation in test results by success and failure categorizations. 
                       * */ 
           } 

            Run test cases in Eclipse using generated launch configurations. We'll run unit tests in Eclipse using the launch configurations generated by webAppCreator for both development mode and production mode. 

 RUN THE JUNIT TEST IN DEVELOPMENT MODE 

  • From the Eclipse menu bar, select Run > Run Configurations... 
  • Under JUnit section, select WaterTalkTest-dev, the class u need to run to test the app
  • To save the changes to the Arguments, press Apply 
  • To run the test, press Run 
If everything is fine with your application, this will produce result. 

RUN THE JUNIT TEST IN PRODUCTION MODE.

  • From the Eclipse menu bar, select Run > Run Configurations... 
  • Under JUnit section, select WaterTalkTest-prod
  • To save the changes to the Arguments, press Apply 
  • To run the test, press Run 

If everything is fine with your application, this will produce result:

Thank you for spending time on this post, hope you got some queries regarding this.

Wednesday 13 March 2013

Loggin management in GWT with sessionId


Loggin management in GWT with sessionId

If you don’t want to waste time reading my ‘good’ English can and must skip to ‘How to achieve’ section.

            As google provide lots of space and features to host an app all must think to develop a good site which provides a good user experience. Even when I came to develop one, first ‘STONE’ came between was a loggin management. As usual I thought to manage it via simple verification process, but still got so many security breach, when I google and ask to experts all say a common solution is to develop a session when a user loggin and use it to manage further transaction or interaction of client. So here I am going to brief what I did to make it happen on my google app.  As I told this is just a brief if you had queries or further solutions or extra  portions that you think must do with this, don’t forget to add it up , or at least link us to where the info is.

 Lets understand what actually session, and co-related word cookies and what it for.
             In computer science, in particular networking, a session is a semi-permanent interactive information interchange, also known as a dialogue, a conversation or a meeting, between two or more communicating devices, or between a computer and user (see Login session). A session is set up or established at a certain point in time, and torn down at a later point in time. An established communication session may involve more than one message in each direction. A session is typically, but not always, state full, meaning that at least one of the communicating parts needs to save information about the session history in order to be able to communicate, as opposed to stateless communication, where the communication consists of independent requests with responses.
An established session is the basic requirement to perform a connection-oriented communication. A session also is the basic step to transmit in connectionless communication modes. However any unidirectional transmission does not define a session.
           What is cookie?
           Also called a transient cookie, a cookie that is erased when the user closes the Web browser. The session cookie is stored in temporary memory and is not retained after the browser is closed. Session cookies do not collect information from the user’s computer. They typically will store information in the form of a session identification that does not personally identify the user.
         The main difference between cookies and sessions is that cookies are stored in the user's browser, and sessions are not. This difference determines what each is best used for. A cookie can keep information in the user's browser until deleted. If a person has a login and password, this can be set as a cookie in their browser so they do not have to re-login to your website every time they visit. You can store almost anything in a browser cookie. The trouble is that a user can block cookies or delete them at any time. If, for example, your website's shopping cart utilized cookies, and a person had their browser set to block them, then they could not shop at your website.

How to achieve

          Okay, it seems we know what we going to do. In brief we have to create some value to identify who is interacting through the service.  So needed to create an id, we can do it via, java.util.UUID, a class that represents an immutable universally unique identifier (UUID). A UUID represents a 128-bit value.  There exist different variants of these global identifiers. The methods of this class are for manipulating the Leach-Salz variant, although the constructors allow the creation of any variant of UUID.

So in GWT service when we have a success full login, I done like this:

            String sessionId = null;
                                  sessionId = UUID.randomUUID().toString();
                                  getUser.setSessionID(sessionId);
                                  pm.makePersistent(getUser);
                                  return sessionId;

So if valid user, new session id is stored with his information for each login, and it send back to client.
On client side store this id in browser and send it with each transaction and verify user by comparing the value stored in database with that user information.

Code to store value on client side or in browser:

@Override
              public void onSuccess(String result) {
                     Cookies.setCookie(SESSION_COOKIE_KEY_NAME, result);
              }

That’s it. Now upon your logic can implement a time out in server side to erase the value after a particular time. Or can create new id after each successful validation for high secured app. What if you know the session id stored in cookie and service to call!

J
Thanks
Any queries and doubt regarding this are welcoming...