SOA(Service-Oriented Architecture)
SOA is a software architecture that facilitates the loosely-coupled integration between diverse applications.
It provides the flexibility to make changes in a software and its networking components, without affecting other existing components of the system.
SOA is represented as a collection of services communicating with each other. A service is a well-defined business functionality.
SOA consists of some entities that maximize the loose coupling and reusability:
- Service registry
- Service provider
- Service consumer
Web Services
The concept of SOA is implemented using Web services.
A Web service is an application function that performs a specific task or set of tasks.
At the same time, the Web services can be published, located, or invoked over a network.
Benefits
- Support for application and data integration
- Versatility
- Code reuse
- Cost savings
JWSDP toolkit
Web services are developed using JWSDP toolkit.
This toolkit enables developers to build, test, and deploy the XML applications, Web applications, and Web services in Java.
| APIs | description | Usage |
|---|---|---|
| JAX-WS | Java API for XML Web Services | used for developing the XML-based Web services. |
| JAXP | Java API for XML Processing | used for processing the XML data from the Java applications. |
| JAXB | Java Architecture API for XML Binding | allows you to map the XML document to the Java objects, and vice versa. |
| SAAJ | SOAP with Attachments API for Java | used to transport large files as attachments with SOAP messages over the Internet. |
| JAXR | Java API for XML Registries | used to access different Web services registries. |
Types of Web Services
Web services can be developed using two different approaches:
- XML-based Web services
- RESTful Web services
XML-based Web services
An XML-based Web service is a self-describing Web component that exposes its functionality to the consumers.
Components:
| name | description |
|---|---|
| WSDL | An XML-based document used to describe the functionalities of an XML-based Web service. |
| UDDI | An XML-based directory service used to register an XML-based Web service. |
| SOAP | An XML-based protocol used to exchange information between applications. It used the HTTP protocol for data transfer. |

WSDL(Web Service Definition Language)
WSDL is an XML-based file that describes details such as publicly available functions of the Web service, location of a Web service, and the data type of messages exchanged between Web services.
Elements
1 | <definitions> |
Types of WSDL Models
- Abstract model
- contains
<types>, <message>, <portType>
- contains
- Concrete model
- contains
<binding>, <service>
- contains
UDDI(Universal Description Discovery and Integration)
UDDI is an XML-based directory service that shares details about the Web services globally.
Components
- Yello Pages
- White Pages
- Green Pages
SOAP
(Simple Object Access Protocol)
Elements
- SOAP envelope
- SOAP header
- SOAP body
- SOAP fault
[DEMO]
1 | POST /endpoint.pl HTTP/1.1 |
Building a Web Service
1.Creating a Web Service
JAX-WS is an API used for creating Web services that communicate with clients using XML.
The JAX-WS API is defined in the javax.xml.ws package.
| Annotation | Description |
|---|---|
| @WebService | defines the class as an implementing class a Web service interface |
| @WebMethod | defines that the method is a Web service method; supported only by those classed that have a @WebService annotation |
| @OneWay | defines that the Web method has input but no output; can be specified only for methods that does not have a return type |
| @WebParam | defines the parameters of methods used in a Web service |
| @WebServiceRef | defines a reference to a Web service |
2.Defining the Web Methods
[Demo]
1 | package com.helloservice; |
RESTful Web services
The RESTful Web services are the services built on the REST architectural style.
REST
REST is a softaware style architecture based on SOA which is used for designing RESTful Web services.
- REST is NOT a standard architecture style. REST follows the resource-oriented architecture.
- REST is NOT a replacement for XML-based Web services. They are used for different businiess requirements.
- While XML-based Web approach defines new specifications for Web application development, the REST approach uses the existing Web standards for developing Web services.
- REST is mostly preferred over XML-based Web services because of its lightweight nature and simple design.
REST Design Principle
- Using HTTP methods
- Exhibiting stateless nature
- Exposing directory structure
- Transferring data in XML and JSON formats
Implementing RESTful Web Services
JAX-RS API
The javax.ws.rs package
| Annotation | Description |
|---|---|
| @ApplicationPath | Indentify the app path |
| @Consumes | defines the MIME types that are accepted by the methods of a resource class |
| @DELETE | - |
| @GET | - |
| @HEAD | - |
| @HeaderParam | binds the values of an HTTP header to the parameter of a resource method, resource class fields, or resource class bean property |
| @HttpMethod | - |
| @Path | Indentify the URI path |
| @POST | - |
| @Produces | defines the MIME types that the methods of a resource class or MessageBoxWriter interface can produce |
| @PUT | - |
| QueryParam | binds the values of an HTTP query parameter to a resource method, resource class fields, or resource class bean property |