Wednesday, December 31, 2014

Spring Integration - Introduction

In this blog post and the subsequent post, I'm going to write about Spring Integration and also share my experience in using Spring Integration in a live project.

To begin with, I will provide a brief introduction to Spring Integration framework and in the next post I will show how to apply it.

Much of the content of this post is taken from the Spring Integration official website Spring Integration Reference

What is Spring Integration?

Spring Integration is a Spring driven framework which supports message driven architecture and provides routing, transformation of messages and implements the common Enterprise Integration patterns, more importantly the "Pipes and Filters" pattern.

What is Pipes and Filter Pattern?

This is an Enterprise Integration pattern, which is applied, if multiple processing units are required to process a message and we need to increase reuse and also achieve decoupling.

The "filters" represent any component that is capable of producing and/or consuming messages, and the "pipes" transport the messages between filters so that the components themselves remain loosely-coupled.

Components of Spring Integration Framework:

There are 3 main components (as in Pipes and Filter pattern):
  1. Message 
  2. Message Channel
  3. Message Endpoint

Message:




Generic wrapper for any Java object combined with metadata used by the framework while handling that object. In the header, any arbitrary key/value could be stored. In other words, any POJO could be used as a Message.

Message Channel:




A Message Channel represents the "pipe" of a pipes-and-filters architecture. Producers send Messages to a channel, and consumers receive Messages from a channel. The Message Channel therefore decouples the messaging components, and also provides a convenient point for interception and monitoring of Messages.

Types of channels:
  1. Point to Point: At most one consumer can receive each Message
  2. Publish/Subscribe: Broadcast each Message to all of its subscribers
Another category of channels:
  1. Pollable Channels: Are capable of buffering Messages within a queue
  2. SubscribableChannel: Iimplemented by channels that send Messages directly to their subscribed MessageHandlers
There are various implementations available for each of the above channel types. For eg, QueueChannel, DirectChannel etc. 

Message Endpoints:

A Message Endpoint represents the "filter" of a pipes-and-filters architecture. This is the processing unit which acts on the message.

Types of endpoint:

  1. Transformer: Responsible for converting a Message's content or structure and returning the modified Message
  2. Filter: Determines whether a Message should be passed to an output channel or not
  3. Router: Responsible for deciding what channel or channels should receive the Message next (if any).
  4. Splitter: Responsible for splitting a message into multiple messages and then send each of those to its output channel.
  5. Service Activator: A generic end point. We can configure a service provider and a service method with custom logic.
  6. Aggregator: Combines multiple messages into one (opposite of Splitter).
  7. Channel Adapter: Connects a Message Channel to some other system or transport.
Types of Channel Adapter:



  1. Inbound adapter: An inbound "Channel Adapter" endpoint connects a source system to a MessageChannel.
  2. Outbound adapter: An outbound "Channel Adapter" endpoint connects a MessageChannel to a target system.



Saturday, December 27, 2014

HTML5 Canvas - Basics

In this post we will take a look at the HTML5 Canvas element and how to use it.


What is canvas?

HTML5 canvas element provides platform to draw stuff on it and also animate them.


How to create a Canvas?

Canvas is a html5 element, which is created as below:

<canvas id="mycanvas" width="578" height="200"></canvas>

How to get a handle to the canvas?

In order to draw shapes or write text into the canvas, we need to get a handle to the canvas object. This could be done in javascript as below:

<script>

      var canvas = document.getElementById('myCanvas');

      var context = canvas.getContext('2d');

	  //TODO

</script>

Entire html code:

<!DOCTYPE HTML>

<html>  

  <body>

    <canvas id="myCanvas" width="578" height="250"></canvas>

    <script>

      var canvas = document.getElementById('myCanvas');

      var context = canvas.getContext('2d');

      //TODO	  

    </script>

  </body>

</html> 
The TODO line above is where we start writing javascript code to draw shapes etc and play around with the canvas. The code in the following sections are intended to be placed after the TODO.


