0% found this document useful (0 votes)
46 views28 pages

IP Unit-5-1

The document provides an introduction and overview of AJAX (Asynchronous JavaScript and XML) and web services. It defines AJAX as a technique for exchanging data with a server and updating parts of a web page without reloading the entire page. The key aspects of AJAX covered include the XMLHttpRequest object, asynchronous client-server communication, and callback functions. Traditional web applications are compared to AJAX applications, highlighting how AJAX reduces page reloads and improves responsiveness. The roles of the XMLHttpRequest object, callback functions, and asynchronous requests and responses are described in the AJAX client-server architecture.

Uploaded by

Thejaa Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views28 pages

IP Unit-5-1

The document provides an introduction and overview of AJAX (Asynchronous JavaScript and XML) and web services. It defines AJAX as a technique for exchanging data with a server and updating parts of a web page without reloading the entire page. The key aspects of AJAX covered include the XMLHttpRequest object, asynchronous client-server communication, and callback functions. Traditional web applications are compared to AJAX applications, highlighting how AJAX reduces page reloads and improves responsiveness. The roles of the XMLHttpRequest object, callback functions, and asynchronous requests and responses are described in the AJAX client-server architecture.

Uploaded by

Thejaa Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

CS8651- Internet Programming Unit - 5 VI Semester CSE

UNIT 5 – AJAX AND WEB SERVICES

AJAX: AJAX client server architecture – XMLHttpRequest object – Call back methods; Web
Services: Introduction – Java Web Services basic – Creating, Publishing, Testing and
Describing a web service (WSDL) – Consuming a web service, Database driven web service
– SOAP.

5.1: INTRODUCTION TO AJAX

Definition of AJAX: AJAX (Asynchronous JavaScript and XML) is a technique of


exchanging data with a server, and updating parts of a web page - without reloading the
whole page. It uses client-side scripting to make web applications more responsive.
✓ AJAX applications separate client-side user interaction and server communication, and
run them in parallel to reduce the delay of server-side processing.

Advantages and Disadvantages of AJAX:


ADVANTAGES:
1. Reduce the traffic travels between the client and the server.
2. Response time is faster so increases performance and speed.
3. AJAX communicates over HTTP Protocol.
4. Asynchronous calls: AJAX makes asynchronous calls to a web server. This means
client browsers need not to wait for the arrival all data before start the rendering.
5. If a section of a page encounters any error, other sections do not get affected and the
data entered by the user is also not lost.

DISADVANTAGES:
1. It can increase design and development time.
2. More complex than building classic web application.
3. Less Accessibility: because all browsers do not completely support Javascript and
xmlHttpRequest object.
4. Due to security constraints, you can only use it to access information from the host
that served the initial page. If you need to display information from another server, it
is not possible within the AJAX.

5.1.1: Traditional Web Application vs. Ajax Applications

1. Traditional Web Applications:

The following figure depicts the interactions between the client and the server in traditional
web applications.
Step 1: The user fills in the form’s fields, and then submits the form.
Step 2: The browser generates a request to the server, which receives the request and process
it.
2

Step 3: The server generates and sends a response containing the exact page that the browser
will render.
Step 4: Browser loads the new page and temporarily makes the browser window blank. The
client waits for the server to respond and reloads the entire page.
Such a Synchronous request is being processed on the server; the user cannot interact with
the client web page.

2. Ajax Web Applications:

The following figure depicts the interactions between the client and the server in Ajax web
applications. Ajax adds a layer between the client and the server to manage communication.

Step 1: When the user interacts with the page, the client creates an XMLHttpRequest object
to manage a request.
Step 2: The XMLHttpRequest object sends the request to the server and awaits for
response. The requests are asynchronous so the user can continue interacting with
the application while the server processes the earlier request concurrently.
Step 3 & 4: Other user interactions results in additional requests to the server.
Step 5: Once the server responds, the XMLHttpRequest object that issued the request calls
a client-side function (also known as callback function) to process the data returned
by the server.
Step 6: This callback function performs the partial page update to display the data in the
existing web page without reloading the entire page.
3

5.1.2: Ajax Client-Server Architecture

Definition of AJAX: AJAX (Asynchronous JavaScript and XML) is a technique of


exchanging data with a server, and updating parts of a web page - without reloading the
whole page. It uses client-side scripting to make web applications more responsive.
✓ AJAX applications separate client-side user interaction and server communication, and
run them in parallel to reduce the delay of server-side processing.

