A Technology Blog About Code Development, Architecture, Operating System, Hardware, Tips and Tutorials for Developers.

Wednesday, November 14, 2012

Before Learning Java Web Service

7:15:00 PM Posted by Satish Kumar , , , No comments

When it comes to web service in java, lot of people tell lot of tools to create web service using java. But most of the people does not know how does it work??.. In fact I asked many people about web service using java; the reply was "Install this plugin, use this build tool configurations and you are ready write a web service. See it is calling the web service". Sounds simple huh. I got confused, but I came across some common word used by most developers like SOAP, REST, DOM, SAX STAX, JAXB, JAX WS, JAX RS, Apache Axis, Apache CFX, Glassfish Jercy, Glassfish Metro etc.. So I started my journey with these words and finally concluded the relation.

Before going directly to web service, let me start the journey with XML parser. Why because web services use XML, JSON etc for message exchange. As many people know there are two types of pacers available and which no body use right now. Yes now no modern applications use these.

DOM (Document Object Model) -  In DOM you access the XML document over an object tree. DOM can be used to read and write XML files.

SAX (Simple API for XML) is an Java API to sequential reading of XML files. SAX can only read XML documents. SAX provides an Event-Driven XML Processing following the Push-Parsing Model. What this model means is that in SAX, Applications will register Listeners in the form of Handlers to the Parser and will get notified through Call-back methods. Here the SAX Parser takes the control over Application thread by Pushing Events to the Application.

Stax (Streaming API for XML) is an API for reading and writing XML Documents. Introduced in Java 6.0 and considered as superior to SAX and DOM.

Java Architecture for XML Binding (JAXB) is a Java standard that defines how Java objects are converted to XML and vice versa(specified using a standard set of mappings). JAXB defines a programmer API for reading and writing Java objects to / from XML documents.

Now coming to JAX WS and JAX RS. I must tell you they are not any tool or API, they are the standards for creating web services.


JAX-WS stands for Java API for XML Web Services. JAX-WS is a technology standard for building web services and clients that communicate using XML. JAX-WS allows developers to write message-oriented as well as RPC-oriented web services. In JAX-WS, a web service operation invocation is represented by an XML-based protocol such as SOAP. There are lot of implementations available in market like Apache Axix and Glassfish Metro


JAX-RS stands for Java API for RESTful Web Services. JAX RS is a technology standard for creating web services according to the Representational State Transfer (REST) architectural style. The very popular Apache CFX and Glassfish Jercy are the implementations of JAX_RS

The advantage of JAX RS over JAX WS, it support message exchanging using TEXT, XML AND JSON. Both there standards use JAXB for mapping XML and object.

JAX RS and JAX WS provide mapping between the request with the end point. If you are using web service in your application, check there will be a front controller in web.xml from these implementations to take all your web service calls. Using these APIs you can also write client code to call a web service.

Now I after reading this you must be thinking, even though you use web service, where do you use these APIs.. The answer is there are lot of tools available in market which takes your .xsd as input and generate all these bean and end point class for you and the data pacing is handled internally. So you just call your end point to get your business logic execute. 

Hope this gives a clear idea web service in java. Let me know if I have missed out anything or there is something wrong.


Post a Comment