Pages

Sunday, December 4, 2016

GIT




               It is the widely used Version Control System. It an actively maintained Open Source project initially developed  by Linus Torvalds, the famous creator of the Linux operating system kernel. 

     Git owns many forward characteristics compared to other software version control systems  in the fields of Performance, Security, Flexibility etc.  Some of the  especial characteristics are  stated below.


  • Committing changes, merging, branching are optimized for performance
  • Unlike other version control systems, Git is not fooled by the name of the file in determining the history  and it focuses on the file content.
  • Git  Repository are secured with cryptographically secure hashing algorithm SHA1. Thus protects the code and the change history against malicious change.
  • It supports various kinds of non-linear development  workflows 
 In this blog we will discuss on the Git branching feature and the Git Tag feature procedures. Thus is suitable for a one with the basic git command knowledge.


Git Branching  




There is a central repository referred to as the Origin.  Each developer push and pull to the origin. But besides the central push-pull relationship ,  there is an Decentralized  feature to form sub-teams and pull changes form these peers  before pushing the work to the Origin.

For that Git contains branching feature. What is the use of keeping the code in a separate branch.

  1. You are about to make an implementation of major or disruptive change
  2. You are about to make some changes that might not be used
  3. You want to experiment on something that you are not sure it will work
  4. When you are told to branch out, others might have something they need to do in master

 There are mainly two types of branches helpful for a systematic development procedure. They are
                                                           01) Main Branches
                                                           02) Supporting Branches


Main Branches

They are in the central repository and holds down two branches as master and develop. These two branches are parallel.

   Master        => main branch which reflects the source code in the production-ready state.

   Develop     => main branch which reflects the latest delivered development changes for the next   release.


As shown in the diagram, after the initial development version if there are any new features to be added these developments are done in the develop branch. 

When the source code in the develop branch reaches a stable point,and ready to released, then source code is merged with the master branch

Supporting Branches


Next to the main branches master and develop,  there are variety of support branches to support the parallel development between team members. 
Unlike main branches, these have a limited life time period, since they will be removed eventually.

These type branches are categorized by how we use them. for an instances, see the figure below with an Feature branch. 

Feature branches above are for the new feature developments for distant future releases.  The Feature branch will exist as long as the feature is in development. Eventually it is merged back to the develop branch which is shown in the figure.

Feature branch typically exist in developer repo only and not in origin.


Creating a feature branch

When developing a new feature, begin it in a feature branch. To begin it
                                         `$ git checkout -b myfeature develop`

Then you will checkout from the develop branch and switch to the branch "myfeature". Once the feature development is over in the supporting branch, changes have to be incorporated to the develop branch for them to be added to the upcoming release. 

For that  first switch to the develop branch
                                          `$ git checkout develop`

Then merge the myfeature branch to the develop branch. Here --no-ff flag always create a new commit object. This avoids  the loss of historical existence info of the feature branch
                                          `$ git merge --no-ff myfeature`

Then delete the feature branch as 
                                          `$ git branch -d myfeature`
Lastly push the committed change to the develop branch 
                                          `$ git push origin develop`



The first diagram shows the above described process. The second diagram shows the merge without the flag. 
  There are other two supply branches as Release branches and Hotfix branches. It is about the basic branching system of the Git. 



Git Tagging

 What is a tag in Git?

 Tag is used in the version maintenance of a software system. Tag is a way to mark a point in time in your repository.  In other words a tag represents the version of a  particular branch at a time whereas the branch is a separate thread of development.  

In Git we are not tagging branches and we are tagging commits.  We can say tag is an annotated pointer to a commit. It is shown in the figure below.

  Let's see some operations with tags. 

Listing Your Tags  => list all the available tags in Git

                                       $ git tag


                               => list tags with a particular pattern
                                     $ git tag -l "v1.8.5*"


