views:

399

answers:

3

I have just started learning Java Web Services ( JAX-WS ) and have one question. The reference documentation always talks about Web Services container. My question is : What is a Web Services container and why do we need it. I saw a simple example of JAX-WS in book "java web services up and running" where the web service is published using:

Endpoint.publish("http://127.0.0.1:9876/ts", new TimeServerImpl());

This example did not require me to host a web service in a Web Server / App Server or any container.

and I was also able to access this web service.

So what is a container, why do we need it for web services?

A: 

Basically you just need something that can run Java servlets. Typical examples are Tomcat, Glassfish, JBoss, Jetty and many others.

Of these Tomcat is the lightest weight as it is "only" a servlet container (JBoss and Glassfish are J2EE application servers) and is the reference implementation for the servlets specification. You'll find lots of IDE integration and tutorials that use it too.

cletus
Thanks cletus..could you please explain why we need a servlet container...
A: 

The web service specification implementation by the various vendors( Websphere,Weblogic, JBoss) are through a servlet and you would need a servelet container to support this servlet. This servlet is specifically designed to handle SOAP based traffic (HTTP traffic with SOAP headers and body) rather than plain HTTP based POST/GET that you send from browsers.

zkarthik
A: 

The web service that you created is running in a container, which in this case is the server. The server can run multiple applications, each having their own container. The container is necessary as it provides a standalone environment for the execution of the Java that is contained in the source.

The containers provide security, so if one application crashes due to a problem the other applications do not crash. Depending on the implementation each container can run in its own VM or can run across multiple VMs. Basically they are there to run the code in a separate environment from other code.

Here is some older(ish) documentation on the idea of containers. Basically they can be run in different safe containers, much like running multiple applications at the same time in Java, that are controlled via a single application (web server).

scheibk
So, you are saying that when we publish a web service as I described above, jvm creates a container and runs webservice in that container?or is the JVM called the "container" in the web service documentation. Could you please explain.
I updated my answer to include some information about containers that came from Sun a few years ago. The concepts haven't changed.
scheibk