You are on page 1of 27

Object 2

XML Tutorial
XML stands for eXtensible Markup Language.
XML was designed to store and transport data.
XML was designed to be both human- and machine-readable.
XML is a software- and hardware-independent tool for storing and transporting data.

What is XML?
 XML stands for eXtensible Markup Language
 XML is a markup language much like HTML
 XML was designed to store and transport data
 XML was designed to be self-descriptive
 XML is a W3C Recommendation

XML Example 1
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

The XML above is quite self-descriptive:


 It has sender information
 It has receiver information
 It has a heading
 It has a message body
But still, the XML above does not DO anything. XML is just information wrapped in tags.
Someone must write a piece of software to send, receive, store, or display it in an application like a
reminder in a calendar.

The Difference Between XML and HTML


XML and HTML were designed with different goals:
 XML was designed to carry data - with focus on what data is
 HTML was designed to display data - with focus on how data looks
 XML tags are not predefined like HTML tags are
XML Does Not Use Predefined Tags
The XML language has no predefined tags.
The tags in the example above (like <to> and <from>) are not defined in any XML standard. These
tags are "invented" by the author of the XML document.
HTML works with predefined tags like <p>, <h1>, <table>, etc.
With XML, the author must define both the tags and the document structure.

XML is Extensible
Most XML applications will work as expected even if new data is added (or removed).
Imagine an application designed to display the original version of note.xml (<to> <from>
<heading> <body>).
Then imagine a newer version of note.xml with added <date> and <hour> elements, and a removed
<heading>.
The way XML is constructed, older version of the application can still work:
<note>
<date>2015-09-01</date>
<hour>08:30</hour>
<to>Tove</to>
<from>Jani</from>
<body>Don't forget me this weekend!</body>
</note>

XML Simplifies Things


 XML simplifies data sharing
 XML simplifies data transport
 XML simplifies platform changes
 XML simplifies data availability
Many computer systems contain data in incompatible formats. Exchanging data between
incompatible systems (or upgraded systems) is a time-consuming task for web developers. Large
amounts of data must be converted, and incompatible data is often lost.
XML stores data in plain text format. This provides a software- and hardware-independent way of
storing, transporting, and sharing data.
XML also makes it easier to expand or upgrade to new operating systems, new applications, or new
browsers, without losing data.
With XML, data can be available to all kinds of "reading machines" like people, computers, voice
machines, news feeds, etc.
How Can XML be Used?
XML is used in many aspects of web development.
XML is often used to separate data from presentation.

XML Separates Data from Presentation


XML does not carry any information about how to be displayed.
The same XML data can be used in many different presentation scenarios.
Because of this, with XML, there is a full separation between data and presentation.

XML is Often a Complement to HTML


In many HTML applications, XML is used to store or transport data, while HTML is used to format
and display the same data.

XML Separates Data from HTML


When displaying data in HTML, you should not have to edit the HTML file when the data changes.
With XML, the data can be stored in separate XML files.
With a few lines of JavaScript code, you can read an XML file and update the data content of any
HTML page.

Transaction Data
Thousands of XML formats exist, in many different industries, to describe day-to-day data
transactions:
 Stocks and Shares
 Financial transactions
 Medical data
 Mathematical data
 Scientific measurements
 News information
 Weather services

XML Syntax Rules


The syntax rules of XML are very simple and logical. The rules are easy to learn, and easy to use.
XML Documents Must Have a Root Element
XML documents must contain one root element that is the parent of all other elements:
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
In this example <note> is the root element:
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

The XML Prolog


This line is called the XML prolog:
<?xml version="1.0" encoding="UTF-8"?>
The XML prolog is optional. If it exists, it must come first in the document.

All XML Elements Must Have a Closing Tag


In XML, it is illegal to omit the closing tag. All elements must have a closing tag:
<p>This is a paragraph.</p>
<br />
Note: The XML prolog does not have a closing tag! This is not an error. The prolog is not a part of
the XML document.

XML Tags are Case Sensitive


XML tags are case sensitive. The tag <Letter> is different from the tag <letter>.
Opening and closing tags must be written with the same case:
<message>This is correct</message>

