Friday, November 1, 2013

Servlet, the way you see it

Hey, have you ever thought of having a book from library ?
Of course, I have done that. Do you think that, I don't read books ?

No,  never. In fact reading books is a good hobby indeed.
Hey, I know that very well. Let's come to the straight point. Don't you think that easy way ?

Well, of course yes. Today I am going to tell you how a library system works.
I don't know why you are doing this. STILL GO ON.

Let's assume that you are going to issue a book on Hibernate.

You went to a library to get a book "JUST HIBERNATE" by O'rEILLY of 2nd Eddition. You meet the librarian and she asked you to fill up a requisition slip. You filled the slip which has three columns
  1. Name of the book
  2. Name of the publisher - O' REILLY
  3. Edition- 2nd Edition
You give this slip to librarian . Now librarian will read the request and will check in the register which bookshelf is having the book you  requested and will go to the shelf and find out the book and will hand it over to you.

Is that the way you borrow a book ?
Yeah, pretty much the same way.

Well, let's check this out in Java way in a web context !!!
You want some service from a server and you push a request to the server with some details you provide over the form (Requisition Slip) you see. There sits a container (Librarian) in the server side (Library), which reads the register (web.xml) for appropriate servlet (Bookshelf) and the servlet returns the response (Specified Book) and the response is sent to the client (You yourself) by the container.

Contributed by:                Amrita Pattnaik
Edited and re-written by:  Palash Kanti Kundu
Palash Kanti Kundu Palash Kanti Kundu Palash Kanti Kundu Palash Kanti Kundu

Internet defined simply

The Internet is so big, so powerful and pointless that for some people it is a complete substitute for life. - Andrew Brown

For most of us, this is true. Internet provides lots of information, lots of entertainment, lots of stuffs to pass time. But the original purpose of internet was to build an information network between computers and internet today really proved to be successful on this goal. Mitchell Kapor perfectly said "Getting information off the Internet is like taking a drink from a fire hydrant."

This powerful weapon can be accessed from any corner of the world using a web browser. Many web site and web applications are available over internet to provide you with information. Beautiful web pages are what we can see in our PC/Mobile phones and more interestingly, whatever device you use, you always get the same information in each of them.

As the days passing by, the numbers of websites are increasing. We for our day to day basis, visit many websites. Many of us are having our own Mail accounts, Facebook Account, WhatsApp Account. World is moving and we call this era, 'Era of Internet'. Most of the world is connected with the giant called, 'Internet' by any means. May be its for entertainment purpose (FacebookYoutube etc), or for news (www.timesofindia.comespncricinfo.com) or for health care purpose (https://www.healthcare.gov/) or may be for some knowledge gaining purpose (www.mathisfun.com) or to connect professionally (https://linkedin.com) or to store your files on cloud(drive.google.com) or to show off who you are (http://palashkantikundu.in) or simply when you have nothing special and start building something (palash90.intales.palash90.in) and the list goes on, each one use internet for a purpose.

Now let's try to see how this is done.

This is achieved by a Server-Client Concept. Following is the graphical representation of the architecture,
Client-Server architecture
To define the different components in the diagram, we have to go through some definitions,

Server: This is a software component which can perform some operations based on requests sent by a Client.
Client: A client is a software which sends request to the server.
User: A user is a person using the Client.

I am a person, can I be a user ?
Yes you are a user at this point of time and you are using a web browser, may be Firefox, Google Chrome, Internet Explorer, Safari, Opera etc. These are applications which sends a request to the server palash-90.blogspot.com; the server knows which information the client wants and does a beautiful job for you and finds the information you want and sends the information formatted as response back to the client you are using and the client application knows how to format the response and gives you a beautiful reading experience.

So, at its bare basic is a process of request-response communication.

So, we know how everything goes on. Now let's check how everything works.

Client application takes user input >> It then generates a request >> Client sends the request to Server

Server receives the request >> Server processes the request >> Server creates a response based on the processed output >> Sends back the response to client

To perform all these operations, Client and Server agrees upon a common language between them for communication. This language is known as HTTP. The communication takes place on a medium known as network. This network is responsible for all the communication taken place on it and also takes care of all the related hassles to ensure that the server and client should not bother about it and can perform their tasks at ease.

So, what is Internet ?
Internet is network of networks. Following diagram puts a more light on it.
Internet - network of networks
Now, its a bit tricky here. We know that network is responsible for a server and a client to communicate. Then we might think what is the use of Internet.

Well the answer is simple but it comes with a question. Suppose, you want a piece of information which is not available on the network you are connected (that happens in most cases), how would you fetch the information ?
Simple, I will connect to the network, it has the information in it.

Exactly, Internet does the same thing. It finds the network for you and connects your client to the network.

Definition from webopedia is 'The Internet is a global network connecting millions of computers. More than 190 countries are linked into exchanges of data, news and opinions.'

What is data ?
Well, this defines data.

Hope, this article helps you understand the internet. Thanks for reading.


Palash Kanti Kundu

REST - a simple approach for network communication

We know about Websites and Web Applications. In day to day uses, we see that most cases, we use Web Applications rather than websites. Now, web comes into different flavours, a perfect browser based GUI application, a powerful back end Web Service or a lightweight alternative REST Service.

Now, you all know about GUI Applications, anything that you see on a web browser like Internet Explorer, Mozilla Firefox, Google Chrome, Opera. When you hit a URL in the address bar, you see a GUI Application with lots of colours, lots of controls, lots of interactions etc.

But, this is not the case for the later two, they just provide the data in text based format like XML, JSON etc. In these cases, the server just knows which data to provide and care less about the presentation of the data.

Hey, wait, what is the necessity of using Web Services and REST, if we already can present the data in the way we want ?
Well, thanks for bringing up this point. Let's take a closer look on this part here. The business problem is already discussed here and a solution approach is also provided to address the business problem.

Well, I understand now, we need Web Service and REST. Now, my question is why REST, if we already have Web Service to answer all the problems ?
Well, you can use either of them.
Now, just to take a confirmation, would you like to have a powerful client application, more network bandwidth, more processing on data ? No, right !

Well, I got it. So, how REST handles all these scenarios ?
Web services use XML, which means a strict API, more verbose. The communication between Server and Client is also a point to consider. Web Services uses SOAP (based on XML) for communication.
Now, in case of REST, it is all based on HTTP. So, the overhead of request and response processing to and from SOAP or XML to or from Request/Response body is not required. Also REST uses JSON as the backbone for data transfer.
This boils down to less processing, less bandwidth and faster data transfer.

Well, now I understand. But you just told that, REST uses JSON, so what about data integrity ?
Well, that's a catch, REST thinks that the client and server knows their responsibility of transferring data. So, you are free to transfer anything you want. On the other hand, Web Services provide a really beautiful way of transferring data in particular format and you can even impose constraints using DTD and XSD if you want. So, data integrity is really a part where Web Services rule over REST.

Hmm... (Aww...) So, if I have a more like of data integrity, I should use Web Services in the cost of performance and bandwidth.
Yes, you are right. If you have a data integrity constraints, you are more likely to bend over Web Services rather REST.

Prev     Next
Palash Kanti Kundu