Difference between an application server and a servlet container? - java

I am trying to understand the difference between a full fledged application server (e.g. Weblogic, JBoss etc.) and a servlet container (Tomcat, Jetty etc.).
How do they differ and when to use which?
Thanks,

A servlet-container supports only the servlet API (including JSP, JSTL).
An application server supports the whole JavaEE - EJB, JMS, CDI, JTA, the servlet API (including JSP, JSTL), etc.
It is possible to run most of the JavaEE technologies on a servlet-container, but you have to install a standalone implementation of the particular technology.

Broadly speaking, a servlet container restricts itself more or less to the implementation of the J2EE Servlet specification. Also, it's focus is on the runtime environment and not so much on providing additional tools.
In contrast, a full fledged application server implements the whole J2EE stack; plus it comes with all the enterprisey tools and integration possibilities. An application server usually has advanced administration interfaces, it supports clustering and other features used mostly in high-end systems development.
For a beginner, it's probably better to stay with a simple servlet container, since the learning curve there is much less steep.
Edit
#Apache Fan: It depends on the specifics of your situation like existing systems and future plans among other things. I don't think a generic flowchart approach is applicable here.
Platform selection is usually done by weighing specific requirements against first-hand knowledge of systems under consideration.
However the question gives no clues as to what the evaluation criteria are. Should it be open source? Is around-the-clock vendor support necessary? What kind of an enterprise environment should the system integrate with? Are licencing fees an issue? Any must-have technologies or tools? Etc.
Without knowing the above it's pretty much shooting in the dark.

Basically an application server in Java EE context is a software installed on a server and that implements one Java EE specification (Java EE 7 for example). That means such software (application server) must be able to run Java EE application.
Java EE defines 4 domains, the so called containers:
Applet container,
Application client container,
Web container, and
EJB container.
Two containers are part of the application server (EJB and Web container) and two others are part of the client-computer.
JBoss and Weblogic are application servers, Tomcat and Jetty are web container. That's why JBoss and Weblogic can deal with more technologies than a Web container. Application server can manage EJB.
Servlet container is not the appropriate expression to qualified Tomcat and Jetty because it is more restrictive. Tomcat can also execute JSP and JSF, not only Servlets.

afaik, websphere and jboss are fully compliant j2ee-server that can run beyond servlets, like EJB, whereas Tomcat is just a servlet container and you can't run EJBs on it.

In Layman terms :
A web Server means: Handling HTTP requests (usually from browsers).
A Servlet Container (e.g. Tomcat) means: It can handle servlets & JSP.
An Application Server (e.g. GlassFish) means: *It can manage Java EE applications (usually both servlet/JSP and EJBs).
For a beginner, it's probably better to stay with a simple servlet container.

Related

Microservices : Embedded tomcat vs standalone tomcat : Difference

Can embedded tomcat or any such embedded server be used for microservices in production environment? How, embedded server is different wrt the normal standalone full fledged server (performance . reliability wise)? Is the embedded server light weight compared to standalone? What are the features that embeded servers do not have compared to their standalone ones? Can we change the default security settings, tls ciphers etc advanced things in embedded tomcat?
Well, it's a matter of choice. I've seen some services which use embedded tomcat in production and some services which rely on standalone tomcat container which is directly provided by the platform. Some platforms might not have a java runtime, in such scenarios you're bound to use embedded containers for tomcat or jetty.
The key difference would be that standalone containers can host multiple java deployments whereas for single deployments you can stick to the embedded ones. And yeah reliability and performance won't be a huge concern, although I believe that standalone containers are designed to be more scalable. From my personal experience, embedded deployments are easier to manage, since we can custom configure the tomcat setting specific to that deployment (might be the answer to your last question)

Is it a good idea to host Java JAX-RS web services on IIS?