Creating Tags        => two types of tags as lightweight and annotated

                                     lightweight tag is like a branch that doesn't change. Its just a pointer to a                                                specific commit.

                                     annotated tags are stored as full objects in Git database.  They contain                                                    information like tag name,  email, tag message, date etc. 
                                 
Annotated Tag Creation =>   $ git tag -a v1.4   -m "my version 1.4" 
                   -a specifies an annotated tag and -m for the tag message.
                                     using git show command information can be seen. 
       


Lightweight  Tags  Creation => $ git tag v1.4-lw 
                                                      This time git show command does not show any detail. Instead                                                                shows the command

















Saturday, September 17, 2016

ScreenCasting

What is Screen Casting... ?

                                                                             

        You might be aware of what is a "Screen Shot". It is a single picture of the screen of your computer.

        But in contrast to it "Screen Casting" is a digital video recording that captures actions taking place on a computer desktop. Screen casting normally contains voice over narration. 

        Thus it becomes a very useful methodology and a procedure in many scenarios to gain higher productivity. Following lists some common and useful instances of screen casting.


1.  To provide answers to some common asked questions of your employers
2. To hire the companys' new hires effectively and free up your time.
3. It is a very productive method to make a software or a product demo
4. To provide clear feedback
5. To create video tutorials


Have you ever wondered how to do this... ?? that is... how to show what's clearly happening on your computer screen...?  Thanks to Screencasting Software  anybody can do it now.

 There are a plenty of screen casting tools. Below lists few

 1.  Adobe Captive
                 -  quite expensive
                 - it takes longer time to work with this tool
                 - not advisable for beginners

2. Camtasia Studio
                 - not free
                 - but a powerful PC only software
                 - not recommanded for beginners

3.   Screenr
                  - web based, java tool, thus no installation
                  - need internet connection
                  - slow to use
                  - it doesn't let webcam to record

4. Jing
                  - same as Screenr
                  - only publishes videos in .swf format
                  - produced .swf videos cannot be converted to mp4 even with file-conversoin utilities

5. SnagIt
                  - overcome the frustrations of Jing
                  - can record for as long as you want
                 
6. Screemcast-O-Matic(SOM)
                 
                   - free
                   - ease of use
                   - records your webcam as well as your screen
                   - Java applet  available which needs no implementation







Friday, September 9, 2016

Configuring Tomcat For SSL


Tomcat is a Web Server for JSP pages. It comes in default for HTTP on port 8080. If required it can be configured to use SSL connection on port 8443.

If you are using Tomcat as a standalone web server, then it is a probably a good idea to configure Tomcat to handle SSL connections. But if you are fronting Tomcat with a web server, and Tomcat serves only as a application server or a Tomcat servelet container, then its BETTER to let the web server function as a proxy for all HTTPS requests and NOT configure Tomcat for SSL.

Why....?

Because in SSL connection the data is encrypted. All that encryption, decryption and handshaking are not just free. Its CPU intensive , thus slows down the transmission speed.

If another web server is used to serve the static content, Tomcat must be freed to focus on its specialty : delivering dynamic content and take data from web server as son as possible.

Following shows set of simple steps to carry out the Tomcat SSL configuration.


STEP 1
cd $JAVA_HOME/bin
Inside this directory is a folder named keytool which is responsible for generating a keystore file.


STEP 2

Then open the terminal

New keystore file is created in the home directory of the user.
keytool -genkey -alias tomcat -keyalg RSA

To specify a different location for the keystore file


keytool -genkey -alias tomcat -keyalg RSA
  -keystore /path/to/my/keystore

It'll ask for some questions .

IMPORTANT
First ask to enter the password for  keystore.  The default password is 'changeit '.  Better to provide the password of your Tomcat server. 

The next important fact is for the first name and last name (first question) provide the host name of the url you are accessing the application. Certificate exception might arise otherwise.





Now keystore file is created on your machine.


STEP 3

Now to configure the Tomcat server file , First move to the bin folder in tomcat installation directory.