"Opening and closing tags" are often referred to as "Start and end tags". Use whatever you prefer. It
is exactly the same thing.
XML Elements Must be Properly Nested
In HTML, you might see improperly nested elements:
<b><i>This text is bold and italic</b></i>
In XML, all elements must be properly nested within each other:
<b><i>This text is bold and italic</i></b>

In the example above, "Properly nested" simply means that since the <i> element is opened inside
the <b> element, it must be closed inside the <b> element.

XML Attribute Values Must Always be Quoted


XML elements can have attributes in name/value pairs just like in HTML.
In XML, the attribute values must always be quoted:
<note date="12/11/2007">
<to>Tove</to>
<from>Jani</from>
</note>

Entity References
Some characters have a special meaning in XML.
If you place a character like "<" inside an XML element, it will generate an error because the parser
interprets it as the start of a new element.
This will generate an XML error:
<message>salary < 1000</message>
To avoid this error, replace the "<" character with an entity reference:
<message>salary &lt; 1000</message>
There are 5 pre-defined entity references in XML:

&lt; < less than


&gt; > greater than
&amp; & ampersand
&apos; ' apostrophe
&quot; " quotation mark
Only < and & are strictly illegal in XML, but it is a good habit to replace > with &gt; as well.

Comments in XML
The syntax for writing comments in XML is similar to that of HTML:
<!-- This is a comment -->
Two dashes in the middle of a comment are not allowed:
<!-- This is an invalid -- comment -->

XML Elements
An XML document contains XML Elements.

What is an XML Element?


An XML element is everything from (including) the element's start tag to (including) the element's
end tag.
<price>29.99</price>
An element can contain:
 text
 attributes
 other elements
 or a mix of the above
<bookstore>
<book category="children">
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title>Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
In the example above:
<title>, <author>, <year>, and <price> have text content because they contain text (like 29.99).
<bookstore> and <book> have element contents, because they contain elements.
<book> has an attribute (category="children").
Empty XML Elements
An element with no content is said to be empty.
In XML, you can indicate an empty element like this:
<element></element>
You can also use a so called self-closing tag:
<element />
The two forms produce identical results in XML software (Readers, Parsers, Browsers).
Empty elements can have attributes.

XML Naming Rules


XML elements must follow these naming rules:
 Element names are case-sensitive
 Element names must start with a letter or underscore
 Element names cannot start with the letters xml (or XML, or Xml, etc)
 Element names can contain letters, digits, hyphens, underscores, and periods
 Element names cannot contain spaces
Any name can be used, no words are reserved (except xml).

Best Naming Practices


Create descriptive names, like this: <person>, <firstname>, <lastname>.
Create short and simple names, like this: <book_title> not like this: <the_title_of_the_book>.
Avoid "-". If you name something "first-name", some software may think you want to subtract
"name" from "first".
Avoid ".". If you name something "first.name", some software may think that "name" is a property
of the object "first".
Avoid ":". Colons are reserved for namespaces (more later).
Non-English letters like éòá are perfectly legal in XML, but watch out for problems if your software
doesn't support them!

Naming Conventions
Some commonly used naming conventions for XML elements:

Style Example Description


Lower
<firstname> All letters lower case
case
Upper <FIRSTNAME> All letters upper case
case
Snake case <first_name> Underscore separates words (commonly used in SQL databases)
Pascal Uppercase first letter in each word (commonly used by C
<FirstName>
case programmers)
Camel Uppercase first letter in each word except the first (commonly used in
<firstName>
case JavaScript)
Tip! Choose your naming style, and be consistent about it!
XML documents often have a corresponding database. A common practice is to use the naming
rules of the database for the XML elements.

XML Elements are Extensible


XML elements can be extended to carry more information.
Look at the following XML example:
<note>
<to>Tove</to>
<from>Jani</from>
<body>Don't forget me this weekend!</body>
</note>
Let's imagine that we created an application that extracted the <to>, <from>, and <body> elements
from the XML document to produce this output:

MESSAGE
To: Tove
From: Jani
Don't forget me this weekend!
Imagine that the author of the XML document added some extra information to it:
<note>
<date>2008-01-10</date>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Should the application break or crash?
No. The application should still be able to find the <to>, <from>, and <body> elements in the XML
document and produce the same output.
This is one of the beauties of XML. It can be extended without breaking applications.
XML DOM

