Showing posts with label JAX-RS. Show all posts
Showing posts with label JAX-RS. Show all posts

Web Services in Java


In this tutorial we will see about Web Services in Java.


What are Web Services?


Web services are client and server applications that communicate over the World Wide Web's (WWW) HyperText Transfer Protocol (HTTP). As described by the World Wide Web Consortium (W3C), web services provide a standard means of interoperating between software applications running on a variety of platforms and frameworks. Web services are characterized by their great interoperability and extensibility, as well as their machine-processable descriptions, thanks to the use of XML. Web services can be combined in a loosely coupled way to achieve complex operations. Programs providing simple services can interact with each other to deliver sophisticated added-value services. By Oracle Docs.


Before Web Services?

Before Web Services introduced we were using RMI (Remote Method Invocation), CORBA etc., to communicate third part services and methods. With the release of JDK version 1.1, Java has its own, built-in native ORB, called RMI (Remote Method Invocation). Where CORBA is an integration technology, not a programming technology which used in Java to communicate between other languages like C, C++, Ada, COBOL etc., Instead of digging to RMI or other client/ server we will focus only on Web Services in this tutorial. 


Types of Web Services?

There are 2 tyes of Web Services,
1. SOAP based (Simple Object Access Protocol) Web Services 
2. RESTful Web Services 


SOAP Web Services (JAX-WS)

SOAP web services use XML messages that follow the Simple Object Access Protocol (SOAP) standard, an XML language defining a message architecture and message formats. Such systems often contain a machine-readable description of the operations offered by the service, written in the Web Services Description Language (WSDL), an XML language for defining interfaces syntactically. Basically Client and Server communication will be in XML standard formats which gives flexibility to use any platform (Java, .NET, etc.,) and to use any OS (Windows, Unix, etc.,). Generally Server can be in any language and client can be any language where communication will be in common XML formats and standards.


RESTful Web Services (JAX-RS)


JAX-RS provides the functionality for Representational State Transfer (RESTful) web services in Java. REST is well suited for basic, ad hoc integration scenarios. RESTful web services, often better integrated with HTTP than SOAP-based services are, do not require XML messages or WSDL service–API definitions as like SOAP. By Oracle Docs.


Difference between SOAP and RESTful

  • SOAP is a Object oriented and REST is a resource oriented.
  • In place of security SOAP supports SSL and WS-Security and REST supports only SSL.
  • As performance wise SOAP will be better than REST
  • SOAP doesn't support caching and REST supports.
  • SOAP is heavy in message size with WS specific markup. where as REST is lightweight and no extra XML markups added. 
  • SOAP supports text and binary encoding and REST supports only text encoding.
  • SOAP uses WSDL to describe the services which we have exposed and in REST there is no formal definition.
  • Complexity of SOAP uses frameworks to develop and on other side REST is very simple in development without any frameworks. 
  • Protocols supported in SOAP are HTTP, SMTP, JMS and REST supports only HTTP.


According to project needs development team need to decide whether they need to go with SOAP or REST.