Open using an editor and  find the following line
<!--
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
    maxThreads="150" scheme="https" secure="true"
    clientAuth="false" sslProtocol="TLS" />
-->

Modify it as follows after uncommenting
Connector SSLEnabled="true" acceptCount="100" clientAuth="false"
    disableUploadTimeout="true" enableLookups="false" maxThreads="25"
    port="8443" keystoreFile="/Users/loiane/.keystore" keystorePass="password"
    protocol="org.apache.coyote.http11.Http11NioProtocol" scheme="https"
    secure="true" sslProtocol="TLS" />

STEP 4

Now access the Tomcat service as https://localhost:8443. You can access default port 8080 too on http://localhost:8080

Here You Goo....  :)


STEP 5

By doing the above 4 steps, you can successfully enable the secure connection. But in order to avoid some common ssl related errors you might encounter when developing applications that communicates securely this step is gonna be very USEFUL....

Import the server certificate to the trusted Java key store.


  • First download the certificate from the server.
access the url of the service from Opera browser. A certificate related warning comes. View certificate details and then export it to hard drive.
  • move to $JAVA_HOME /bin folder. Execute the following command there.

keytool -import -alias _alias_name_ -keystore ..\lib\security\cacerts -file _path_to_cer_file








Thursday, August 25, 2016

populate a dropdown according to the selection in another dropdown


                      Suppose two dropdowns as dropdown1 andropdown2. I need to populate the dropdown2 with different values based on the selection in dropdown1. Following shows the two dropdown menus


<select class=" form-control" id="dropdown1">
    <option>--Select--</option>
    <option>Customer</option>
    <option>Staff Member</option>
</select>

<select class=" form-control" id="dropdown2" >
    <option value="None">None</option>
</select>




                    Following javascript code works fine. Values to be populated to dropdown2 are taken into two arrays. Switch statement is used to decide which array is to be populated based on the dropdown1 selection.

                     the function createFunction() will build up the <option> elements in the dropdown1 menu.  


function configureDropDownLists(ddl1,ddl2) {
    var customer= ['None','Name', 'Registered Period', 'Area'];
    var staff = ['None','Designation', 'Department', 'Branch'];


    switch (ddl1.value) {
        case 'Customer':
            ddl2.options.length = 0;
            for (i = 0; i < customer.length; i++) {
                createOption(ddl2, customer[i], customer[i]);
            }
            break;
        case 'Staff Member':
            ddl2.options.length = 0;
            for (i = 0; i < staff.length; i++) {
                createOption(ddl2, staff[i], staff[i]);
            }
            break;

        default:
            ddl2.options.length = 0;
            break;
    }

}

function createOption(ddl, text, value) {
    var opt = document.createElement('option');
    opt.value = value;
    opt.text = text;
    ddl.options.add(opt);
}
 

 
 
 
 Finally configureDropDownLists(ddl1,ddl2)  function is called on 
the dropdown1 menu as shown menu
 
<select class=" form-control" id="selectCustomer"    onchange="configureDropDownLists(this,document.getElementById('filterOption'))">
     
    <option>--Select--</option>
    <option>Customer</option>
    <option>Staff Member</option>
</select> 
 
 

Including a html file in another html

  • Using jQuery following code perfectly works

<html> 
  <head> 
    <script src="jquery.js"></script> 
    <script> 
    $(function(){
      $("#includedContent").load("b.html"); 
    });
    </script> 
  </head> 

  <body> 
     <div id="includedContent"></div>
  </body> 
</html>
 
 
  • By including an import 
<head>
  <link rel="import" href="/path/to/imports/stuff.html">
</head>
 
to access the content of the import use link element's .import property as below
 
 
var content = document.querySelector('link[rel="import"]').import; 
 
 
 
 



Sunday, July 24, 2016

Spring MVC



What is Spring MVC....??

                              The diagram below gives a general idea of what MVC is and its usage.



The Spring web MVC framework provides model-view-controller architecture and ready components that can be used to develop flexible and loosely coupled web applications. 