What is the DOM?


The Document Object Model (DOM) defines a standard for accessing and manipulating documents:
"The W3C Document Object Model (DOM) is a platform and language-neutral interface that
allows programs and scripts to dynamically access and update the content, structure, and style of a
document."
The HTML DOM defines a standard way for accessing and manipulating HTML documents. It
presents an HTML document as a tree-structure.
The XML DOM defines a standard way for accessing and manipulating XML documents. It
presents an XML document as a tree-structure.
Understanding the DOM is a must for anyone working with HTML or XML.

The HTML DOM


All HTML elements can be accessed through the HTML DOM.
This example changes the value of an HTML element with id="demo":

Example
<h1 id="demo">This is a Heading</h1>

<button type="button"
onclick="document.getElementById('demo').innerHTML = 'Hello World!'">Click Me!
</button>

The XML DOM


All XML elements can be accessed through the XML DOM.

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

<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>

<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>

</bookstore>
This code retrieves the text value of the first <title> element in an XML document:

Example
txt = xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;
The XML DOM is a standard for how to get, change, add, and delete XML elements.
This example loads a text string into an XML DOM object, and extracts the info from it with
JavaScript:

Example
<html>
<body>

<p id="demo"></p>

<script>
var text, parser, xmlDoc;

text = "<bookstore><book>" +
"<title>Everyday Italian</title>" +
"<author>Giada De Laurentiis</author>" +
"<year>2005</year>" +
"</book></bookstore>";

parser = new DOMParser();


xmlDoc = parser.parseFromString(text,"text/xml");

document.getElementById("demo").innerHTML =
xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;
</script>

</body>
</html>
JSP
Java Server Pages (JSP) is a server-side programming technology that enables the creation of
dynamic, platform-independent method for building Web-based applications. JSP have access to the
entire family of Java APIs, including the JDBC API to access enterprise databases.

What is JavaServer Pages?


JavaServer Pages (JSP) is a technology for developing Webpages that supports dynamic content.
This helps developers insert java code in HTML pages by making use of special JSP tags, most of
which start with <% and end with %>.
A JavaServer Pages component is a type of Java servlet that is designed to fulfill the role of a user
interface for a Java web application. Web developers write JSPs as text files that combine HTML or
XHTML code, XML elements, and embedded JSP actions and commands.
Using JSP, you can collect input from users through Webpage forms, present records from a
database or another source, and create Webpages dynamically.
JSP tags can be used for a variety of purposes, such as retrieving information from a database or
registering user preferences, accessing JavaBeans components, passing control between pages, and
sharing information between requests, pages etc.

The Lifecycle of a JSP Page


The JSP pages follow these phases:
 Translation of JSP Page
 Compilation of JSP Page
 Classloading (the classloader loads class file)
 Instantiation (Object of the Generated Servlet is created).
 Initialization ( the container invokes jspInit() method).
 Request processing ( the container invokes _jspService() method).
 Destroy ( the container invokes jspDestroy() method).
As depicted in the above diagram, JSP page is translated into Servlet by the help of JSP translator.
The JSP translator is a part of the web server which is responsible for translating the JSP page into
Servlet. After that, Servlet page is compiled by the compiler and gets converted into the class file.
Moreover, all the processes that happen in Servlet are performed on JSP later like initialization,
committing response to the browser and destroy.

Creating a simple JSP Page


To create the first JSP page, write some HTML code as given below, and save it by .jsp extension.
We have saved this file as index.jsp. Put it in a folder and paste the folder in the web-apps directory
in apache tomcat to run the JSP page.

index.jsp
Let's see the simple example of JSP where we are using the scriptlet tag to put Java code in the JSP
page. We will learn scriptlet tag later.
1. <html>
2. <body>
3. <% out.print(2*5);%>
4. </body>
5. </html>
It will print 10 on the browser.
JSP Tags *Important

JSP Scriptlet tag (Scripting elements)


In JSP, java code can be written inside the jsp page using the scriptlet tag. Let's see what are the
scripting elements first.