How to draw a line?



Lines are drawn from the current position of the cursor till the destination x and y coordinates provided. Note that the coordinates are relative points from top left corner of the canvas.

To move the cursor around, we can use the moveTo function.

The width of the line could be set using the lineWidth attribute of canvas.
The color of the line could be set using the strokeStyle attribute of canvas. You can give either rgb values or hex values.


context.beginPath();
//move the cursor to position (100,200)
context.moveTo(100, 200);
//draw line from (100,200) to (400,100)
context.lineTo(400, 100);
//set line width
context.lineWidth = 10;
//set line color
context.strokeStyle = '##FE2E2E';
context.stroke();



How to draw an arc?


To draw an arc, we need to specify the coordinates of the center of the circle and also the radius. The start and end angles decide how big or how complete the arc should be relative to the circle. Whether the arc should be drawn in clockwise/counter clockwise is decided by the last parameter (boolean).

context.beginPath();
var centerX = 250;
var centerY = 150;
var startAngle = 0.4 * Math.PI;
var endAngle = 1.8 * Math.PI;
var radius = 50;
var counterClockwise = false;
context.lineWidth = 5;

context.arc(centerX, centerY, radius, startAngle, endAngle, counterClockwise);
context.stroke();


How to draw a circle?

Circle is a special case of arc, where the start angle is 0 and end Angle is 2* Math.PI.

How to draw a rectangle?


To draw a rectangle, use the rect() function, which takes the x and y coordinates of the top left corner of the rectangle, along with width and height.

context.beginPath();
var x = 100;
var y = 100;
var width = 300;
var height = 200;
context.rect(x, y, width, height);
context.fillStyle = 'red';
context.fill();
context.stroke();




Wednesday, November 26, 2014

HTML5 Form Fields

In this post I'm going to write about HTML5 form fields. HTML5 has introduced a lot of input controls, which would otherwise been very tedious to code using javascript.


Note that if the browser does not support any of these controls, it would just render a plain text field.

1. Color Picker:
<input type="color"/>


2. Range slider
This input type displays a slider within min and max range of values.
<input type="range" min="10" max="80"/>

3. Date 
<input type="date"/>
4. Email
<input type="email"/>
5. URL 
<input type="url"/>

6. Datalist 
<input type="text" list="states"/>
 <datalist id="states"> 
        <option value="CA"> 
        <option value="TX"> 
        <option value="FL"> 
</datalist>
The datalist input type provides a suggestion list drop down while entering data in the text field.
7. Search 
<input type="search"/>
The search input type would provide a google search kind of look and feel with cross button.

Monday, September 15, 2014

Agile and Scrum Methodology - Estimation

In this post, I'm going to talk about estimating in agile.

In agile world, before sprint planning happens, the team would go through the backlog and estimate them in terms of Story Points. This would provide a relative high level estimate for the team/management so that they can proceed with Sprint planning.

Story Points:

Story Pointing is a technique wherein the team gets together and understands the high level requirements for each story and provides a rough number indicating the complexity of the story. The team would brainstorm on the high level requirements and come to a consensus on the story points. If team members disagree, then they have to give justification on why they disagree and try to arrive at a consensus. (Scrum master can play the role of moderator in these discussions).

Story Pointing is NOT time based, but rather, is based on complexity.
The rationale here is that some tasks would take less time but are complicated and needs more focus than few other tasks which could consume more time but are less complicated. For instance, documentation can consume same amount of time as building a small UI, but UI building could be more challenging than documentation. Consequently, the team can give a higher story point to UI building and lesser one to documentation.


Representation of Story points:

The Story points could follow any representation. Following are the few widely used ones:
1. Fibanocci series as in, 1,1,2,3,5... 
2. T-Shirt size XL, L,M,S etc

Remember, this is just a relative figure and this depends on individual projects. So a XL for one project could differ from a XL for a different project.

Story Pointing is generally done well before Sprint planning wherein the requirements are not very detailed.

During Sprint planning, the team will take each story and discuss the detailed requirements. They then breakdown each story into smaller tasks and provide a time estimate for the same. The time estimate here would not have any bearing on the story points given earlier. 

It is assumed that the story points reflect the estimates when requirements were at less detailed level and that is why the relative points for each story will tell the same story :).

Velocity:

Velocity is a measure of the pace at which the team delivers stories during each sprint. For eg, if the total story points delivered by a team during consecutive sprints is 30,34,30 then we can calculate an average velocity as 32.


Tuesday, August 19, 2014

Agile and Scrum Methodology - Product and Sprint backlog

In this post, we are going to see what is a Product backlog and what is a Sprint backlog and the differences between the two.


Product backlog:

The product backlog is an ordered list of everything that might be needed in the product and is the single source of requirements for any changes to be made to the product.

A product backlog contains a list of product backlog items. The items could be in the form of:
  1. Story - short description of what the user wants from the product (eg., As a online retailer I need a catolog of products to be displayed).
  2. Bug
  3. Epic - represents bigger user stories
The items which are of high priority will be at the top of the backlog. The product backlog is maintained and managed by the product owner. 

Progressive Refinement:

It is a process wherein items at the top of the backlog will have more details into it than the ones at the bottom of the backlog. With time, and as and when the the backlog items at the top are completed, rest of the items are detailed out. This is similar to "Progressive Elaboration" technique used in typical project management process.

Sprint backlog:

This is a subset of the product backlog, and contains the items which will be completed by the team in the active sprint. Before the start of the sprint, the team will get together and identify items in the product backlog, which could be completed as part of the sprint. Those identified items will be moved to the sprint backlog. Thus, the items move from Product backlog to the Sprint backlog and get completed. New items should never be directly added to the Sprint backlog. They should always be added to the Product backlog and taken from there.

Sprint backlog is :
  • maintained by the team.
  • can contain additional tasks/stories which are decomposed from the product backlog item
  • updated daily during an active sprint




Sunday, August 3, 2014

Agile and Scrum Methodology - Roles and Responsibilites

In this post, we will talk about the various roles and responsibilities associated with Scrum.

In scrum, generally there are 3 distinguished roles as follows:

  • Product Owner
  • Scrum master
  • The Team

1. Product Owner

The role of a Product Owner is very crucial in the making the product a success in the market, as it deals with the "What" and the "Why" of the product.

  • Is one who has a product vision on how the product should look like, what should be its features etc. Unsurprisingly, the product owner should have very good domain expertise.
  • Communicates with various stakeholders like sponsor, client, end users and gathers requirements.
  • Also responsible for end user satisfaction, has overall commitment to product road map.
  • Also responsible for ROI (return on investment) and work out the budget constraints.


2. Scrum master

Scrum master is more of a facilitator and a coach who gives valuable advice to the team. The roles include:

  • Make sure everybody is following scrum process
  • Provide advice when needed on right process to be followed.
  • Work towards resolving issues which affect team's productivity (could be external factors, Organizational behaviour/culture, external dependencies)
  • Protect the team from distractions and help the team stay focused.

What a scrum master is not?

  • A scrum master doesn't have control over the team, but has control over the process.
  • The scrum master is not accountable to the outcome of the project.
  • The role of a scrum master is not the same as that of a Project Leader or a Project Manager. In Scrum, it is more of a servant-leader role.


3. The team

The team consists of Development  team and the QA team. All of the action happens here. The roles of a team include:

  • Design, implement the product features
  • Brain storm technical challenges and come up with solution
  • Build, test

The important deviation in the characteristics of a team from that of Waterfall model, is that the team is self organized and self dependent, rather than depending on a project manager to dictate and monitor tasks.

One of the key reasons for this is that, numerous researches found and concluded that, employees are more motivated and driven by passion, when they have  freedom and when there is collective collaboration rather than single person dictating terms.