Model =>
represents the underlying, logical structure of data in a software
directly manages the data, logic and rules of the application.

View =>
represents the elements in the user interface
responsible for rendering the model data through the generated HTML

Controller =>
represents the classes connecting the model and the view
        communicate between classes in the model and view

The DispatcherServlet


In the Spring Web MVC framework we need an interface which handles the HTTP requests and make then reach the above mentioned 3 components. All the HTTP requests coming to the application first reach to the DispatcherServlet and then from there the requests are handled accordingly.

Its worth discussing the MVC Architecture functionality to get a general idea of how the HTTP requests are being served by Spring Web MVC.

The following shows the step-wise functionality referred with the below diagram


  • The DispatcherServlet first receives the request.
  • The DispatcherServlet consults the HandlerMapping and invokes the Controller associated with the request.
  • The Controller process the request by calling the appropriate service methods and returns a ModeAndView object to the DispatcherServlet. The ModeAndView object contains the model data and the view name.
  • The DispatcherServlet sends the view name to a ViewResolver to find the actual View to invoke.
  • Now the DispatcherServlet will pass the model object to the View to render the result.
  • The View with the help of the model data will render the result back to the user.


ican.png

This DispatcherServlet must be mapped before it can work with the correct functionality.


  • You need to map which requests are handled by which DispatcherServlet


  • This mapping is done by using a URL mapping in web.xml config file

  • Following shows the mapping for the HelloWeb DispatcherServlet
helloweb.png


  • <servlet> tag => initializes the dispatcherservlet named
                                                           HelloWeb .


  • <servlet-mapping> tag =>   indicates what URLs will be handled  by the which dispatcherservlet




  • Then the framework will try to load the application

       context from a file named [servlet-name]-servlet.xml

In this case it is : HelloWeb-servlet.xml

  • Following shows the above configured HelloWeb-servlet.xml dispatcherservlet.
  • Spring Configuration is done there
servlet-xml.png


Now lets  go through a simple Model, View and Controller  in  Spring MVC .
  • A class with @Controller is termed as the controller



handlermethod.png


  • Model is the business logic is defined inside the service method of the controller
  • Model is created within the method (in the method argument in above example)
  • Different model attributes are set and accessed by the view to present the output
  • In above model attribute set is message. And is accessed in the view view.png

Tips for writing a MVC Controller



01) Annotating a  class with @Controller is the simplest way of creating a controller

02) It returns the view name

03)For a controller to handle one request @RequestMapping at the beginning of the class

anno1.png
























04) For a controller to handle multiple different request @RequestMapping at the beginning of each method in the class

















05)  @RequestMapping  annotation can be used to specify multiple different URLs  to be handled by a single method



                        @RequestMapping({"/hello""/hi""/greetings"})


06) Specify the HTTP Request method in  @RequestMapping  annotation. 













07) Retrieve request parameters as regular parameters of the handler method by using @RequestParam
 annotation. This decouples the controller from the HttpServletRequest interface











Spring binds the method parameters username and password to the HTTP request parameters with the same names. 
That means you can invoke a URL as follows (if request method is GET):
http://localhost:8080/spring/login?username=scott&password=tiger

Some especial case scenarios of the @RequestParam annotation is shown below











































08) The simplest is returning  view name  from the model as a String as below







09) If additional data is needed to be sent to the view, return a  ModelAndView  object. There are 3 basic ways in declaring a ModelAndView object.


  • First method is to create a ModelAndView  object in handler method. The object holds the view name in its initiation











  • The second method is to declare ModelAndView object as a parameter of the handler method.
          Here view name is set for the model and objects are added to the model












  • declare as a parameter of type Map in the handler method. This map is used to store 
           objects for the  model










10) In case you want to redirect the user to another URL if a condition is met, 
just append redirect:/ before the URL. 











11) @ModelAttribute  is used to bind form fields to the form backing objects. 
       BindResult interface is used for validating form fields.