What is a web service?

In Chapter 7, Creating JEE Applications with EJB, we learned that EJBs can be used to create distributed applications. EJBs can act as glue and help different JEE applications in the enterprise to communicate with each other. However, what if the enterprise wants to let its partners or customers make use of some of the application functionality? For example, an airline might want to let its partners make online reservations.

One option is for the partner to redirect its customers to the airline website, but this would not provide a unified experience to users. A better way to handle this would be for the airline to expose its reservation APIs to partners, who can integrate these APIs into their own applications, providing a unified user experience. This is an example of a distributed application, and EJBs can be used for this.

However, for EJBs to work in such scenarios, where API calls cross enterprise boundaries, the clients of the APIs also need to be implemented in Java. As we know, this is not practical. Some of the airline partners in this example may have their applications implemented using different programming platforms, such as .NET and PHP.

Web services are useful in situations such as the one mentioned here. Web services are self-contained APIs that are based on open standards and are platform independent. They are widely used for communication between disparate systems. There are mainly two types of web service implementations:

  • Simple Object Access Protocol (SOAP)-based
  • Representational State Transfer (RESTful) services

For many years, SOAP-based web services were quite popular, but recently, RESTful services have been gaining ground because of the simplicity in their implementation and consumption.

Web services provide a common integration platform and offer service-oriented architecture (SOA) in which certain components expose services for consumption by other components or applications. The consumer of such services can create an entire application by assembling a number of such loosely coupled services, possibly from different sources.

In this chapter, we will see how to develop and consume both SOAP and RESTful services by using JEE and Eclipse. However, first it would be useful to understand how to convert Java objects to XML and JSON, and vice versa, because both REST and SOAP web service implementations need to perform these operations. First, we will take a look at JAXB, Java XML binding, using which you can bind Java objects to both XML and JSON. Then we will take a look at JSON-B (a new specification added in JEE 8) for Java JSON binding.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.158.134