JSP Scripting elements


The scripting elements provides the ability to insert java code inside the jsp. There are three types of
scripting elements:
 scriptlet tag
 expression tag
 declaration tag

JSP scriptlet tag


A scriptlet tag is used to execute java source code in JSP. Syntax is as follows:
1. <% java source code %>

Example of JSP scriptlet tag


In this example, we are displaying a welcome message.
1. <html>
2. <body>
3. <% out.print("welcome to jsp"); %>
4. </body>
5. </html>

****IMPORTANT

Example of JSP scriptlet tag that prints the user name


In this example, we have created two files index.html and welcome.jsp. The index.html file gets the
username from the user and the welcome.jsp file prints the username with the welcome message.
File: index.html
1. <html>
2. <body>
3. <form action="welcome.jsp">
4. <input type="text" name="uname">
5. <input type="submit" value="go"><br/>
6. </form>
7. </body>
8. </html>
File: welcome.jsp
<html>
1. <body>
2. <%
3. String name=request.getParameter("uname");
4. out.print("welcome "+name);
5. %>
6. </form>
7. </body>
8. </html>

JSP expression tag


The code placed within JSP expression tag is written to the output stream of the response. So you
need not write out.print() to write data. It is mainly used to print the values of variable or method.

Syntax of JSP expression tag


1. <%= statement %>

Example of JSP expression tag


In this example of jsp expression tag, we are simply displaying a welcome message.
1. <html>
2. <body>
3. <%= "welcome to jsp" %>
4. </body>
5. </html>

Example of JSP expression tag that prints current time


To display the current time, we have used the getTime() method of Calendar class. The getTime() is
an instance method of Calendar class, so we have called it after getting the instance of Calendar
class by the getInstance() method.
index.jsp
<html>
1. <body>
2. Current Time: <%= java.util.Calendar.getInstance().getTime() %>
3. </body>
4. </html>

Example of JSP expression tag that prints the user name


In this example, we are printing the username using the expression tag. The index.html file gets the
username and sends the request to the welcome.jsp file, which displays the username.
File: index.jsp
1. <html>
2. <body>
3. <form action="welcome.jsp">
4. <input type="text" name="uname"><br/>
5. <input type="submit" value="go">
6. </form>
7. </body>
8. </html>
File: welcome.jsp
1. <html>
2. <body>
3. <%= "Welcome "+request.getParameter("uname") %>
4. </body>
5. </html>

JSP Declaration Tag


The JSP declaration tag is used to declare fields and methods.
The code written inside the jsp declaration tag is placed outside the service() method of auto
generated servlet.
So it doesn't get memory at each request.
Syntax of JSP declaration tag
The syntax of the declaration tag is as follows:
<%! field or method declaration %>

Difference between JSP Scriptlet tag and Declaration tag


Jsp Scriptlet Tag Jsp Declaration Tag
The jsp scriptlet tag can only declare variables The jsp declaration tag can declare variables as
not methods. well as methods.
The declaration of scriptlet tag is placed inside The declaration of jsp declaration tag is placed
the _jspService() method. outside the _jspService() method.

Example of JSP declaration tag that declares field


In this example of JSP declaration tag, we are declaring the field and printing the value of the
declared field using the jsp expression tag.

index.jsp
1. <html>
2. <body>
3. <%! int data=50; %>
4. <%= "Value of the variable is:"+data %>
5. </body>
6. </html>
Example of JSP declaration tag that declares method
In this example of JSP declaration tag, we are defining the method which returns the cube of given
number and calling this method from the jsp expression tag. But we can also use jsp scriptlet tag to
call the declared method.

index.jsp
1. <html>
2. <body>
3. <%!
4. int cube(int n){
5. return n*n*n*;
6. }
7. %>
8. <%= "Cube of 3 is:"+cube(3) %>
9. </body>
10. </html>

JSP request implicit object


The JSP request is an implicit object of type HttpServletRequest i.e. created for each jsp request by
the web container. It can be used to get request information such as parameter, header information,
remote address, server name, server port, content type, character encoding etc.
It can also be used to set, get and remove attributes from the jsp request scope.
Let's see the simple example of request implicit object where we are printing the name of the user
with welcome message.