So, here "THE TEAM" does everything. Collaboration is the key here, where the entire team works as a single unit towards a common goal. It also helps in ironing out egotistic issues, personal biases and the team as a unit solves issues and advances towards the goal. 

Tuesday, July 29, 2014

Agile and Scrum Methodology - Introduction

In this post (and a a few more to come), I will be writing about Agile methodology and how it works.

What is agile?

Agile is a methodology, a way of managing projects which is emerged as an alternative to traditional software management (also termed as "Waterfall" model).

In Waterfall model, we perform the following:

  1. Team gathers requirements
  2. Team comes up with design and architecture 
  3. Team implements (coding)
  4. Release it to market

Now, lets say it is a huge project and took around 6 months to complete. At the end of six months, when the product is released, the team realizes that this is not what the customer wanted or the market conditions have changed and the customer wants lot of modifications to the product. 

There is only one shippable deliverable in this process and that was produced at the end of 3rd step, which took months together.

Clearly, there is a problem with this process.

Why Agile?

Agile as the name suggests is a process which allows the stakeholders of the project to quickly adapts to the changing conditions.
This process focuses on smaller iterations and each iteration produces an increment of shippable deliverable.

So, an agile process looks like:

Iteration 1:

  1. Team gathers requirements
  2. Team comes up with design and architecture 
  3. Team implements (coding)
  4. Release it to market


At end of Iteration 1 :Inspect and adapt

Iteration 2:

  1. Team gathers requirements
  2. Team comes up with design and architecture 
  3. Team implements (coding)
  4. Release it to market

So, after every iteration, all the stakeholders introspect on what went wrong and what could be made better and also take stock of the market conditions etc.
So, at the end of 6 months, agile process will produce a product which is in line with what the customer wanted.

There are different subsets of agile methodology like 'Extreme programming', 'Feature driven development', 'Scrum' etc. So Scrum is one subset of Agile methodology.

What is Scrum?

The idea of scrum (as derived from the Rugby game) is to take the entire team take smaller steps towards a common goal. Projects are divided into smaller units of work called 'Sprint' which are typically one week, two weeks, or three weeks in duration.

At the end of each sprint, all the stakeholders meet to evaluate the team's progress and plan their next sprint.



Thursday, January 9, 2014

Security Questions and password security in Web Applications

Security questions:

Today almost every web application uses security questions to identify the user, especially when the user forgets password. 

However these security questions pose a major security risk, if they are not properly thought of. Most of the times we come across simple questions like 'In which city you were born' ,'What is your favorite movie' etc. 
Nowadays there is so much information on social networking sites, that a little research will give us all the information needed. Information on favorite movie/actress etc, can be mined by following the 'likes' the user has clicked.

The questions have to be smart enough to avoid questions on events which occurred in the person's life, and also avoid questions on person's taste and likes. 

Rather, the questions should evoke answers (sometimes strange) which cannot be guessed. How about these questions:

  1.  'Name a city which you never visited', (definitely this will have a larger answer set)
  2.  'Mention a name which you consider very funny' (few people can hack names like 'hay focker' P.S pun intended)

Password Rules:

Also, the application should have strict password rules to defeat dictionary attacks. The user should be forced to enter alphanumeric and special characters. 

The  application should maintain a list of black listed passwords. It should not accept black listed passwords like 'welcome 123','password 123'. A recent survey has shown that these two are most used passwords. The black list should be updated regularly based on industry findings. 

Password Storage:

The passwords should be stored as one way hash (instead of encrypting) which makes it difficult to retrieve the password. 
You might have read about instances, where in, hackers post all the passwords online after hacking the database. This wouldn't have happened if the passwords were stored as one way hash. SHA-2 is the latest algorithm for hashing. 
We can apply a strongly generated salt to the algorithm and also we can generate hash of hash, some N number of times in order to prevent a brute force attack.