The following figure depicts the interactions between the client and the server in Ajax web
applications. Ajax adds a layer between the client and the server to manage communication.

Step 1: When the user interacts with the page, the client creates an XMLHttpRequest object
to manage a request.
Step 2: The XMLHttpRequest object sends the request to the server and awaits for
response. The requests are asynchronous so the user can continue interacting with
the application while the server processes the earlier request concurrently.
Step 3 & 4: Other user interactions results in additional requests to the server.
Step 5: Once the server responds, the XMLHttpRequest object that issued the request calls
a client-side function (also known as callback function) to process the data returned
by the server.
Step 6: This callback function performs the partial page update to display the data in the
existing web page without reloading the entire page.
4

WORKING OF AJAX:

➢ XMLHttpRequest Object:

The XMLHttpRequest Object is the layer between the client and the server that creates and
manages asynchronous requests in Ajax applications. All modern browsers support the
XMLHttpRequest object (IE5 and IE6 use an ActiveXObject).

Creating an XMLHttpRequest Object:


All modern browsers (IE7+, Firefox, Chrome, Safari, and Opera) have a built-in
XMLHttpRequest object.
5

Syntax for creating an XMLHttpRequest object:

variable=new XMLHttpRequest();

Old versions of Internet Explorer (IE5 and IE6) use an ActiveX Object:

variable=new ActiveXObject("Microsoft.XMLHTTP");

various Methods and Properties of XMLHttpRequest Object:

PROPERTIES:
Property Description
onreadystatechange Stores the callback function – the event handler that gets called
when the server responds.
readystate Holds the status of the XMLHttpRequest. Changes from 0 to 4:
0: request not initialized
1: server connection established
2: request received
3: processing request
4: request finished and response is ready
status 200: "OK"
404: Page not found
statusText Additional information on the request’s status. It is used to
display error messages to the user when the request fails.
response Returns the response received from the server
responseText Text that is returned to the client by the server
responseXML If the server’s response is in XML format, this property contains
the XML document.

METHODS:
Method Description
open(method,url,async) Specifies the type of request, the URL, and if the request should
be handled asynchronously or not.
method: the type of request: GET or POST
url: the location of the file on the server
async: true (asynchronous) or false (synchronous)
send sends the request to the server
setRequestHeader Alters the request header
getResponseHeader Returns the header data that precedes the response body
getAllResponseHeaders Returns an array that contains all the headers data that precedes
the response body
abort Cancels the current request.
6

➢ Callback Functions:

✓ A callback function is a function passed as a parameter to another function. It is an


event handler that gets called when the server responds.
✓ If you have more than one AJAX task on your website, you should create ONE
standard function for creating the XMLHttpRequest object, and call this for each
AJAX task.
✓ The function call should contain the URL and what to do on onreadystatechange.

Example:
ajaExample.html

<html>
<head>
<style>
div {
border-style:solid;
border-color:blue;
border-width:5px
}
</style>
<script type="text/javascript">
var req;

function getContent(url)
{
try
{
if(window.XMLHttpRequest)
{
req=new XMLHttpRequest(); // Creating XMLHttpRequest Object
}
else
{
req=new ActiveXObject("Microsoft.XMLHTTP");
}
req.onreadystatechange=callbackfun; // Callback function call to handle response
req.open("GET",url, true); // open the connection to the requested resource
req.send(); // send the request to the server
}
catch(e) { alert("Request failed"); }
}
7

function callbackfun()
{
if(req.readyState==4 && req.status==200)
Callback
{
Method
document.getElementById('display').innerHTML=req.responseText;
}
}

</script>
</head>
<body>
<h3><center>
<input type="button" value="Flowers" onclick="getContent('flowers.html')">
<input type="button" value="Fruits" onclick="getContent('fruits.html')">
<div id="display" ><h2>Let AJAX change this text and picture</h2></div><br>
</center></h3>
</body></html>

Flowers.html

<html>
<body><br>
<img src="flower1.jpg" width="100" height="100">
<img src="flower2.jpg" width="100" height="100">
<img src="flower3.jpg" width="100" height="100">
</body>
</html>
Fruits.html

<html>
<body>
<br>
<img src="fruit1.jpg" width="100" height="100">
<img src="fruit2.jpg" width="100" height="100">
<img src="fruit3.jpg" width="100" height="100">

</body>
</html>
8

Output:
9

5.2.1: WEB SERVICES BASICS