Example of JSP request implicit object


index.html
1. <form action="welcome.jsp">
2. <input type="text" name="uname">
3. <input type="submit" value="go"><br/>
4. </form>

welcome.jsp
1. <%
2. String name=request.getParameter("uname");
3. out.print("welcome "+name);
4. %>
Output

JSP response implicit object


In JSP, response is an implicit object of type HttpServletResponse. The instance of
HttpServletResponse is created by the web container for each jsp request.
It can be used to add or manipulate response such as redirect response to another resource, send
error etc.
Let's see the example of response implicit object where we are redirecting the response to the
Google.

Example of response implicit object


index.html
1. <form action="welcome.jsp">
2. <input type="text" name="uname">
3. <input type="submit" value="go"><br/>
4. </form>
welcome.jsp
1. <%
2. response.sendRedirect("http://www.google.com");
3. %>
Output

JSP - Form Processing **Important


In situations when you need to pass some information from your browser to the web server and
ultimately to your backend program (The server side .jsp file handles it). The browser uses two
methods to pass this information to the web server. These methods are the GET Method and the
POST Method.

GET method
The GET method sends the encoded user information appended to the page request. The page and
the encoded information are separated by the ? character as follows −
http://www.test.com/hello?key1=value1&key2=value2

The GET method is the default method to pass information from the browser to the web server and
it produces a long string that appears in your browser's Location:box. It is recommended that the
GET method is better not used. if you have password or other sensitive information to pass to the
server.
The GET method has size limitation: only 1024 characters can be in a request string.
This information is passed using QUERY_STRING header and will be accessible through
QUERY_STRING environment variable which can be handled using getQueryString() and
getParameter() methods of request object.

POST method
A generally more reliable method of passing information to a backend program is the POST
method.
This method packages the information in exactly the same way as the GET method, but instead of
sending it as a text string after a ? in the URL it sends it as a separate message. This message comes
to the backend program in the form of the standard input which you can parse and use for your
processing.
JSP handles this type of requests using getParameter() method to read simple parameters and
getInputStream() method to read binary data stream coming from the client.

Reading Form Data using JSP


JSP handles form data parsing automatically using the following methods depending on the
situation −
 getParameter() − You call request.getParameter() method to get the value of a form
parameter.
 getParameterValues() − Call this method if the parameter appears more than once and
returns multiple values, for example checkbox.
 getParameterNames() − Call this method if you want a complete list of all parameters in
the current request.
 getInputStream() − Call this method to read binary data stream coming from the client.

GET Method Example Using URL *Important


The following URL will pass two values to HelloForm program using the GET method.
http://localhost:8080/main.jsp?first_name=ZARA&last_name=ALI
Below is the main.jsp JSP program to handle input given by web browser. We are going to use the
getParameter() method which makes it very easy to access the passed information −
<html>
<head>
<title>Using GET Method to Read Form Data</title>
</head>

<body>
<h1>Using GET Method to Read Form Data</h1>
<ul>
<li><p><b>First Name:</b>
<%= request.getParameter("first_name")%>
</p></li>
<li><p><b>Last Name:</b>
<%= request.getParameter("last_name")%>
</p></li>
</ul>

</body>
</html>

Now type http://localhost:8080/main.jsp?first_name=ZARA&last_name=ALI in your browser's


Location:box. This will generate the following result −
Using GET Method to Read Form Data
 First Name: ZARA

 Last Name: ALI

GET Method Example Using Form *Important


Following is an example that passes two values using the HTML FORM and the submit button. We
are going to use the same JSP main.jsp to handle this input.
<html>
<body>

<form action = "main.jsp" method = "GET">


First Name: <input type = "text" name = "first_name">
<br />
Last Name: <input type = "text" name = "last_name" />
<input type = "submit" value = "Submit" />
</form>

</body>
</html>

Keep this HTML in a file Hello.htm and put it in


<Tomcat-installation-directory>/webapps/ROOT directory. When you would access
http://localhost:8080/Hello.htm, you will receive the following output.

First Name:
Last Name:

SUBMIT