We are required to build some Java JAX-RS web services that will connect to some other external web services to retrieve data. Logically, we should host these new JAX-RS web services on a container like WebLogic. Due to cost saving measures by management, we are told to use IIS to host these JAX-RS web services as it is supposedly cheaper than WebLogic. They want the services to be written in Java because it is OS independent, so using .NET is out of the question.
(1) Is using IIS to host Java JAX-RS web services instead of a fully J2EE compliant container like WebLogic to save cost a good idea?
(2) How do we host Java JAX-RS web services on IIS 7.5? What are the required add ons?
Thanks in advance.
First of all, IIS does not support Java. See this old post in MSDN (2005)
IIS can never directly support the use of JSP because it requires an add-on to run Java code in a JVM to Load,
Therefore you always require a J2EE server to execute J2EE services, and the IIS add-on isapi_redirect (see the link). The add-on will capture the requests and forward them to the J2EE server (in the example is used tomcat)
So the answer to your question
(1) Is using IIS to host Java JAX-RS web services instead of a fully J2EE compliant container like WebLogic to save cost a good idea?
No, because you allways need a J2EE server., so the cost parameter is non applicable (without considering other aspects). I suggest also to consider some free of charge servers like Jboss, Tomcat or Jetty
Note also you do not need a fully compliant J2EE server to use JAX-RS. Latest versions of JVM are shipped with an implementation of JAX-RS.

What are the specific uses of Java Application Server that cannot be done with web servers?

I am a little confused about the roles of a java application server and its differences from a web server.
I found many sites explaining the same difference between the two but not to my satisfaction.
So please explain me about the two following cases:-
1)App. Server and its difference with web server:
From these two links:
Difference between an application server and a servlet container?
What is the difference between application server and web server?
web server: It handles everything through http protocol by accepting requests from clients and sending
responses to them with the help of its servlet container(e.g Apache Tomcat)
App. Server: An application server supports the whole of JavaEE like JMS,JPA,RPC etc.
Now what I am confused with is that how can I use a lot of JavaEE APIs like JMS,JPA etc. with my Tomcat
by adding their jar files in my web application ?
Does that mean that if I use an appliation server I don't have to add those jar files?(I don't think so)
2)The roles of an appl. server (This is very important to me)
From Wikipedia
http://en.wikipedia.org/wiki/Application_Server
An application server provides services such as security,transaction support etc.
"The term is often used for web servers which support the JavaEE" -- It sounds like if we add the required jar files of JavaEE APIs a web server becomes an appl. server.What about it.
Now my question is how an application server performs the tasks of security control or transaction management by itself ?
E.g. in my web application using Spring framework I am providing security by using spring-security and transaction management by using #Transactional annotation and all those things you know.
So does the appl. server have anything to do with my security or transaction management or it has its own ways ?
Forgive my ignorance.
Using Spring, you're in fact embedding some kind of Java EE container inside your application. But even when using Spring, if you need JTA support (because you need distributed XA transactions), you'll need to use an additional transaction manager. If you need JMS, you'll need to install an additional JMS broker. If you need connection pooling, you'll need to use an additional connection pool. Sometimes it's as simple as adding additional jars to the classpath and properties or XML files. Sometimes it's harder.
A Java EE app server comes with everything bundled. You have less flexibility, but you don't need to install, configure and make everything work by yourself.
When you use the Java EE framework, that is a specification. So the application server, if it is Java EE compliant, needs to implement this. So once it is implemented the specification, then it will address Security,transaction etc because it is mentioned in the spec. So it is a contract. Whereas, in a web server, it will just pull out your static resource. There is no need for handling other stuff.
In case of the Spring framework, the framework knows how to handle transaction, security etc. So particularly the developer need not look into these aspects which are implemented by the Application Server in the other scenario.
how an application server performs the tasks of security control or transaction management by itself
It is rather the specification that address these issues, not the application server. So, the duty of the app server is to implement these.
So, if your application is Java EE compliant, then these areas will be addressed and the implementation would have been done by the app server.
May be this is oversimplification,
A web server is basically a HTTP server serving contents over http protocol. So a web server is simply about serving the contents over http protocol. A typical example would be Apache web server. This is simply a file server.
Now the question is where does the web server gets the contents from ? Possible sources are
Static contents (the contents like images/css etc) which are not generated on request but statically served.
Dynamic contents: Simply put, the contents to be served are generated upon the user request.
For the static contents, the web server does not need anything as it simply reads the file and serves it.
For dynamic contents, the web server might need help of additional components which will generate the contents to be served.
Here the Application Server comes into picture.
Now these additional components referred earlier, might interact with database or some other system etc.
In a web environment where your website is exposed to huge number of users (intended/unintended), you need typical services like transaction/security/concurrency etc. so that the user get expected responses and do not see inconsistencies in the behavior of the application.
An application server has inbuilt abilities to manage transaction/security/concurrency/resource management. generally these are referred as Managed services and environment offered by them is called Managed Environment where these basic services are managed by the application server and programmer does not have be bother for them.
Application Server needs web servers or we can say Web servers use Application server's services to generate dynamic contents.
For example, JBoss uses Tomcat as inbuilt web server. Whereas web logic has its own web server. Tomcat again can be called as application server (in principle) as it also offers managed environment for servlets (it manages concurrency and instance pool of servlets/JSPs ).
Coming your your example of Spring:
An Application server will come inbuilt with transaction/security etc whether you need it or not. The Spring offers a very nice way handling this. Spring has all these things BUT you use what you need. Not just these, but just a Java Web Sever like Tomcat is sufficient to build a full fledged services that needs an application server.

