2.1. Overview of Web Service Standards

Standards differ from technologies. Standards are a collection of specifications, rules, and guidelines formulated and accepted by the leading market participants. While these rules and guidelines prescribe a common way to achieve the standard's stated goal, they do not prescribe implementation details. Individual participants devise their own implementations of an accepted standard according to the standard's guidelines and rules. These various implementations of a standard by different vendors give rise to a variety of technologies. However, despite the implementation detail differences, the technologies can work together if they have been developed according to the standard's specifications.

For Web services to be successful, the Web service standards must be widely accepted. To enable such wide acceptance, the standards used for Web services and the technologies that implement those standards should meet the following criteria:

  • A Web service should be able to service requests from any client regardless of the platform on which the client is implemented.

  • A client should be able to find and use any Web service regardless of the service's implementation details or the platform on which it runs.

Standards establish a base of commonality and enable Web services to achieve wide acceptance and interoperability. Standards cover areas such as:

  • Common markup language for communication— To begin with, service providers, who make services available, and service requestors, who use services, must be able to communicate with each other. Communication mandates the use of a common terminology, or language, through which providers and requestors talk to one another. A common markup language facilitates communication between providers and requestors, as each party is able to read and understand the exchanged information based on the embedded markup tags. Although providers and requestors can communicate using interpreters or translators, using interpreters or translators is impractical because such intermediary agents are inefficient and not cost effective. Web services use eXtensible Markup Language (XML) for the common markup language.

  • Common message format for exchanging information— Although establishing a common markup language is important, by itself it is not sufficient for two parties (specifically, the service providers and service requestors) to properly communicate. For effective communication, the parties must be able to exchange messages according to an agreed-upon format. By having such a format, parties who are unknown to each other can communicate effectively. Simple Object Access Protocol (SOAP) provides a common message format for Web services.

  • Common service specification formats— In addition to common message formats and markup language, there must be a common format that all service providers can use to specify service details, such as the service type, how to access the service, and so forth. A standard mechanism for specifying service details enables providers to specify their services so that any requestor can understand and use them. For example, Web Services Description Language (WSDL) provides Web services with common specification formats.

  • Common means for service lookup— In the same way that providers need a common way to specify service details, service requestors must have a common way to look up and obtain details of a service. This is accomplished by having common, well-known locations where providers can register their service specifications and where requestors know to go to find services. By having these common, well-known locations and a standard way to access them, services can be universally accessed by all providers and requestors. Universal Description, Discovery, and Integration (UDDI) specification defines a common means for looking up Web services.

Although they do not exhaustively discuss these basic standards, the next sections provide enough information about the standards to enable further discussion about the J2EE technologies that implement them. For complete details, see the reference section at the end of this chapter. In addition to these basic standards, more complex Web services that implement enterprise-level processes need standards for security, transactions, process flow control, and so forth.

2.1.1. Extensible Markup Language

The eXtensible Markup Language (XML), a standard accepted throughout the industry, enables service providers and requestors to communicate with each other in a common language. XML is not dependent on a proprietary platform or technology, and messages in XML can be communicated over the Internet using standard Internet protocols such as HTTP. Because XML is a product of the World Wide Web Consortium (W3C) body, changes to it will be supported by all leading players. This ensures that as XML evolves, Web services can also evolve without backward compatibility concerns.

XML is a simple, flexible, text-based markup language. XML data is marked using tags enclosed in angled brackets. The tags contain the meaning of the data they mark. Such markup allows different systems to easily exchange data with each other. This differs from tag usage in HTML, which is oriented to displaying data. Unlike HTML, display is not inherent in XML. Code Example 2.1 shows the code from an XML document representing an individual's contact information.

Code example 2.1. XML Document Example
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<ContactInformation>
    <Name>John Doe</Name>
    <Address>
        <Street>4140 Network Circle</Street>
        <City>Santa Clara</City>
        <State>California</State>
        <Country>USA</Country>
    </Address>
    <HomePhone>123-456-7890</HomePhone>
    <EMail>[email protected]</EMail>
</ContactInformation>

A Document Type Definition (DTD) or XML Schema Definition (XSD) describes the structure of an XML document. It has information on the tags the corresponding XML document can have, the order of those tags, and so forth. An XML document can be validated against its DTD or its XSD. Validating an XML document ensures that the document follows the structure defined in its DTD or XSD and that it has no invalid XML tags. Thus, systems exchanging XML documents for some purpose can agree on a single DTD or XSD and validate all XML documents received for that purpose against the agreed-upon DTD/XSD before processing the document. Code Example 2.2 is the DTD for the XML document in Code Example 2.1.

Code example 2.2. Document Type Definition
<!ELEMENT ContactInformation (Name, Address, HomePhone, EMail)>
<!ELEMENT Name (#PCDATA)>
<!ELEMENT Address (Street, City, State, Country)>
<!ELEMENT Street (#PCDATA)>
<!ELEMENT City (#PCDATA)>
<!ELEMENT State (#PCDATA)>
<!ELEMENT Country (#PCDATA)>
<!ELEMENT HomePhone (#PCDATA)>
<!ELEMENT EMail (#PCDATA)>

Unfortunately, DTDs are an inadequate way to define XML document formats. For example, DTDs provide no real facility to express data types or complex structural relationships. XML schema definitions standardize the format definitions of XML documents. Code Example 2.4 shows the XSD schema for the sample XML document in Code Example 2.3.

Code example 2.3. XML Document
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<ContactInformation
       xmlns="http://simple.example.com/CInfoXmlDoc"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation=
          "http://simple.example.com/CInfoXmlDoc
						file:./CInfoXmlDoc.xsd">
    <Name>John doe</Name>
    <Address>
        <Street>4140 Network Circle</Street>
        <City>Santa Clara</City>
        <State>California</State>
        <Country>USA</Country>
    </Address>
    <HomePhone>123-456-7890</HomePhone>
     <EMail>[email protected]</EMail>
</ContactInformation>

Code example 2.4. XSD Schema
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   targetNamespace="http://simple.example.com/CInfoXmlDoc"
   xmlns=" http://simple.example.com/CInfoXmlDoc"
   elementFormDefault="qualified">
   <xsd:element name="ContactInformation">
      <xsd:complexType>
         <xsd:sequence>
             <xsd:element name="Name" type="xsd:string" />
             <xsd:element name="Address">
                <xsd:complexType>
                    <xsd:sequence>
                       <xsd:element name="Street"
                                 type="xsd:string" />
                       <xsd:element name="City"
                                 type="xsd:string" />
                       <xsd:element name="State"
                                 type="xsd:string" />
                       <xsd:element name="Country"
                                 type="xsd:string" />
                     </xsd:sequence>
                 </xsd:complexType>
              </xsd:element>
              <xsd:element name="HomePhone" type="xsd:string" />
              <xsd:element name="EMail" type="xsd:string" />
          </xsd:sequence>
       </xsd:complexType>
   </xsd:element>
</xsd:schema>

When considering XML schemas, it is important to understand the concept of XML namespaces. To enable using the same name with different meanings in different contexts, XML schemas may define a namespace. A namespace is a set of unique names that are defined for a particular context and that conform to rules specific for the namespace. Since a namespace is specific to a particular context, each namespace is unrelated to any other namespace. Thus, the same name can be used in different namespaces without causing a duplicate name conflict. XML documents, which conform to an XML schema and have multiple elements and attributes, often rely on namespaces to avoid a collision in tag or attribute names or to be able to use the same tag or attribute name in different contexts.

Technically speaking, an XML namespace defines a collection of names and is identified by a URI reference. (Notice in Code Example 2.4 the code xmlns="http://simple.example.com/CInfoXmlDoc". Code such as this indicates that the XML schema defines a namespace for the various elements and attributes in the document.) Names in the namespace can be used as element types or attributes in an XML document. The combination of URI and element type or attribute name comprises a unique universal name that avoids collisions.

For example, in Code Example 2.4, there is a namespace that defines the ContactInformation document's element types, such as Name and Address. These element types are unique within the contact information context. If the document included another namespace context, such as BankInformation that defined its own Name and Address element types, these two namespaces would be separate and distinct. That is, a Name and Address used in the context of BankInformation would not conflict with a name and address used in the context of ContactInformation.

2.1.2. Simple Object Access Protocol

XML solves the need for a common language, and the Simple Object Access Protocol (SOAP) fills the need for a common messaging format. SOAP enables objects not known to one another to communicate; that is, to exchange messages. SOAP, a wire protocol similar to Internet Inter-ORB Protocol (IIOP) and Java Remote Method Protocol (JRMP), is a text-based protocol that uses an XML-based data encoding format and HTTP/SMTP to transport messages. SOAP is independent of both the programming language and the operational platform, and it does not require any specific technology at its endpoints, making it completely agnostic to vendors, platforms, and technologies. Its text format also makes SOAP a firewall-friendly protocol. Moreover, SOAP is backed by leading industrial players and can be expected to have universal support.

To enable message exchanges, SOAP defines an envelope, which contains a SOAP body, within which the message is included, and an optional SOAP-specific header. The whole envelope—body plus header—is one complete XML document. (See Figure 2.1.)

Figure 2.1. SOAP Message Structure


The header entries may contain information of use to recipients, and these header entries may also be of use to intermediate processors since they enable advanced features. The body, which contains the message contents, is consumed by the recipient. SOAP is agnostic about the message contents; the only restriction is that the message be in XML format.

Code Example 2.5 shows a simple but complete example of a SOAP request for obtaining a stock quote.

Code example 2.5. Example SOAP Request
<SOAP-ENV:Envelope xmlns:SOAP-ENV="SoapEnvelopeURI"
       SOAP-ENV:encodingStyle="SoapEncodingURI">
    <SOAP-ENV:Header>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <m:GetLastTradePrice xmlns:m="ServiceURI">
            <tickerSymbol>SUNW</tickerSymbol>
        </m:GetLastTradePrice>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

This example shows how a SOAP message is encoded using XML and illustrates some SOAP elements and attributes. All SOAP messages must have an Envelope element and must define two namespaces: One namespace connotes the SOAP envelope (xmlns:SOAP-ENV) and the other indicates the SOAP encoding (SOAP-ENV:encodingStyle). SOAP messages without proper namespace specification are considered invalid messages. The encodingStyle attribute is important, as it is used to specify serialization rules for the SOAP message. Moreover, there can be no DTD referrals from within SOAP messages.

While optional, the Header element when used should be the first immediate child after the Envelope. The Header element provides a way to extend the SOAP message by specifying additional information such as authentication and transactions. Specifying this additional information as part of the Header tells the message recipient how to handle the message.

There are many attributes that can be used in the SOAP Header element. For example, the actor attribute of the Header element enables a SOAP message to be passed through intermediate processes enroute to its ultimate destination. When the actor attribute is absent, the recipient is the final destination of the SOAP message. Similarly, many other attributes may be used. However, this chapter does not address these details.

The Body element, which must be present in all SOAP messages, must follow immediately after the Header element, if it is present. Otherwise, the Body element must follow immediately after the start of the Envelope element. The Body contains the specification of the actual request (such as method calls). The Fault element in the SOAP Body enables error handling for message requests.

Note that this chapter does not discuss details of Header elements, attributes, and other additional features, such as SOAP with attachments and binding HTTP, although they are part of the SOAP standard. Interested readers should refer to the SOAP specifications.

2.1.3. Registry Standards

The Universal Description, Discovery, and Integration (UDDI) specification defines a standard way for registering, deregistering, and looking up Web services. UDDI is a standards-based specification for Web service registration, description, and discovery. Similar to a telephone system's yellow pages, a UDDI registry's sole purpose is to enable providers to register their services and requestors to find services. Once a requestor finds a service, the registry has no more role to play between the requestor and the provider.

Figure 2.2 shows how UDDI enables dynamic description, discovery, and integration of Web services. A Web service provider registers its services with the UDDI registry. A Web service requestor looks up required services in the UDDI registry and, when it finds a service, the requestor binds directly with the provider to use the service.

Figure 2.2. Role of a Registry in a Web Service


The UDDI specification defines an XML schema for SOAP messages and APIs for applications wanting to use the registry. A provider registering a Web service with UDDI must furnish business, service, binding, and technical information about the service. This information is stored in a common format that consists of three parts:

  1. White pages— describe general business information such as name, description, phone numbers, and so forth

  2. Yellow pages— describe the business in terms of standard taxonomies. This information should follow standard industrial categorizations so that services can be located by industry, category, or geographical location.

  3. Green pages— list the service, binding, and service-specific technical information

The UDDI specification includes two categories of APIs for accessing UDDI services from applications:

  1. Inquiry APIs— enable lookup and browsing of registry information

  2. Publishers APIs— allow applications to register services with the registry

UDDI APIs behave in a synchronous manner. In addition, to ensure that a Web service provider or requestor can use the registry, UDDI uses SOAP as the base protocol. Note that UDDI is a specification for a registry, not a repository. As a registry it functions like a catalog, allowing requestors to find available services. A registry is not a repository because it does not contain the services itself.

2.1.4. Web Services Description Language

The Web Services Description Language (WSDL) defines a standard way for specifying the details of a Web service. It is a general-purpose XML schema that can be used to specify details of Web service interfaces, bindings, and other deployment details. By having such a standard way to specify details of a service, clients who have no prior knowledge of the service can still use that Web service.

WSDL specifies a grammar that describes Web services as a collection of communication endpoints, called ports. The data being exchanged are specified as part of messages. Every type of action allowed at an endpoint is considered an operation. Collections of operations possible on an endpoint are grouped together into port types. The messages, operations, and port types are all abstract definitions, which means the definitions do not carry deployment-specific details to enable their reuse.

The protocol and data format specifications for a particular port type are specified as a binding. A port is defined by associating a network address with a reusable binding, and a collection of ports define a service. In addition, WSDL specifies a common binding mechanism to bring together all protocol and data formats with an abstract message, operation, or endpoint. See Figure 2.3.

Figure 2.3. WSDL Service Description


Code Example 2.6 shows a WSDL document for a weather Web service that returns a given city's weather information. The Web service, which uses SOAP as the communication protocol, expects to receive the city name as String type data and sends String type data as its response.

Code example 2.6. WSDL Document for Weather Web Service
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="WeatherWebService"
         targetNamespace="urn:WeatherWebService"
         xmlns:tns="urn:WeatherWebService"
         xmlns="http://schemas.xmlsoap.org/wsdl/"
         xmlns:xsd="http://www.w3.org/2001/XMLSchema"
         xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
   <types/>
   <message name="WeatherService_getWeather">
      <part name="String_1" type="xsd:string"/>
   </message>
   <message name="WeatherService_getWeatherResponse">
      <part name="result" type="xsd:string"/>
   </message>
   <portType name="WeatherService">
      <operation name="getWeather" parameterOrder="String_1">
         <input message="tns:WeatherService_getWeather"/>
         <output
            message="tns:WeatherService_getWeatherResponse"/>
      </operation>
   </portType>
   <binding name="WeatherServiceBinding"
                            type="tns:WeatherService">
      <operation name="getWeather">
         <input>
            <soap:body use="literal"
               namespace="urn:WeatherWebService"/>
         </input>
         <output>
            <soap:body use="literal"
               namespace="urn:WeatherWebService"/>
         </output>
         <soap:operation soapAction=""/></operation>
      <soap:binding
             transport="http://schemas.xmlsoap.org/soap/http"
             style="rpc"/>
   </binding>
   <service name="WeatherWebService">
      <port name="WeatherServicePort"
                        binding="tns:WeatherServiceBinding">
         <soap:address
            location="http://mycompany.com/weatherservice"/>
      </port>
   </service>
</definitions>

A complete WSDL document consists of a set of definitions starting with a root definitions element followed by six individual element definitions—types, message, portType, binding, port, and service—that describe the services.

  • The types element defines the data types contained in messages exchanged as part of the service. Data types can be simple, complex, derived, or array types. Types, either schema definitions or references, that are referred to in a WSDL document's message element are defined in the WSDL document's type element.

  • The message element defines the messages that the Web service exchanges. A WSDL document has a message element for each message that is exchanged, and the message element contains the data types associated with the message.

  • The portType element specifies, in an abstract manner, operations and messages that are part of the Web service. A WSDL document has one or more portType definitions for each Web service it defines.

  • The binding element binds the abstract port type, and its messages and operations, to a transport protocol and to message formats.

  • The service and port elements together define the name of the Web service and, by providing a single address for binding, assign an individual endpoint for the service. A port can have only one address. The service element groups related ports together and, through its name attribute, provides a logical name for the service.

This description is for a simple WSDL document. Each element definition has various attributes and WSDL has additional features, such as fault handling. WSDL also specifies how to bind directly with HTTP/MIME, SMTP/MIME, and so forth, but these are beyond the scope of the current discussion. For more details, see the WSDL specification available at http://www.w3c.org/TR/wsdl.

2.1.5. Emerging Standards

So far we have examined existing standards, which meet the needs of simple Web services. Organizations that cross various industries have been formed to create and promote cross-platform standards. The Web Services Interoperability Organization (WS-I) is one such group. WS-I has published a WS-I Basic Profile that defines a set of cross-platform standards, such as those just examined, to promote and ensure interoperability. But other standards are required to address issues for Web services that handle complex business processes. These issues include strict security requirements, business processes interacting with other business processes and having long-lived transactions or transactions that span multiple business processes, or business processes nested within other processes. These business processes must also execute properly even when run on different platforms. Various standards bodies and organizations such as WS-I are currently working on these standards. Since these standards are still being defined and it is not yet clear which standards will be accepted as universal, we do not go into the details of emerging standards.

Now that we have examined the Web service standards, let's go on to see how J2EE supports these accepted standards.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset