Saturday, February 23, 2013

Java WebSerivces Tutorial - Part 01


Java Web Services:

What is a web service?
A web service is a service which is available over internet use a standardized xml messaging system and is not tied to any operating system.

Main purpose of web service:

The business logic can be written once it can be accessed from various User Interface of different operating systems and different devices. Such as Mobile, Computers, etc.

Main Component of Web service :(XML)
The main advantage that a web service provides by means of XML.XML can be accessed and viewed from different Interface without worrying about platform or operating system.
Ex: A web service written in Java can be accessed by a .Net or Perl Client by XML (request & response) vice versa.

In Java they are variety of ways from which we can create, deploy and access web service.
We will be seeing the below concepts:


I.   Basics of Web service:
a.       Web Service Architecture
b.      Basic flow of Web service
c.       SOAP
d.      WSDL
e.       UDDI


II. Java way of handling web services:

a.       JAX-WS  ( Java web service API)
b.      JAX-RPC (Java remote procedure call)
c.       JAXP (Java Parsing API)
d.      JAXM (Java Messaging API)
e.       JAXB (Java XML Binding API)          
f.       JAXR (Java Metadata Registry API)
g.      JAX-RS (Java Restful Services)


They Beginning part would be more concept wise it would be boring but it is important to understand these terminologies.
 

  a. Web Service Architecture :


They are two ways to examine the Web Service Architecture they are:

-          Examining individual role of a each webservie actor
-          Web Service protocol stack

 Roles of Web service :


 It has three components :

Service provider
This is the provider of the web service. The service provider implements the service
and makes it available on the Internet.

Service requestor
This is any consumer of the web service. The requestor utilizes an existing web
service by opening a network connection and sending an XML request.

Service registry
This is a logically centralized directory of services. The registry provides a central
place where developers can publish new services or find existing ones. It therefore
serves as a centralized clearinghouse for companies and their services.

Web Service protocol stack :

They web service protocol stack is still evolving .

It has four main layers

Service Transport :


This layer is responsible for the transporting of Message between Applications currently have HTTP,SMTP,FTP,BEEP.

XML Messaging :


Responsible for encoding message in a common xml format that message can be understood by either end .includes XML-RPC and SOAP.

Service description
This layer is responsible for describing the public interface to a specific web service.
Currently, service description is handled via the Web Service Description Language
(WSDL).

 Service discovery
This layer is responsible for centralizing services into a common registry, and
providing easy publish/find functionality. Currently, service discovery is handled
via Universal Description, Discovery, and Integration (UDDI).
As web services evolve, additional layers may be added, and additional technologies may
be added to each layer.

   b. Basic flow of Web service :


To understand the basic flow we must know this term
SOAP, WSDL, UDDI [We will see in detail about these in later part as for know we will see what is what]

SOAP : Simple Object Access protocol .It is a XML based protocol for exchanging information .It can be used along with variety of protocol  such as HTTP,FTP etc along with various operating system.
Given below is  the simple request & response obtain from a web service created by JAX-WS technique in java. We will cover in detail about JAX-WS in later part.

package test;
import java.util.InputMismatchException;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService()
public class ss {
    @WebMethod(operationName = "hello")
    public String hello(@WebParam(name = "input")   // Method name hello accept a String      Paramter
    String input) {
        return input;
    }
}
After deploying this business method .We checks the request and response.

EX : SOAP REQUEST
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <ns0:hello xmlns:ns0="http://test/">
            <input>Hello World</input>
        </ns0:hello>
    </soap:Body>
</soap:Envelope>

EX: SOAP RESPONSE
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <ns0:helloResponse xmlns:ns0="http://test/">
            <return>Hello World</return>
        </ns0:helloResponse>
    </soap:Body>
</soap:Envelope>

WSDL :

-          Web Service Description Language.
-          It is a web grammar of specifying a public interface of web service. This public interface can include information on all publicly available functions, data type information for all XML messages, binding information about the specific transport protocol to be used, and address information for locating the specified Service.
-          WSDL is not necessarily tied to a specific XML messaging system, but it does include built-in extensions for describing SOAP services.


UDDI :

-          UDDI currently represents the discovery layer within the web service protocol stack.
-          UDDI was originally created by Microsoft, IBM, and Ariba, and represents a  technical specification for publishing and finding businesses and web services.
-           UDDI consists of two parts. First, UDDI is a technical specification for building a distribute directory of businesses and web services. Data is stored  within a specific XML format. The UDDI specification  includes API details for searching existing data and publishing new data.
-          Second, the UDDI Business Registry is a fully operational implementation of the UDDI  specification.
  
Accessing a Web Service: Service Requester Perspective 
 Find a Web service from UDDI
 Retrieve WSDL or XML-RPC human Instructions
Create a XML-RPC or SOAP Client
Invoke Remote Procedure Call

Creating a Web service: Service Developer Perspective 

                       
   Find the business functionality(business logic)

   Create a XML-RPC or SOAP Service Wrapper

   Create a WSDL or XML RPC Instructions

   Deploy Service

   Register new service via UDDI
                      

In my next post i will be covering in detail about Soap and other parts of Web service basics. so stay tuned and thanks for reading  and please comment your feedback.

                                              Index                                         Next >>     
                             
                                ----------------------------------------------------------------------------
          



Technology Blogs
blogs