Sie sind auf Seite 1von 52

Unit-5

Technologies for SOA:


Unit-5: Technologies for SOA
• XML: Namespaces, schemas, processing/passing
models
• SOAP: messages, elements, attributes and processing
model, message exchange types ,HTTP binding
• WSDL: containment structure, elements of abstract
description, elements of the implementation part,
logical relationships, SOAP binding
• UDDI Registry: Basic data model, tmodel,
categorization and identification schemes, binding
template, use of WSDL in the UDDI registry
XML
• XML is probably the most important pillar of Web
Services.
• a means for passing information between the
service provider and service consumer.
• XML also forms the basis for
– WSDL
– SOAP
– UDDI (Universal Description, Discovery, and
Integration), which is used to publish and discover a
Web Service, is also based on XML.
XML
• overview of the XML language.
• concept of namespaces
• Schemas
• various models you can use for parsing,
processing, creating, and editing an XML
document.
XML
• XML uses tags (Similar to HTML).
• HTML tags indicate how the data should be
presented or displayed
• XML tags are used to describe what the data is
• HTML has fixed set of tags
• XML is extensible (new tags can be defined)
XML
■ Open tags Example: <name>
■ Close tags Example: </name>
■ Elements Example: <name>Blue Device</name>
■ Attributes Example: <price currency="US">
<product>
<name>Blue Device</name>
<price currency="US">99.99</price>
</product>
XML cond.
 This figure shows that a basic XML document consists of
a top element. This top element may consist of data (the
payload), an attribute, any number of other elements in
a recursive manner.
 A sample portion of a simple XML document
1 <address country=“USA”>
2 <name>John Smith</name>
3 <street>43 Walcut St</street>
4 <city>Dublin</city>
5 <state>Ohio</state>
6 <postal-code>45561</postal-code>
7 </address>
XML cond.
The XML contains a top element named
address
has a single attribute -- country.
has four child elements
 name of the person, street address, the city, and the
postal code.
Each of these child elements has data
XML cond.
Grammar of an XML document
DTD
XMLSchema
 NameSpace is used to
 avoid the tag name collisions
extend the use of vocabulary defined in one specific domain
to other
Namespaces
XML Namespaces increase reuse across
multiple WSDL documents and across the
enterprise and beyond
An XML namespace comprises a collection of
element type names
attribute names
A namespace is identified by a URI reference.
As an example, consider the three different
namespaces shown in Figure 11.3.
Namespace examples
Namespaces
 The element's name and the address of the namespace
(http://myCompnny.com/hr/employees) refer to the names and
addresses of the employee' of the company (myCompany).
 The identical element type name of the namespace
http://mCompany.com/sales/orders holds the name for the supplier
for myCompany
 myCompany's tennis club management also decides to store their
member data in XML format with the element types of name and
address.
 A namespace is declared through the reserved namespace attribute
xmlns or through an attribute that is prefixed with "xmlns:" and
followed by a name without a colon.
 The namespace attribute can be provided in any element of an XML
document.
Namespaces
 An example of a namespace prefix declaration is shown here:
<address xmlns:myC=“http://myCompany.com/hr/employees”>

 we can use the prefix to qualify any name of the element.

<myC:address xmlns:myC=“http://myCompany.com/hr/employees”>

<myC:name>John Smith</myC:name>
<myC:street>43 Walcut St</myC:street>
<myC:city>Dublin</myC:city>
<myC:state>Ohio</myC:state>
<myC:postal-code>45561</myC:postal-code>
</myC:address>
Namespaces
Namespaces
 another way to declare and use a namespace without a prefix.
 It is called a default namespace. Example
<address xmlns= "http//myCompany.com/hr/employees" >
 All subordinate elements are assumed to belong to the default
namespace, provided they are not prefixed

<address xmlns= “http://myCompany.com/hr/employees” >


<name>John Smith</name>
<street>45 Walcut St</street>
<city>Dublin</city>
<state>Ohio</state>
<postal-code>45565</postal-code>
</address>
XML Schema
 An XML schema defines
the grammar and
structure of XML
instance documents of
a particular type.
 An XML schema is itself
an XML instance.
 The top element of a
schema is named
"schema."
 Its name space is:
http://www.w3.org/2001/XMLSchema
XML Schema
The sub elements of the top element schema are:
 element
 This sub-element declares an element used in an XML
instance. A declaration includes the name and type.
 attribute
This subelement declares an attribute used in an XML
instance. A declaration includes the name and type.
 SimpleType
This subelement defines a simple type. A simple type in an
XMIL schema is a built-in type, a list of simple types, a
union of simple types, or a restriction of a simple type.
XML Schema
Other sub elements of the top element schema are:
 ComplexType
 subelement defines a complex type.
 typically contains XML elements and attributes. The elements and
Attributes appearing or referenced within the type definition are
declared within the type definition.
 include
 This subelement is used to import an element definition defined in
another schema. The other schema must belong to the same XML
namespace.
 import
 This subelement is used to import an element definition defined in
another schema that belongs to a different namespace. Through the
use of include and import, reuse is possible with XML schema
definitions.
XML Schema
The complexType can have any
number of attributes but can have
only one of the following:
 sequence, all, choice, or group.
 Under sequence, we can have
any number of elements, but
these elements must appear in
the specific order.
 In case of all, we can have any
number of elements. All these
elements must appear, but the
order is not important.
 In case of choice, only one of
the allowed elements can
appear in an XML instance.
XML Schema example
Listing 11.5: An example of a complexType .
<xsd:complexType name="nameType">
<xsd:sequence>
<xsd:element name="title" type="xsd: string">
<xsd:element name="firstName" type="xsd:string">
<xsd:element name="middleName" type="xsd:string">
<xsd:element name="lastName" type="xsd:string">
</xsd:sequence>
</xsd:complexType>
XML Schema example
XML confirms to Schema
<?xml version="1.0" encoding="UTF-8"?>
<shiporder orderid="889923"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="shiporder.xsd">

<orderperson>John Smith</orderperson>
<shipto>
<name>Ola Nordmann</name>
<address>Langgt 23</address>
<city>4000 Stavanger</city>
<country>Norway</country>
</shipto>
<item>
<title>Empire Burlesque</title>
<note>Special Edition</note>
<quantity>1</quantity>
<price>10.90</price>
</item>
<item>
<title>Hide your heart</title>
<quantity>1</quantity>
<price>9.90</price>
</item>
</shiporder>
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="shiporder">
<xs:complexType>
<xs:sequence>
<xs:element name="orderperson" type="xs:string"/>
<xs:element name="shipto">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="item" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="note" type="xs:string" minOccurs="0"/>
<xs:element name="quantity" type="xs:positiveInteger"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="orderid" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>

</xs:schema>
XML Processing and Parsing Models
 the service provider and service consumer application
exchange data through XML instance documents.
Five choices for XML processing models:
 SAX The Simple API for XML is an event-driven parsing
/programming model.
 StAX The Streaming API for XML provides a pull, event-
based parsing /programming model.
 DOM The Document Object Model provides an in-memory
tree transversal programming model.
 XML data-binding Provides an in-memory Java content
class-bound programming model.
 XSLT Extensible Stylesheet Language Transformation
provides a template-based programming model.
XML Processing and Parsing Models
 SAX, DOM more common. StAX catching up.
 JAXP APIs (Java APIs for XML Processing) – SAX, DOM, StAX
 JAXB technology - XML data binding
 The processing includes
 Parsing the XML document for processing
 Making changes
 Creating a new XML document
 Deserialization or Unmarshalling Parsing an XML document into an
equivalent data structure
 Serialization or Marshalling writing a data structure to an XML
Document
 DOM supports both Deserialization and Serialization
 SAX supports only Deserialization
SAX Processing Model
Need to implement event handlers to manage
events generated by the parser
A SAX parser generates a transient, flow of events
To process the source document
intercept the relevant type of events generated by
the parser. You can use the information passed as
parameters of the events to help identify the relevant
information
the application logic can be applied to the information
obtained.
Some times need to maintain the context to logically
aggregate information from the flow of events.
SAX Processing Model
There are two ways of applying business logic
when using SAX parsing:
First Approach:
The business logic is invoked as soon as the information is
extracted or after minimal aggregation. This approach is
referred to as stream processing
The document can be processed in one step.
Second Approach:
invokes the business logic after complete parsing and
consolidating the extracted information.
Needs two steps to complete the processing of an XML
document.
SAX Processing Model
 SAX first approach (stream processing) advantage:
 it lets an application immediately start processing the content of the
source document.
 application does not even have to wait for the entire document to be
retrieved.
 Useful when - retrieving document from an earlier processing stage
(pipeline) or from the network
 disadvantages :
 a document may appear to be well and has unexpected errors at the
end
 notices these problems only when it comes across erroneous tokens
or when it cannot resolve an entity reference.
 the input stream from which it is reading the document unexpectedly
closes
 Use stream processing model within the context of a transaction
SAX Processing Model
With the second approach,
parsing the document and applying business logic are
performed in two steps
first ensures that the document and the information
extracted from the document are valid
Once the document data is validated, the application
invokes the business logic
Disadvantages of the SAX model
no facility to modify or produce XML documents.
still possible to generate an XML document by writing
custom serialization handler
SAX Processing Model
 SAX processing model well suited when
 the XML document is very large and needs more memory
Your applications do not make any structural
modifications and no need to generate XML documents.
the document needs only be processed once
 you want to implement stream process very large
documents
extract and process only part of the XML document
 the XML document structure and the order of
information map well to the domain-specific objects
familiar with event-based programming
no need to generate/write XML documents
 SAX processing follows a push model
SAX Processing Model
StAX Processing Model
 StAX (Streaming API for XML) is a new API that is becoming
most common processing model for JAVA applications
 Like SAX, it is based on streaming
 Streaming
 a programming model in which XML infosets (sections of XML
document) are transmitted and parsed serially at application
runtime, often in real time, and often from dynamic sources
 stream-based parsers can start generating output
immediately
 infoset elements can be discarded and garbage collected
immediately after they are used.
 stream processing provides a smaller memory footprint,
reduced processor requirements
StAX Processing Model
Limited to cardboard tube
view of is document
need to know what
processing you want to do
before reading the XML
StAX follows pull streaming
model (a client application
calls methods on an XML
parsing library)
StAX Processing Model
Pull model has several advantages over push model:
 the client controls the application thread (in pull) vs
the parser controls the application thread
 Pull parsing libraries can be much smaller, and the
client code is simpler than with push libraries
 Pull clients can read multiple documents at one time
with a single thread.
 A StAX pull parser can filter XML documents such
that elements unnecessary to the client can be
ignored
 StAX provides marshalling (creating XML docs)
StAX Processing Model
Use the StAX processing model when :
You are dealing with very large documents and
memory usage is an issue
You are familiar with event-based programming
The document must be processed only once
There is need for marshalling and unmarshalling
XML documents
You want high performance
DOM Processing Model
processing the XML input data involves two
steps:
 The DOM parser generates a tree-like data
structure that models the XML source
document. This structure is called a DOM
tree.
 The application searches for the relevant
information in the tree and extracts,
consolidates, and processes it further. Then
the application can create domain-specific
objects from the consolidated data.
 The cycle for searching, extracting, and
processing can be repeated as many times as
is needed because the DOM tree persists in
memory.
DOM Processing Model
Limitations:
 The DOM model designed to be a platform-and language-
independent interface. (does not use the java.util.Collection API )

Advantages:
 it is slightly easier to use than the SAX model.
 allow both marshalling and unmarshalling of the XML document
 XSLT identity transformation can be used to achieve serialization
back to the XML document
 use of XPath with the DOM processing model simplifies many
tasks
 XPath allows to specify path patterns to locate element content,
attribute values, and subtrees, may eliminate tree-transversal code.
 XPath expressions are strings, they can be easily parameterized and
externalized in a configuration file
DOM Processing Model
DOM processing model should be used when
 You want to process or generate XML documents
 You want to process the XML document more than once
 The document is not very large and memory usage is not an
issue
 You want to manipulate an XML document and need fine-
grained control over the document structure that you want to
create or edit
 You want random access to parts of the document. For example,
you want to go back and forth within the document.
 You want to benefit from the flexibility of XPath and apply XPath
expressions on the DOM tree.
 You want to implement data binding but you cannot use JAXB
technology because the document either has no schema or it
conforms to a DTD
XML Data-Binding Processing Model
 allows the processing a XML document without being concerned with XML
representation
 binding compiler is used to generate Java content classes from a source schema

JAXB binds XML namespace to a Java package.


XML Data-Binding Processing Model

JAXB binds XML namespace to a Java package.


XSD schema instance (XML document) can be unmarshaled into
a tree of Java objects
 The Java Objects created are the instances of the Java classes
generated by the binding compiler using the XSD schema.
XML Data-Binding Processing Model
 Application can access the source document using Java Bean—style
getter and setter methods.
 you can create or edit in-memory content tree and then marshal
the tree into an XML document instance.
 validations can be performed to ensure that the document created
satisfies the constraints expressed in the XSD schema.
steps to use JAXB:
 Set up the JAXB context (JAXBContext) with the list of derived
packages that are used to unmarshal the document.
 Unmarshal an XML document into a content tree. Also, perform
validation of the document
 Directly apply the business logic to the content tree or consolidate
information from the content tree and then apply business logic on
the consolidated information
XML Data-Binding Processing Model
This processing model also supports
serialization to XML

Steps to marshal a content tree:


1. Modify the existing content tree/generate new tree, from the application’s business logic
2. Validate content tree against the source schema
3. Marshal the content tree into an XML document
Difficult to use JAXB if there is no schema
Use JAXB when
 You are creating or consuming XML documents
 want to deal with Java Objects and are not
concerned with XML representation
do not need to maintain certain as aspects of an XML
document (comments and entity references)
Process the content tree multiple times
You need random access to parts of the document
Memory usage: JAXB implementation creates a Java
representation of the content of a document is much
more compact than the equivalent DOM tree
You previously used DOM, and an XSD schema is now
available.
XSLT Processing Model
 XSLT is a higher level processing model than the SAX, StAX, DOM, and XML
 XSLT complements to these models, and should be used along with these
other models
 XSLT requires writing of rules and templates that are applied when
specified patterns are encountered in the source document.
 The application of the rules adds new fragments or copies fragments
from the source tree to a result tree (XPATH is used to locate and extract
information from the source document)
 When using XSLT, one typically writes style sheets, which are themselves
XML documents.
 XSLT processing provides the flexibility that comes with scripting.
 The XSLT API available with JAXP provides an abstract for the source and
result of a transformation, allowing the developer not only the ability to
chain transformations but also to interface with other processing models,
such as SAX and DOM.
XSLT Processing Model
XSLT Processing Model
 XSLT should be used when
You want to change the structure or insert, remove, or filter
the content of an XML document.
You need to perform complex transformations. Because
XSLT is a functional declarative model, it is easier to design
complex transformations by coding individual rules or
templates than by hard-coding procedures.
You want the ability to be flexible and allow future changes
in the schemas of documents you are processing.
You need to minimize performance overhead for large
documents that contain a significant amount of data
You potentially have more than one transformation for the
same document—because of the scripting nature of the
style sheets—are better performed using XSLT
transformations
Summary Recommendations

 If you are required to deal with the content and


structure of a document, consider using DOM, StAX
 if you are more concerned with the actual domain-
oriented objects, consider using JAXB. Use JAXB if the
document content has representation in Java that is
directly usable by the application implementing the
service provider or service consumer.
 DOM, when used with XPath, can be very powerful
 DOM can be more flexible if the schema for the
document does not exist or is not well defined.

Das könnte Ihnen auch gefallen