< p>Try to enter the First Name and the Last Name and then click the submit button to see the result
on your local machine where tomcat is running. Based on the input provided, it will generate similar
result as mentioned in the above example.

After you fill the fields and press the submit button, the data is sent to “main.jsp” which reads
the data and stores them in variables and displays them as a list as written in “main.jsp”.
What are Web Services? *Important
A web service is a collection of open protocols and standards used for exchanging data
between applications or systems. Software applications written in various programming
languages and running on various platforms can use web services to exchange data over
computer networks like the Internet in a manner similar to inter-process communication on
a single computer. This interoperability (e.g., between Java and Python, or Windows and
Linux applications) is due to the use of open standards.
To summarize, a complete web service is, therefore, any service that −
 Is available over the Internet or private (intranet) networks
 Uses a standardized XML messaging system
 Is not tied to any one operating system or programming language
 Is self-describing via a common XML grammar
 Is discoverable via a simple find mechanism

Components of Web Services


The basic web services platform is XML + HTTP. All the standard web services work using the
following components −
 SOAP (Simple Object Access Protocol)
 UDDI (Universal Description, Discovery and Integration)
 WSDL (Web Services Description Language)

How Does a Web Service Work?


A web service enables communication among various applications by using open standards such as
HTML, XML, WSDL, and SOAP. A web service takes the help of −
 XML to tag the data
 SOAP to transfer a message
 WSDL to describe the availability of service.
You can build a Java-based web service on Solaris that is accessible from your Visual Basic
program that runs on Windows.
You can also use C# to build new web services on Windows that can be invoked from your web
application that is based on JavaServer Pages (JSP) and runs on Linux.
Example
Consider a simple account-management and order processing system. The accounting personnel use
a client application built with Visual Basic or JSP to create new accounts and enter new customer
orders.
The processing logic for this system is written in Java and resides on a Solaris machine, which also
interacts with a database to store information.
The steps to perform this operation are as follows −
 The client program bundles the account registration information into a SOAP message.
 This SOAP message is sent to the web service as the body of an HTTP POST request.
 The web service unpacks the SOAP request and converts it into a command that the
application can understand.
 The application processes the information as required and responds with a new unique
account number for that customer.
 Next, the web service packages the response into another SOAP message, which it sends
back to the client program in response to its HTTP request.
 The client program unpacks the SOAP message to obtain the results of the account
registration process.

SOAP
SOAP is an acronym for Simple Object Access Protocol.
SOAP is a XML-based protocol for accessing web services.
SOAP is a W3C recommendation for communication between applications.
SOAP is XML based, so it is platform independent and language independent. In other words, it can
be used with Java, .Net or PHP language on any platform.

WSDL
WSDL is an acronym for Web Services Description Language.
WSDL is a xml document containing information about web services such as method name, method
parameter and how to access it.
WSDL is a part of UDDI. It acts as a interface between web service applications.
WSDL is pronounced as wiz-dull.

UDDI
UDDI is an acronym for Universal Description, Discovery and Integration.
UDDI is a XML based framework for describing, discovering and integrating web services.
UDDI is a directory of web service interfaces described by WSDL, containing information about
web services.

SOAP Web Services


SOAP stands for Simple Object Access Protocol. It is a XML-based protocol for accessing web
services.
SOAP is a W3C recommendation for communication between two applications.
SOAP is XML based protocol. It is platform independent and language independent. By using
SOAP, you will be able to interact with other programming language applications.

Advantages of Soap Web Services


WS Security: SOAP defines its own security known as WS Security.
Language and Platform independent: SOAP web services can be written in any programming
language and executed in any platform.

Disadvantages of Soap Web Services


Slow: SOAP uses XML format that must be parsed to be read. It defines many standards that must
be followed while developing the SOAP applications. So it is slow and consumes more bandwidth
and resource.
WSDL dependent: SOAP uses WSDL and doesn't have any other mechanism to discover the
service.

RESTful Web Services


REST stands for REpresentational State Transfer.
REST is an architectural style not a protocol.

Advantages of RESTful Web Services


Fast: RESTful Web Services are fast because there is no strict specification like SOAP. It consumes
less bandwidth and resource.
Language and Platform independent: RESTful web services can be written in any programming
language and executed in any platform.
Can use SOAP: RESTful web services can use SOAP web services as the implementation.
Permits different data format: RESTful web service permits different data format such as Plain
Text, HTML, XML and JSON.
SOAP vs REST Web Services
There are many differences between SOAP and REST web services. The important 10 differences
between SOAP and REST are given below:

No. SOAP REST


1) SOAP is a protocol. REST is an architectural style.
SOAP stands for Simple Object
2) REST stands for REpresentational State Transfer.
Access Protocol.
SOAP can't use REST because it REST can use SOAP web services because it is a concept
3)
is a protocol. and can use any protocol like HTTP, SOAP.
SOAP uses services interfaces to
4) REST uses URI to expose business logic.
expose the business logic.
JAX-WS is the java API for SOAP
5) JAX-RS is the java API for RESTful web services.
web services.
SOAP defines standards to be
6) REST does not define too much standards like SOAP.
strictly followed.
SOAP requires more bandwidth
7) REST requires less bandwidth and resource than SOAP.
and resource than REST.
RESTful web services inherits security measures from
8) SOAP defines its own security.
the underlying transport.
SOAP permits XML data format REST permits different data format such as Plain text,
9)
only. HTML, XML, JSON etc.
SOAP is less preferred than
10) REST more preferred than SOAP.
REST.

Service Oriented Architecture (SOA)


A Service-Oriented Architecture or SOA is a design pattern which is designed to build distributed
systems that deliver services to other applications through the protocol. It is only a concept and not
limited to any programming language or platform.

What is Service?
A service is a well-defined, self-contained function that represents a unit of functionality. A service
can exchange information from another service. It is not dependent on the state of another service. It
uses a loosely coupled, message-based communication model to communicate with applications and
other services.

Service Connections
The figure given below illustrates the service-oriented architecture. Service consumer sends a
service request to the service provider, and the service provider sends the service response to the
service consumer. The service connection is understandable to both the service consumer and
service provider.
Service-Oriented Terminologies

• Services - The services are the logical entities defined by one or more published interfaces.
• Service provider - It is a software entity that implements a service specification.
• Service consumer - It can be called as a requestor or client that calls a service provider. A
service consumer can be another service or an end-user application.
• Service locator - It is a service provider that acts as a registry. It is responsible for
examining service provider interfaces and service locations.
• Service broker - It is a service provider that pass service requests to one or more additional
service providers.

Characteristics of SOA
The services have the following characteristics:
• They are loosely coupled.
• They support interoperability.
• They are location-transparent
• They are self-contained.
Components of service-oriented architecture
The service-oriented architecture stack can be categorized into two parts - functional aspects and
quality of service aspects.

Functional aspects
The functional aspect contains:
• Transport - It transports the service requests from the service consumer to the service
provider and service responses from the service provider to the service consumer.
• Service Communication Protocol - It allows the service provider and the service consumer
to communicate with each other.
• Service Description - It describes the service and data required to invoke it.
• Service - It is an actual service.
• Business Process - It represents the group of services called in a particular sequence
associated with the particular rules to meet the business requirements.
• Service Registry - It contains the description of data which is used by service providers to
publish their services.
Quality of Service aspects
The quality of service aspects contains:
• Policy - It represents the set of protocols according to which a service provider make and
provide the services to consumers.
• Security - It represents the set of protocols required for identification and authorization.
• Transaction - It provides the surety of consistent result. This means, if we use the group of
services to complete a business function, either all must complete or none of the complete.
• Management - It defines the set of attributes used to manage the services.

Advantages of SOA
SOA has the following advantages:
• Easy to integrate - In a service-oriented architecture, the integration is a service specification
that provides implementation transparency.
• Manage Complexity - Due to service specification, the complexities get isolated, and
integration becomes more manageable.
• Platform Independence - The services are platform-independent as they can communicate
with other applications through a common language.
• Loose coupling - It facilitates to implement services without impacting other applications or
services.
• Parallel Development - As SOA follows layer-based architecture, it provides parallel
development.
• Available - The SOA services are easily available to any requester.
• Reliable - As services are small in size, it is easier to test and debug them.

You might also like