Definition: A Web Service is a software component stored on one computer that can be
accessed via method calls by an application (or other software component) on another
computer over a network. These software components are not directly used by the end-users.
Web Services communicate using technologies such as XML, SOAP (an XML based
protocol) and HTTP.

Examples of Web Service:


1. Credit Card validation System: The client simply enters the ID and password for the
credit card and web service reports the validity of it.
2. Whether Forecast System: The client submits the location and the web service returns the
information about current whether predictions.

✓ A web service normally resides on a server.


✓ The application (the client) that accesses the web service sends a method call over a
network to the remote machine, which processes the call and returns a response over the
network to the application.

✓ Basic Web Service Model:


The following diagram shows the basic web service model:

Web Service UDDI


Registration

Publish Web Service


using WSDL Finds Web Service and
WSDL WSDL its location using WSDL

Web Service Provider SOAP Web Service


Requestor (the client)
Bind and invoke the
web service

Making a web service available to client is known as publishing a web service;

Using a web service from a client application is known as consuming a web service;
10

Following are the steps that a web service model follows:

1. A service provider publishes a web service in the web service registry.


2. A web client who demands for the same web service searches in the registry. After finding
a match for the desired web service, the client chooses it.
3. Then the client binds to the corresponding web service provider and invokes for the
service.

✓ Interaction between a web service client and web service:

Client Server

Client Proxy
Internet Web Service
Code Object

✓ An application that consumes a web service consists of two parts:


1. An object of a Proxy Class for interacting with the web service
2. The client code.
✓ The client code consumes the web service by invoking methods on the proxy object.
✓ The Proxy Object handles the details of communication with the web service on behalf of
the client.
✓ The web service performs the corresponding tasks and returns the results to the proxy
object, which then returns the result to the client code.
✓ Request to and responses form web services are created with JAX-WS and transmitted via
SOAP.
✓ Any client capable of generating and processing SOAP messages can interact with a web
service.

Advantages of Web Services:

1. Application and Data Integration


2. Versatility
3. Code re-use
4. Cost saving
5. Interoperability
11

Disadvantages of Web Service:


1. Big in Size
2. Low security due to HTTP
3. Lack of access from browser
4. Won't leverage emerging Web developments (Semantic Web, AJAX
XMLHttpRequest, etc.)

5.2.2: Creating, Publishing, Testing a Web Service

CREATING A WEB SERVICE TO ADD TWO INTEGERS:

Steps:

1. Create a Web Application Project


2. Create a Web Service
3. Add / Update a web method
4. Publish the web service (Build, Deploy and Run the Project)
5. Test the Web service.

1. Creating a Web Application Project:

To create a web application, perform the following steps:


Step 1: Select File > New project
Step 2: Select Web from the dialog box, then select the Web Application from the Projects
list.
Step 3: Specify the name of the project.
Step 4: Slect GlassFish Server 3 from the server drop-down list.
Step 5: Select Java EE 5 from the J2EE Version drop-down list.
Step 6: Click Finish.

2. Creating a Web Service:

Adding a Web Service Class to a Web Application Project:

Step 1: Right click on the project name and select New > Web Service…
Step 2: Specify the name of the web service in the Web Service name field.
Step 3: Specify the package name in the package filed.
Step 4: Click Finish.
12

3. Add / Update a web method:

IntegerOpr.java

package com.ip;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

@WebService()
public class IntegerOpr
{
/* Web service operation */
@WebMethod(operationName = "Add")
public int Add(@WebParam(name = "n1") int n1, @WebParam(name = "n2") int n2)
{
int sum = n1+n2;
return sum;
}
}

Annotations used:

@WebService() – indicates that the class IntegerOpr implements a web service.


@WebMethod(operationName = "Add") – Indiates that this method can be called
remotely.
@WebParam(name = "n1") & @WebParam(name = "n2") – Indicates that this method
contains parameters and name indicates the parameter name that is exposed to the web
service client.
13

4. Publishing the web service (Build, Deploy and Run the Project)

Build and publish (deploy) the web service so that the client can consume its service.
Step 1: Right click on the project name and select Build Project to compile the source codes
in the project.
Step 2: When the project compiled successfully, select Deploy Project to deploy the project
to the GlassFish server.
5. Testing the Web service.
In the IDE's Projects tab, expand the Web Services node of the IntegerOpr Application
project. Right-click the IntegerOpr node, and choose Test Web Service.
14

CONSUMING THE WEB SERVICE TO ADD TWO INTEGERS:

Client : Java Class in Java SE Application


Create a standard Java application. The wizard that you use to create the application also
creates a Java class. Then use the IDE's tools to create a client and consume the web service
that you created.
1. Choose File > New Project. Select Java Application from the Java category. Name
the project MyWebClient. Leave Create Main Class selected and accept all other
default settings. Click Finish.
2. Right-click the MyWebClient node and choose New > Web Service Client. The
New Web Service Client wizard opens.
3. Select Project as the WSDL source. Click Browse. Browse to the IntegerOpr web
service in the IntegerOpr project. When you have selected the web service, click OK.
4. Leave the other settings at default and click Finish. The Projects window displays the
new web service client, with a node for the add method that you created:

5. In the Main.java, insert the code to call web services operation.

Main.java

package mywebclient;
public class Main {

public static void main(String[] args)


{
System.out.println("Sum (40,50) = "+add(40,50));
}
// Code to invoke web service operation
private static int add(int n1, int n2) {
com.ip.IntegerOprService service = new com.ip.IntegerOprService();
com.ip.IntegerOpr port = service.getIntegerOprPort();
return port.add(n1, n2);
}
15

6. Run Main.java to see the result.

5.2.3: Describing a Web Service (WSDL – Web Services Description Language)

Once we implement, compile and deploy a web service on an application server, a


client application can consume the web service. To do so, the client must know where to find
the web service and must be provided with a description of how to interact with the web
service. For this purpose JAX-WS uses the WSDL.

Definition: (WSDL – Web Services Description Language)


WSDL is a XML vocabulary for describing web services. It is a language for
describing the web service and how to access them. WSDL file contains the description about
the following:
• Web Service Name and the method to access it
• What methods are available on the web service
• What parameters that the methods expect
• What each web method returns

The WSDL Document Structure:

A WSDL document is just a simple XML document.

It contains set of definitions to describe a web service.

A WSDL document describes a web service using these major elements:


Element Description
<types> A container for data type definitions used by the web service
16

<message> A typed definition of the data being communicated


<portType> A set of operations supported by one or more endpoints
<binding> A protocol and data format specification for a particular port type

The main structure of a WSDL document looks like this:


<definitions>

<types>
data type definitions........
</types>

<message>
definition of the data being communicated....
</message>

<portType>
set of operations......
</portType>

<binding>
protocol and data format specification....
</binding>

</definitions>

WSDL Types
The <types> element defines the data types that are used by the web service.

WSDL Messages
The <message> element defines the data elements of an operation.
Each message can consist of one or more parts (parameters of method).

WSDL Ports
The <portType> element is the most important WSDL element.
It describes a web service, the operations that can be performed, and the messages that are
involved.
Operation Types
The request-response type is the most common operation type, but WSDL defines four types:
Type Definition
The operation can receive a message but will not return a
One-way
response
17

Request-response The operation can receive a request and will return a response
Solicit-response The operation can send a request and will wait for a response
The operation can send a message but will not wait for a
Notification
response

WSDL Bindings
The <binding> element defines the data format and protocol for each port type.

<Service> - This element specifies the name for overall web service.

Example: WSDL document for a web service that add two integers:

<definitions name="IntegerOprService">

<types>
<xs:schema>
<xs:element name="Add" >
<xs:element name="AddResponse" type="tns:AddResponse" />

<xs:complexType name="Add">
<xs:sequence>
<xs:element name="n1" type="xs:int" />
<xs:element name="n2" type="xs:int" />
</xs:sequence>
</xs:complexType>

<xs:complexType name="AddResponse">
<xs:sequence>
<xs:element name="return" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:schema>
</types>

<message name="Add">
<part name="parameters" element="tns:Add"/>
</message>
<message name="AddResponse">
<part name="parameters" element="tns:AddResponse"/>
18

</message>

<portType name="IntegerOpr">
<operation name="Add">
<input message="tns:Add"/>
<output message="tns:AddResponse"/>
</operation>
</portType>

<binding name="IntegerOprPortBinding" type="tns:IntegerOpr">


<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="Add">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>

<service name="IntegerOprService">
<port name="IntegerOprPort" binding="tns:IntegerOprPortBinding">
<soap:address location="http://localhost:8080/IntegerOpr/IntegerOprService"/>
</port>
</service>

</definitions>

Advantages of WSDL:
1. WSDL is platform independent.
2. WSDL provides a structured approach to define web service.
3. A client can locate a web service and invoke its public methods with (or) without
programming efforts.
4. Changes can be made in WSDL documents dynamically.

Disadvantages of WSDL:
Though a wsdl provides details on how to invoke a service, it does not contain
information about the use of the service. Programmer should be aware about the use of a
service.
19

5.2.4: SOAP – Simple Object Access Protocol

Simple Object Access Protocol (SOAP) is a protocol based on XML to facilitate remote
procedure calls over HTTP. It is a W3C recommendation used by the web service for
exchanging information between web service clients and web services.
It is a wire protocol because it transmits request-response message “along the wire”.

SOAP Building Blocks:

A SOAP message is an ordinary XML document containing the following elements:


• An Envelope element that identifies the XML document as a SOAP message
• A Header element that contains header information
• A Body element that contains call and response information
• A Fault element containing errors and status information

Skeleton SOAP Message

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Header>
... Envelop
</soap:Header>
<soap:Body>
... Head Body
<soap:Fault>
...
</soap:Fault> Fault
</soap:Body>
</soap:Envelope>
Syntax Rules:

Here are some important syntax rules:


• A SOAP message MUST be encoded using XML
• A SOAP message MUST use the SOAP Envelope namespace
• A SOAP message MUST use the SOAP Encoding namespace
• A SOAP message must NOT contain a DTD reference
• A SOAP message must NOT contain XML Processing Instructions

Example:

SOAP Request

<?xml version="1.0" encoding="UTF-8"?>


20

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header/>
<S:Body>
<ns2:Add xmlns:ns2="http://ip.com/">
<n1>40</n1>
<n2>50</n2>
</ns2:Add>
</S:Body>
</S:Envelope>

SOAP Response

<?xml version="1.0" encoding="UTF-8"?>


<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:AddResponse xmlns:ns2="http://ip.com/">
<return>90</return>
</ns2:AddResponse>
</S:Body>
</S:Envelope>

SOAP Advantages:

1. Platform independent.
2. Uses XML to send and receive messages.
3. SOAP is also a simple way to accomplish remote object/component/service
communications.
4. Uses standard internet HTTP protocol.
5. SOAP runs over HTTP, which eliminates firewall problems.
6. A protocol for exchanging information in a decentralized and distributed environment.

Disadvantages:

1. The SOAP specification contains no mention of security facilities.


2. SOAP clients do not hold any stateful references to remote objects.
21

5.2.5: DATABASE DRIVEN WEB SERVICES

Database driven web service is one that uses database for collecting and storing
information. It interacts with the database based upon request issued by the web service
client.

CREATING A WEB SERVICE FOR AIRLINES DATABASE:

Steps for creating and connecting database:


1. Create a database AirLinesDB in MSAccess.
2. Create a table called AirInfo which stores all the information about the flights.
3. Populate the database with necessary data values.
4. Create a Data Source Name (DSN) to access the DB.
5. Then open netbeans IDE.
6. In the services tab, expand the Databases node.
7. Expand the Drivers node > right click on JDBC-ODBC Bridge > Connect
Using….
8. Type the JDBC URL to map the driver with your DSN and click OK.
9. Now the mapped database will be displayed in the Database URL.
22

Steps for creating a web service:


1. Create a Web Application Project
2. Create a Web Service
3. Add / Update a web method
4. Publish the web service (Build, Deploy and Run the Project)
5. Test the Web service.

1. Creating a Web Application Project:


To create a web application, perform the following steps:
Step 1: Select File > New project
Step 2: Select Web from the dialog box, then select the Web Application from the Projects
list.
Step 3: Specify the name of the project.
Step 4: Slect GlassFish Server 3 from the server drop-down list.
Step 5: Select Java EE 5 from the J2EE Version drop-down list.
Step 6: Click Finish.

2. Creating a Web Service:


Adding a Web Service Class to a Web Application Project:
Step 1: Right click on the project name and select New > Web Service…
Step 2: Specify the name of the web service in the Web Service name field.
Step 3: Specify the package name in the package filed.
Step 4: Click Finish.

3. Add / Update a web method:

AirLineInfo.java

package com.ip;

import java.sql.*;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
23

@WebService()
public class AirLineInfo {
Connection conn;
Statement stmt;
ResultSet rs;
String result=null;

@WebMethod(operationName = "getInfo")
public String getInfo(@WebParam(name = "FID")
int FID) {

try
{
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc:odbc:Air","","");
stmt=conn.createStatement();
rs=stmt.executeQuery("select * from AirInfo where FId ="+FID);

if(rs.next())
{

result="Flight Id:"+rs.getInt(1);
result+="-->Name:"+rs.getString(2);
result+="-->Source:"+rs.getString(3);
result+="-->Destination:"+rs.getString(4);
result+="-->Capacity:"+rs.getInt(5);
}

else
result="Invalid Flight ID";
}
catch(Exception e){}
return result;
}
}

4. Publishing the web service (Build, Deploy and Run the Project)

Build and publish (deploy) the web service so that the client can consume its service.
Step 1: Right click on the project name and select Build Project to compile the source codes
in the project.
Step 2: When the project compiled successfully, select Deploy Project to deploy the project
to the GlassFish server.
24

CONSUMING THE WEB SERVICE FOR AIRLINES DATABASE:


Home.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


<html>
<head>
</head>
<body>
<form name="myform" method="GET"
action="http://localhost:8080/AirServlet/AirServlet">
Enter the flight Id:
<input type="text" name="fid"><br>
<input type="submit" value="Send Request">
</form>
</body>
</html>

AirServlet.java

package mypack;

import com.ip.AirLineInfoService;
import java.io.*;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import javax.xml.ws.WebServiceRef;

@WebServlet(name="AirServlet", urlPatterns={"/AirServlet"})

public class AirServlet extends HttpServlet {

@WebServiceRef ( wsdlLocation =
"WEB-INF/wsdl/localhost_8080/AirLines/AirLineInfoService.wsdl")
private AirLineInfoService service;

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
int fid=Integer.parseInt(request.getParameter("fid"));
out.println("<html><body>");
out.println("<center>");
25

out.println("<h1>Requested Information for the Flight Id:"+fid+"</h1>");


out.println("<h3>"+getInfo(fid)+"</h3>");
out.println("</center>");
out.println("</html></body>");
}

private String getInfo(int fid) {


com.ip.AirLineInfo port = service.getAirLineInfoPort();
return port.getInfo(fid);
}
}
26

5.2.6: UDDI

UDDI is an XML-based standard for describing, publishing, and finding web services.

• UDDI stands for Universal Description, Discovery, and Integration.


• Registry of Web Services
o “Yellow Pages” for clients
• Provides
o Dynamic discovery of Web Service
o Dynamic binding to Web Service
• Searchable
o Business type, geographic location, contact info, etc

• Provides client with the service’s WSDL


o Client gets information needed to connect and make use of a service
• UDDI itself is a Web Service
o Accessed using SOAP

• UDDI registry is updated by Web Services providers


o Service providers advertise services by registering its WSDL
• Registry can be:
o Private
▪ Listing just services for internal use
o Public UDDI
▪ Listing services that are accessible to all
• Limited number of “well known” public UDDI registries on the Internet
o Point to other registries
o Similar to DNS today

• Example: Restocking item


o Inventory program does a lookup in a UDDI repository for one or more
companies that offer item
o Select a company based on set of criteria
▪ e.g. price and payment terms
o Then:
▪ retrieve the WSDL from UDDI
▪ examine its contents to learn how and where
▪ connect to that company’s service

UDDI has two sections:


• A registry of all web service's metadata, including a pointer to the WSDL
description of a service.
27

• A set of WSDL port type definitions for manipulating and searching that
registry.
• Relationship between SOAP, WSDL & UDDI:

Registry
(UDDI) Publish
Find
(WSDL)
(SOAP)
Service
Service
Provider
Requestor
Bind
(SOAP)

UDDI Elements:

A business or a company can register three types of information into a UDDI registry. This
information is contained in three elements of UDDI.

These three elements are:


• White Pages,
• Yellow Pages, and
• Green Pages.

White Pages
White pages contain:
• Basic information about the company and its business.
• Basic contact information including business name, address, contact phone number,
etc.

Yellow Pages
• Yellow pages contain more details about the company

Green Pages
Green pages contain technical information about a web service. A green page allows
someone to bind to a Web service after it's been found. It includes:
• The various interfaces
• The URL locations
• Discovery information and similar data required to find and run the Web service.

UDDI Benefits

1. It delivers visibility when identifying which services within the organization can be
reused to address a business need.
28

2. It promotes reuse and prevents reinvention.


3. It supports service configurability and adaptability by using the service-oriented
architectural principle of location and transport independence. Users can dynamically
discover services stored in the UDDI registry.
4. It allows you to understand and manage relationships between services, component
versions and dependencies.
5. It makes it possible to manage the business service lifecycle.

You might also like