Posts

What is REST actually?

 REST is about creating representation(like JSON or XML or any other format.) of object's current state(like data in database) and transferring that representation over network. Rest is the set of constraint/convention. Resources are decoupled from their representation so that their content can be accessed in a variety of formats, such as HTML, XML, plain text, PDF, JPEG, JSON, and others. Metadata about the resource is available and used, for example, to control caching, detect transmission errors, negotiate the appropriate representation format, and perform authentication or access control At ground level , Rest is nothing more but a collection of principles  Communication should be stateless : Server should not store any state . If required it should be part of message  State should be representational : Internally resource at server can be in one form but it should be able to change it representation. An object referenced by one URI can have different forma...

How Kafka workflow works from 1000 feet view ?

Here is the high level workflow explaining how Kafka cluster works at 1000 feet Producer Side  1. Say Kafka cluster have one Topic with three partition(P1,P2,P3) on three nodes.  2. Each partition has two replica(R11, R12),(R21, R22),(R31, R32) on other nodes.  3. Cluster has a zookeeper.  4. On kafka startup, kafka elects the leader for each partition say out of P1, R11, R12 , P1 is the leader whereas R11 and R12 are followers.  5. Producer connects to Kafka cluster which can be any node in cluster and  get all metadata info on client side through kafka client side library.  6. Producer connects to leader partition  as leader is responsible for all read and writes.  7. Partition can be either specified/or selected at run time based on message key and no of partition/or round robin fashion.  8. Producer can go for any acknowledgement level i.e. fire and forget/leader acknowledgement/all insynch replica(ISR) acknowledgeme...

Association vs aggregation and vs composition

Association:-   Association is relationship where both container object and contained class has it own life cycle and no one is owner is here. Example :- Consider student is taught by multiple teachers where Student is container object containing list of teachers. So Teacher is contained object . What life cycle means here  Even student is deleted, teacher will continue to exist. What owner means here Same teacher can be associated more more student. So student is not owner of that teacher. What association means to developer It tells clearly to developer when student is deleted , teacher can stay in memory(or DB) if required . May be it can be associated with further students Aggregation:-   Aggregation is relationship where both container object and contained object has it own life cycle and but container object is the  owner of contained object . It is represented by has a relationship. Example :- Consider department has multiple teachers. Wh...

When to use Java 8 Optional instead of traditional null pointer check ?

My project has recently moved to Java 8. Now, I see applications flooded with Optional objects mainly to check the Null Pointer on an object. Before Java 8  code style to check the null pointer Employee employee = employeeServive.getEmployee(); if(employee!=null){     System.out.println(employee.getId()); } After java 8  code style to check the null pointer Optional<Employee> employeeOptional = Optional.ofNullable(employeeService. getEmployee()); // Another way of implementing above  where service itself will return Optional<Employee> employeeOptional = employeeService.getEmployee(); if(employeeOptional.isPresent()){     Employee employee = employeeOptional.get();     System.out.println(employee.getId()); } Which one is better to check Null Pointer I see  style 1 is better when intention is just to check Null Pointer. So I find, style 1 is more clear and lesser lines of code. In this case I see devs are...

How to solve javax.net.ssl.SSLHandshakeException ?

This blog is about how two secured web application on SSL can communicate with each other without get certificate error i.e. SSLHandshakeException Error developer generally face When web_application_A with self signed certificate  tries to connect to web_application_B (with same self signed certificate), sometimes you must have got below error detailed message sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target cause javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target Details oF mine environment :-  I got same error . Here are the environment details Webserver :- Tomcat -6 OS :- Windows 7 Java Version :- 1.6 web_application_A :- Port 8443 web_applicat...