Understanding and Developing Web Services: For DBAs and Database Developers
-
Upload
raastech -
Category
Technology
-
view
46 -
download
3
Transcript of Understanding and Developing Web Services: For DBAs and Database Developers
Raastech, Inc. 2201 Cooperative Way, Suite 600 Herndon, VA 20171 +1-703-884-2223 [email protected]
Understanding and Developing Web Services For DBAs and Database Developers
Wednesday, May 20,2015 8:30 - 9:30 am
Room: Superior and Erie
© Raastech, Inc. 2015 | All rights reserved. Slide 2 of 61 @Raastech
Agenda
1. Introduction
2. Introducing Web Services
3. Accessing a Web Service
4. Anatomy of a WSDL
5. Getting Started: Concepts
6. Live Development Demo
Java Web Service: Top-Down Development
Java Web Service: Bottom-Up Development
BPEL Web Service
7. Recap & Summary
© Raastech, Inc. 2015 | All rights reserved. Slide 3 of 61 @Raastech
© Raastech, Inc. 2015 | All rights reserved. Slide 4 of 61 @Raastech
About Us
Ahmed Aboulnaga @Ahmed_Aboulnaga
18+ years Oracle experience
Author of “Oracle SOA Suite 11g Administrator’s Handbook”
OCE (SOA Foundation Practitioner)
Oracle ACE
.
© Raastech, Inc. 2015 | All rights reserved. Slide 5 of 61 @Raastech
About Raastech
Small systems integrator founded in 2009
Headquartered in the Washington DC area
Specializes in Oracle Fusion Middleware
Oracle Platinum Partner & Reseller
Oracle SOA Specialized
100% of consultants are Oracle certified
100% of consultants present at major Oracle conferences
100% of consultants have published books, whitepapers, or articles
Oracle SOA Specialized – 1 in 1,500 worldwide
Oracle Platinum Partner – 1 in 3,000 worldwide
© Raastech, Inc. 2015 | All rights reserved. Slide 6 of 61 @Raastech
Why This Presentation
Learn to develop a web service from scratch
Lot of PL/SQL developers are intimidated by SOA development
Presentation is specific to SOAP, but concepts are similar for REST
© Raastech, Inc. 2015 | All rights reserved. Slide 7 of 61 @Raastech
© Raastech, Inc. 2015 | All rights reserved. Slide 8 of 61 @Raastech
Custom Drivers
How application access was previously developed
PL/SQL Procedure PL/SQL
Procedure
SQL Developer
Java Application
.NET Application
ODBC driver
JDBC driver
SQL*NET
(internal)
© Raastech, Inc. 2015 | All rights reserved. Slide 9 of 61 @Raastech
Specific Target Implementation
ProC anyone?
Must be aware of the technology of
the target system implementation
and import the necessary libraries
and drivers compatible with that
technology
PL/SQL Application Java
Application
Java Application
.NET Application
.NET JARs
Java API
JDBC drive
© Raastech, Inc. 2015 | All rights reserved. Slide 10 of 61 @Raastech
SOAP over HTTP
Standardization on SOAP over HTTP
Web Service Any
Application
Java Application
.NET Application
SOAP over HTTP
SOAP over HTTP
SOAP over HTTP
© Raastech, Inc. 2015 | All rights reserved. Slide 11 of 61 @Raastech
Agnostic Target Implementation
No need to worry about
implementation technology
of target applications
AWS Java
Application
SalesForce
Intuit SOAP over HTTP
SOAP over HTTP
SOAP over HTTP
© Raastech, Inc. 2015 | All rights reserved. Slide 12 of 61 @Raastech
PL/SQL Samples
CREATE PROCEDURE getWeather (
zipcode IN VARCHAR2,
temperature OUT NUMBER)
IS
BEGIN
temperature := '35';
END;
CREATE PROCEDURE setWeather (
zipcode IN VARCHAR2,
temperature IN NUMBER)
IS
BEGIN
INSERT INTO weather
VALUES (zipcode, temperature);
END;
Request-Response Synchronous
1-way Asynchronous
© Raastech, Inc. 2015 | All rights reserved. Slide 13 of 61 @Raastech
Synchronous vs. Asynchronous
PL/SQL Procedure
PL/SQL Procedure
PL/SQL Procedure
PL/SQL Procedure
© Raastech, Inc. 2015 | All rights reserved. Slide 14 of 61 @Raastech
© Raastech, Inc. 2015 | All rights reserved. Slide 15 of 61 @Raastech
Web Service Clients
Now that business functionality is exposed as web services, these
services need to be consumed somehow.
Since web services are standards based, they can be invoked via the
majority of programming languages or through other services.
© Raastech, Inc. 2015 | All rights reserved. Slide 16 of 61 @Raastech
SoapUI
© Raastech, Inc. 2015 | All rights reserved. Slide 17 of 61 @Raastech
Accessing a WSDL
The web service interface is accessible via an HTTP URL:
http://admin.packt.com:7001/Packt-GetWeather-context-root/WeatherPort?WSDL
The web service implementation may or may not reside on the same
service:
<soap:address location="http://srv.packt.com:8888/Packt-GetWeather-context-
root/WeatherPort"/>
Often impossible to tell what underlying language was used to create
the web service.
© Raastech, Inc. 2015 | All rights reserved. Slide 18 of 61 @Raastech
© Raastech, Inc. 2015 | All rights reserved. Slide 19 of 61 @Raastech
Dissecting a WSDL: Interface <definitions name="Weather">
<types>
<schema>
<element name="zip" type="string"/>
<element name="temp" type="string"/>
</schema>
</types>
<message name="zipReq"><part name="parameters" element="zip"/></message>
<message name="tempResp"><part name="parameters" element="temp"/></message>
<portType name="WeatherPort">
<operation name="getWeather">
<input message="zipReq"/>
<output message="tempResp"/>
</operation>
</portType>
<binding name="WeatherBinding" type="WeatherPort">
<operation name="getWeather">
<input name="zipReq"/>
<output name="tempResp"/>
</operation>
</binding>
<service name="WeatherService">
<port name="WeatherPort" binding="WeatherBinding">
<soap:address location="http://localhost/wc/weather"/>
</port>
</service>
</definitions>
The WSDL is the interface to the
web service. Implementation
details of the web service is unknown.
© Raastech, Inc. 2015 | All rights reserved. Slide 20 of 61 @Raastech
<definitions name="Weather">
<types>
<schema>
<element name="zip" type="string"/>
<element name="temp" type="string"/>
</schema>
</types>
<message name="zipReq"><part name="parameters" element="zip"/></message>
<message name="tempResp"><part name="parameters" element="temp"/></message>
<portType name="WeatherPort">
<operation name="getWeather">
<input message="zipReq"/>
<output message="tempResp"/>
</operation>
</portType>
<binding name="WeatherBinding" type="WeatherPort">
<operation name="getWeather">
<input name="zipReq"/>
<output name="tempResp"/>
</operation>
</binding>
<service name="WeatherService">
<port name="WeatherPort" binding="WeatherBinding">
<soap:address location="http://localhost/wc/weather"/>
</port>
</service>
</definitions>
Dissecting a WSDL: Endpoints
Location is referred to as the “endpoint”. Identifies where the actual code resides.
© Raastech, Inc. 2015 | All rights reserved. Slide 21 of 61 @Raastech
<definitions name="Weather">
<types>
<schema>
<element name="zip" type="string"/>
<element name="temp" type="string"/>
</schema>
</types>
<message name="zipReq"><part name="parameters" element="zip"/></message>
<message name="tempResp"><part name="parameters" element="temp"/></message>
<portType name="WeatherPort">
<operation name="getWeather">
<input message="zipReq"/>
<output message="tempResp"/>
</operation>
</portType>
<binding name="WeatherBinding" type="WeatherPort">
<operation name="getWeather">
<input name="zipReq"/>
<output name="tempResp"/>
</operation>
</binding>
<service name="WeatherService">
<port name="WeatherPort" binding="WeatherBinding">
<soap:address location="http://localhost/wc/weather"/>
</port>
</service>
</definitions>
Dissecting a WSDL: Operations
This web service has a single
operation, with an input and an output (i.e., synchronous).
© Raastech, Inc. 2015 | All rights reserved. Slide 22 of 61 @Raastech
<definitions name="Weather">
<types>
<schema>
<element name="zip" type="string"/>
<element name="temp" type="string"/>
</schema>
</types>
<message name="zipReq"><part name="parameters" element="zip"/></message>
<message name="tempResp"><part name="parameters" element="temp"/></message>
<portType name="WeatherPort">
<operation name="getWeather">
<input message="zipReq"/>
<output message="tempResp"/>
</operation>
</portType>
<binding name="WeatherBinding" type="WeatherPort">
<operation name="getWeather">
<input name="zipReq"/>
<output name="tempResp"/>
</operation>
</binding>
<service name="WeatherService">
<port name="WeatherPort" binding="WeatherBinding">
<soap:address location="http://localhost/wc/weather"/>
</port>
</service>
</definitions>
Dissecting a WSDL: Messages
The type of the message is defined
in the “schema”.
© Raastech, Inc. 2015 | All rights reserved. Slide 23 of 61 @Raastech
Java
B
PEL
Today’s Live Development Demo
getWeather SoapUI
getWeather SoapUI
© Raastech, Inc. 2015 | All rights reserved. Slide 24 of 61 @Raastech
© Raastech, Inc. 2015 | All rights reserved. Slide 25 of 61 @Raastech
w3schools References
http://www.w3schools.com/xml/default.asp
http://www.w3schools.com/schema/default.asp
http://www.w3schools.com/xpath/default.asp
http://www.w3schools.com/xsl/default.asp
http://www.w3schools.com/xquery/default.asp
http://www.w3schools.com/webservices/default.asp
http://www.w3schools.com/webservices/ws_wsdl_intro.asp
http://www.w3schools.com/webservices/ws_soap_intro.asp
http://blog.raastech.com/2009/01/creating-top-down-java-web-service-for.html
http://blog.raastech.com/2009/03/creating-bottom-up-java-web-service-for.html
© Raastech, Inc. 2015 | All rights reserved. Slide 26 of 61 @Raastech
XML stands for “EXtensible Markup Language”.
XML was designed to transport and store data.
XML is designed to be self-descriptive.
XML was originally designed to transport and store data.
XML does not contain any logic.
Introduction to XML
© Raastech, Inc. 2015 | All rights reserved. Slide 27 of 61 @Raastech
XML documents follow a tree structure.
Every XML document must have 1 root element.
The root element is the parent of all other elements.
<Customer>
<Name>John Doe</Name>
<OrderNumber>61237</OrderNumber>
<Items>
<Item quantity="2">Book</Item>
</Items>
</Customer>
XML Structure – Root Element
© Raastech, Inc. 2015 | All rights reserved. Slide 28 of 61 @Raastech
Comments
<Customer>
<!-- this is a comment -->
<Name>John Doe</Name>
<OrderNumber>61237</OrderNumber>
<Items>
<Item quantity="2">Book</Item>
</Items>
</Customer>
XML Structure – Comments
© Raastech, Inc. 2015 | All rights reserved. Slide 29 of 61 @Raastech
XML documents must have open and close tags.
Valid HTML, but invalid XML: <li> XML is easy
XML Structure – Tags
© Raastech, Inc. 2015 | All rights reserved. Slide 30 of 61 @Raastech
Open and close tags must have matching case
Valid HTML, but invalid XML: <Customer>John Doe</customer>
XML Structure – Tags
© Raastech, Inc. 2015 | All rights reserved. Slide 31 of 61 @Raastech
XML elements must be properly nested
Valid HTML, but invalid XML: <b><u>Hello World</b><u>
XML Structure – Tags
© Raastech, Inc. 2015 | All rights reserved. Slide 32 of 61 @Raastech
Entity reference.
< < less than
> > greater than
& & ampersand
' ' apostrophe
" " quotation mark
XML Structure – Entity Reference
© Raastech, Inc. 2015 | All rights reserved. Slide 33 of 61 @Raastech
Unlike HTML, whitespace is preserved in XML.
<Customer>
<Name>John Doe
is a person. His age is 20.</Name>
</Customer>
XML Structure – Whitespace
© Raastech, Inc. 2015 | All rights reserved. Slide 34 of 61 @Raastech
Attributes
<Customer OrderNumber="61237">
<Items>
<Item quantity="2">Book</Item>
<Item quantity="1">Binder</Item>
</Items>
</Customer>
XML Structure – Attributes
© Raastech, Inc. 2015 | All rights reserved. Slide 35 of 61 @Raastech
Should you use elements or attributes when designing
XML documents? <Customer>
<OrderNumber>61237</OrderNumber>
<Items>
<Item quantity="1">Binder</Item>
</Items>
</Customer>
<Customer OrderNumber="61237">
<Items>
<Item quantity="1">Binder</Item>
</Items>
</Customer>
XML Structure – Attributes vs. Elements
© Raastech, Inc. 2015 | All rights reserved. Slide 36 of 61 @Raastech
Namespaces are identifiers
<Customers>
<e:Customer xmlns:e="http://raastech.com/Employees">
<e:Name>John Doe</e:Name>
</e:Customer>
<p:Customer xmlns:p="http://raastech.com/Partners">
<p:Name>Jane Doe</p:Name>
</p:Customer>
<Customers>
XML Structure – Namespaces
© Raastech, Inc. 2015 | All rights reserved. Slide 37 of 61 @Raastech
Default namespace; no need to prefix all child elements.
<Customer xmlns="http://raastech.com/Employees">
<Name>John Doe</Name>
</Customer>
XML Structure – Default Namespace
© Raastech, Inc. 2015 | All rights reserved. Slide 38 of 61 @Raastech
XML Schema defines elements in an XML document.
XML Schema defines attributes in an XML document.
XML Schema defines child elements, and optionally their number and order.
XML Schema defines data types for both elements and attributes.
XML Schema defines default and fixed values for elements and attributes.
Introduction to XML Schema
© Raastech, Inc. 2015 | All rights reserved. Slide 39 of 61 @Raastech
XML Schemas are well-formed XML documents and are
extensible.
They are typically saved as .xsd files.
The root element of every XML Schema is the <schema> element.
The <schema> element may include attributes such as
the XML namespace.
Introduction to XML Schema
© Raastech, Inc. 2015 | All rights reserved. Slide 40 of 61 @Raastech
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="Customer">
<xs:complexType>
<xs:sequence>
<xs:element name="OrderNumber" type="xs:string"/>
<xs:element name="Name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Example of an XML Schema
© Raastech, Inc. 2015 | All rights reserved. Slide 41 of 61 @Raastech
A simple element contains only plain text that can be defined in one of several predefined data types (or custom types).
The predefined data types in XML Schema include:
string
decimal
integer
boolean
date
time
Simple Element
© Raastech, Inc. 2015 | All rights reserved. Slide 42 of 61 @Raastech
String
<someelement>Hello World</someelement>
Decimal
<someelement>12.50</someelement>
Integer
<someelement>12</someelement>
Boolean
<someelement>true</someelement>
Data Types
© Raastech, Inc. 2015 | All rights reserved. Slide 43 of 61 @Raastech
Date
<someelement>2002-09-24Z</someelement>
<someelement>2008-07-24-06:00</someelement>
Time:
<someelement>08:00:00</someelement>
DateTime:
<someelement>2008-07-24T08:00:00</someelement>
Data Types
© Raastech, Inc. 2015 | All rights reserved. Slide 44 of 61 @Raastech
Restrictions are also referred to as facets.
Examples include:
minInclusive
maxInclusive
Enumeration
fractionDigits
Length
maxInclusive
maxExclusive
maxLength
minLength
totalDigits
Restrictions
© Raastech, Inc. 2015 | All rights reserved. Slide 45 of 61 @Raastech
Complex elements are XML elements that contains other
elements or attributes. <xs:element name="Customer">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Item" type="xs:ItemType" minOccurs="1" maxOccurs="5"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="ItemType">
<xs:sequence>
<xs:element name="Item" type="xs:string"/>
<xs:element name="Price" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
Complex Element
© Raastech, Inc. 2015 | All rights reserved. Slide 46 of 61 @Raastech
SOAP stands for “Simple Object Access Protocol”.
It is a communication protocol and allows XML documents to be exchange over HTTP.
As a result, it is platform and technology independent, and ideal for Internet-based communication.
A SOAP message is an XML document that contains the following:
Envelope
Header
Body
Fault
Introduction to SOAP
© Raastech, Inc. 2015 | All rights reserved. Slide 47 of 61 @Raastech
Example:
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope">
<soap:Body>
<m:Customer xmlns:m="http://raastech.com/Customer">
<m:Name>John Doe</m:Name>
</m:Customer>
</soap:Body>
SOAP Message
© Raastech, Inc. 2015 | All rights reserved. Slide 48 of 61 @Raastech
Envelope
Root element of a SOAP message.
xmlns:soap namespace should always have the value of http://www.w3.org/2001/12/soap-envelope.
Header
Optional.
Could include information such as authentication information.
First child element of the Envelope element.
Body
Required.
Contains the content of the SOAP message (i.e., the payload).
SOAP Message
© Raastech, Inc. 2015 | All rights reserved. Slide 49 of 61 @Raastech
WSDL stands for “Web Services Description Language”.
It is an XML document that describes a web service (i.e.,
it is the interface specification for the web service).
It specifies the location of the web service, the
operations it supports, and the message types.
Introduction to WSDL
© Raastech, Inc. 2015 | All rights reserved. Slide 50 of 61 @Raastech
© Raastech, Inc. 2015 | All rights reserved. Slide 51 of 61 @Raastech
Java Web Service Development: Top-Down Approach
A top-down web service begins with a WSDL.
Stubs for the underlying Java classes are created.
Live Development Demo
© Raastech, Inc. 2015 | All rights reserved. Slide 52 of 61 @Raastech
© Raastech, Inc. 2015 | All rights reserved. Slide 53 of 61 @Raastech
Java Web Service Development: Bottom-Up Approach
A bottom-up web service begins with an already existing Java class.
Class and methods are easily exposed as a web service interface.
Live Development Demo
© Raastech, Inc. 2015 | All rights reserved. Slide 54 of 61 @Raastech
© Raastech, Inc. 2015 | All rights reserved. Slide 55 of 61 @Raastech
BPEL Web Service Development
Live Development Demo
© Raastech, Inc. 2015 | All rights reserved. Slide 56 of 61 @Raastech
© Raastech, Inc. 2015 | All rights reserved. Slide 57 of 61 @Raastech
SOAP vs. REST
{
"Customer":
{
"FirstName":"John",
"LastName":"Doe"
}
}
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope">
<soap:Body>
<m:Customer xmlns:m="http://raastech.com/Customer">
<m:FirstName>John</m:FirstName>
<m:LastName>Doe</m:LastName>
</m:Customer>
</soap:Body>
SOAP Message
Strong message type validation
Based on XML standard
Wide usage and adoption
Not size-friendly:
Size of data: 7 bytes
Size of message: 236 bytes
JSON Message
Lightweight and efficient (mobile!)
Growing usage and adoption
Oracle will standardize on REST
Size-friendly:
Size of data: 7 bytes
Size of message: 50 bytes
© Raastech, Inc. 2015 | All rights reserved. Slide 58 of 61 @Raastech
SOAP vs. REST
http://www.ateam-oracle.com/performance-study-rest-vs-soap-for-mobile-applications/
© Raastech, Inc. 2015 | All rights reserved. Slide 59 of 61 @Raastech
Recap
Why has web services become the accepted standard?
Are you more familiar with XML terminology?
What is a popular SOAP client testing tool?
What is SOAP and what are the components of a SOAP message?
Can you understand a WSDL when you look at it now?
What is the difference between top-down and bottom-up web service
development?
What is REST?
© Raastech, Inc. 2015 | All rights reserved. Slide 60 of 61 @Raastech
Contact Information
Ahmed Aboulnaga
Technical Director
@Ahmed_Aboulnaga
© Raastech, Inc. 2015 | All rights reserved. Slide 61 of 61 @Raastech
Q&A