Difference between web server and application server [duplicate]

This question already has answers here:
What is the difference between application server and web server?
(28 answers)
Closed 4 years ago.
As a layman, how do I understand the difference between web server and application server ? If you could give an example using a Java based web app in very "simple" terms that would be really great..
Also when we say Weblogic, is it a web server only ?
A web server is something that handles HTTP requests and responses.
An application server (like WebLogic, WebSphere, JBoss AS, Glassfish, etc) usually includes a web server, but also adds a lot more features. The most important is that it manages objects. Whether they will be servlets (Servlet container), EJBs (ejb container), JMS listeners, etc.
Webserver can execute only web applications i,e servlets and JSPs and has only a single container known as Web container which is used to interpret/execute web applications
Application server can execute Enterprise application, i,e (servlets, jsps, and EJBs) it is having two containers 1. Web Container(for interpreting/executing servlets and jsps) 2. EJB container(for executing EJBs). it can perform operations like load balancing , transaction demarcation etc etc
I would say definitions vary. In the generalized context, a Web Server is a server that can receive incoming web-requests and have knowledge about how they should be handled and responded to. Some requests are static (html files, images etc), some are dynamic. In the case of dynamic requests, the web server will know where to route handling of the request, could be a JSP page or a java servlet, a PHP script, a perl CGI script etc etc.
While the "web server" in this context executes the dynamic handler, it is not considered to include any supporting middleware features for the dynamic handler.
An Application Server, by contrast, is a general execution environment that offers some type of middleware tier support. Examples are EJB containers or the .NET framework built into Windows (in where Windows in itself is an "application server"). There is no inherent requirement that an application-server have anything to do with web requests (although many do), it's just a general execution context and container for any type of application that offers some sort of additional middleware support.
In a purely web-centric context, many people will draw the line at static vs dynamic content. In this definition, a "web server" can only handle requests for static information itself and it will pass on requests for dynamic content to the "application server". For example, Apache httpd is a web server and Tomcat is an application server. IIS is a combination of both. In the Java web world, an application server can be either a servlet container (like Tomcat), or a full blown Java EE container (like JBoss, WebLogic or WebSphere) that provides the Java EE middleware support (EJB) container in addition to the servlet container.
And adding to previous answers, Weblogic is app server and not only web server.
Basically if we say the major difference between Web Server & Application Server, is the protocols on which these servers work.
Web Server -- it works on protocols like HTTP & HTTPS. Example of this server is Apache. For web server you use JSP, Servlet.
Application Server -- it works on any protocol. example is JBOSS. On application server we host EJB, web service or any business Logic.

Servlet container; What is it and do I need it in my case?

I have just ordered a VPS from my provider.
I have some Q however...
My website uses Solr, which requires the following according to their website:
"Solr requires Java 1.5 and an Application server (such as Tomcat) which supports the Servlet 2.4 standard"
I also need php 5, MySql, and the usual javascript etc...
The OS is Ubuntu 9.10
1- So what do I need to install then?
2- What is a servlet container?
3- The solr I have downloaded came with Jetty. Is Jetty a Servlet container?
Thanks
3- The solr I have downloaded came
with Jetty. Is Jetty a Servlet
container?
Yes, Jetty is a Web server and Servlet container. A servlet container is a web server that interacts with servlets, and you need one of those to host your servlets, execute them, etc.
An application server typically hosts many other facilities, such as security, authentication, Java Mail, EJB container, and many others.
PHP: Hypertext Preprocessor is a widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages.
PHP 5 included new features such as improved support for object-oriented programming, the PHP Data Objects extension (which defines a lightweight and consistent interface for accessing databases), and numerous performance enhancements.
Servlets are Java programming language objects that dynamically process requests and construct responses. Jetty is the simplest/smallest servlet container that could be run easily in a cross platform way. That does not imply that Solr runs better under Jetty, or that Jetty is only good enough for demos, it's just that Jetty makes demo setup easier.
Users should decide for themselves which Servlet Container they consider the easiest/best for their use cases based on their needs/experience. For high traffic scenarios, investing time for tuning the servlet container can often make a big difference.
A Servlet container is basically a web server for Java Servlets and JSP pages.
Tomcast and Jetty are both Servlet containers.
In the phrase you quoted, it is using the phrase "Application server" interchangeably with "Servlet container". While Solr may only require a Servlet container, it shouldn't use the terms interchangeably.
The Servlet container is only part of a J2EE application server. Some other application servers (that also include Servlet containers) are JBoss and Apache Geronimo; Geronimo uses either Tomcat or Jetty depending on which set you install.
If you also need PHP, a Servlet Container won't be enough... you'll also need a normal webserver.
Installing the libapache2-mod-php5 module from the Ubuntu repository should install both PHP5 and Apache 2.2 for you. To install MySQL, install the mysql-server and php5-mysql packages.
Assuming you only have command-line access, installing packages on Ubuntu is done using the aptitude or apt-get programs; aptitude is preferred.
Before you install new programs, you should always run aptitude update, which updates the local index of which programs are available. Afterwards, you can upgrade existing packages with aptitude safe-upgrade and install new packages with aptitude install <packagename> (without the <>)
Ubuntu is usually pretty good about keeping the available package list up to date, and will periodically tell you on login that some packages have available upgrades. Since upgrades are almost always security updates, it is a good idea to check for them.
I also need php 5, MySql, and the usual javascript etc... The OS is Ubuntu 9.10
1- So what do I need to install then?
Use Apache HTTPD server for PHP, use Apache Tomcat for JSP/Servlet, use mod_jk to let HTTPD play proxy for Tomcat so that you can run PHP and JSP at one same site.
Since JavaScript is a client side language, you don't need to worry about it at the server side.
2- What is a servlet container?
A webserver with a JSP/Servlet API implementation. An application server is usually more than that. JSP/Servlet is only a little part of the huge Java EE API. A fullfledged application server implements pretty much all of Java EE API.
3- The solr I have downloaded came with Jetty. Is Jetty a Servlet container?
Yes, it is. It however doesn't support PHP. You need Apache HTTPD for PHP. However I am not aware of ways to connect Jetty with HTTPD.

Categories

Resources