Friday, February 9, 2007

Web Server and Application Server

Webserver is for hosting ur webapplications (Servlets and jsps). Application
server is server which provides services like transactions, security,messaging, and other j2ee services like jndi etc to the application. Theapplications can be built using ejb which use all the declarative services,which minimizes the lines of code and reduces the application development time.

WebServer is a service or a daemon running at a given IP and a Port that is capable of accepting and responding to all HTTP events. It is created to understand the HTTP transfer protocol. The basic functionality of a WebServer is to accept a browser request for HTML pages and respond it with the resources in it. To completely understand a webserver, i will suggest, write your own webserver. Dont get scared. Writting a webserver using java is no big deal.
Creating your own WebServer
* Create a Server Socket using the ServerSocket class.
* Configure it to accept requests at a default HTTP port that is port 80.
* Once a connection is established and a request is send, read the HTTP header in the request.
* From the HTTP header, do normal parsing using StringTokenizer, and you can get the filename that is requested.
* Once u get the filename, open a filestream and read the file into some DataOutputStream object.
* Write this object over the open connection.
* Now Flush the data.
This is the most basic HTTP server that can be written in JAVA. I did this long time back, let me know if you require code, i ll try finding it in my old backups.
Over this basic functionality you can build a better and powefull WebServer.
For instance you can start with using threads to support more requests. You can set unset session id to track Sessions. You can Read the MIME type in the header to respond to various file formats like JPEG, MPEG, GIF etc. And other things. So now you understand what a web server is.
A WebServer is a service running on some remote machine that can communicate with your webBrowser and fetch you files using HTTP protocol.
And thats it, nothing more nothing less. For instance IIS and Apache are webServers. Though they do many other things then serving webpages. But that is not a part of a simple webServer.
Applicatin server.
Anything u know abt app servers minus the defn of the web server that i just stated is the job of an application server. An application server executes an application code written in some language and bundles the results in form of HTTP response, which can be send over wire by the HTTP Web Server. (Dont get confused). For instance IIS is a combination of both application server as well as web server. The webserver part is supposed to deal with the browser sending and receiving request and response objects using the HTTP protocol. The application server is responsible of doing all the processing work, executing scripts, accessing the database, bla bla.. Today's Application servers evolved long way back from there ancistors -> CGI or common gateway interface. Though CGI are not true app server as per todays defn of application servers, but it provides a backbone for the application technology that is build in the middleware.
So to make the discussion short, lets define application server
An Application server is a service or daemon running on some remote machine that communicates with the WebServer using HTTP protocol and hosts a range of services and applications. Not to explain, these services can be anything like ACLs, Object pooling, Transaction management, etc etc.
A noteworthy difference betn the two is webservers communicate with the Browser, where as app server communicate with the webServers. Here u can very well question "but y so" ?
The ans is simple. Let me give you one eg, and things will be clear.
In 1 of my project we had the following congifuration. We used the Weblogic server, providing its service at 7001 port. This is where our application(JSP, EJB, Servlets etc etc) was hosted. Then we had a IIS server providing service on 80 port. So if i connect http:\\www.mysite.com\index.html, the index.html page will be served directly by the IIS server. Now we had a configuration in IIS server which stated that all the application related requests be directed to the WebLogic server. So wheneveer IIS gets a request asking for *.jsp, *.class (say http:\\www.mysite.com\index.jsp) it gets routed to WebLogic app server. WL will get the request object, execute the script, create the response object and dump it back to IIS. IIS will wait till it receives a response from WL or till timeout occurs. On response it will just fwd it to the browser.
This architecture clearly differentiates the app server from the web server. Most of the app servers also bundle a webserver with them. That is, they behave as a single web+app server. So we dont understand the difference betwn the dual role. (above architecture is used in many scenarios, but detailed explaination is out of the scope of this discussion.)
One last thing. we can summarize by saying that serving files is the job of an webserver. And serving appliactions is the job of app server. Remember, we can access the application sevices without using the HTTP protocol. HTTP protocol was specifically created for web servers. If you have used WebLogic, there is something called as T3 services. This is the application protocol that gives you access directly to the app server services. We had an application that accessed WL directly using t3 to get the job done. (again detailed explaination of t3 or app protocols is out of the scope of this discussion).


SOURCE : www.referjava.com

No comments: