The UDDI Client
Just like the user applet, a UDDI client can be a browser-based application (e.g. JavaScript, Flash, or applet-based client), an independent application (for example, a JFC/AWT-based Java application), or part of the server-side logic. In any of these cases, the client sends an XML message to a UDDI registry, which responds with an XML message. The returned XML messages are UDDI API's. The API I'm working with in this article provides a method called find_business, which searches for a particular business in the registry.
The UDDI client has three tasks:
- Author a UDDI invocation request (step 2).
- Send the authored UDDI invocation request to the UDDI Registry (step 2).
- Process the response from the UDDI Registry to extract meaningful information (step 4).
Tasks (1) and (3) involve simple XML authoring and processing. For task 1, design a Java class that authors XML (the BusinessSpec class in Listing 1). For task 3, another Java class BusinessList (see Listing 2) processes the response from the UDDI registry, from which it extracts information. Task 2 is a transporting task. The usual way of doing this is to let SOAP handle all of the transporting. This will be discussed in more detail later in this article.
I've created two XML structures. Listing 3 is the XML structure that the UDDI client authors and sends to the UDDI registry. Listing 4 is the message that the UDDI registry will sends in response. These two XML structures together form one method of the UDDI API called find_business.
UddiAppletGui (Listing 5) is the test container (discussed earlier) that demonstrates the functionality of the other classes. As soon as the applet is initialized, it draws the GUI and is ready to communicate with the server to find the required business information. It displays some text fields for the end user to enter search criteria.
| |
 |
Figure 1. This is the GUI for the find_business method in the applet-based UDDI client.
|
The client-side implementation of the find_Business method is in the form of a reusable Java class called UDDIClient. The UDDIClient (Listing 6) has a method findBusiness() that handles all the UDDI requirements of find_business process.
To invoke the find_business method of UDDI, you need to specify the search criteria. For this, author an API out of XML, like the one in Listing 3 (all API calls in UDDI are XML structures). The API in Listing 1 contains all the information required to run a search for a business. Each element in Listing 3 contains information entered by the user in the applet's GUI.
When the user fills out the fields of the GUI. and presses the Find Business button, the applet runs the ActionEvent method (look at the actionPerformed() method of the UddiAppletGui class in Listing 5). The ActionEvent method creates an instance of the BusinessSpec class, and invokes various Set methods for those text fields that have values present. The BusinessSpec class creates the find_Business XML structure in Listing 3.
Specifying Business Search Criteria
As mentioned above, the findBusiness method in the UDDIClient class takes in a BusinessSpec object and returns a BusinessList object. The BusinessSpec class represents the XML structure that forms the find_Business method call of UDDI's Inquiry API. The BusinessSpec class authors the find_Business XML structure in Listing 3, which completely specifies the business search criteria. The Set methods in the BusinessSpec class set specific XML tags. The ToString() method in this class returns the string representation of the XML markup. All XML authoring is done through kXML, an open source implementation of Document Object Model (DOM).
Use the DOM (Document Object Model) to create the individual nodes in your required XML structure and assemble them into one XML document. The nodes are of type Document, Element, or Attribute. The following list gives details of each element authored. Match the XML elements of the following list with those of Listing 3.
- The Document node doc is the XML document. It holds all child nodes.
- The Element node findBusiness represents the tag named find_Business in the XML structure. Following the start element is an extract from Listing 3. The wax namespace refers to the UDDI API, as specified by xmlns:wax namespace declaration:
<wax:find_business generic="1.0" xmlns:wax="urn:uddi-org:api"_
maxRows="12">
child nodes
</wax:find_business>
- name represents the name of the business tag:
<name>Waxsys</name>
- discoveryURLs represents the discoveryUrls structure:
<discoveryURLs>
<discoveryURL useType="Business entity">_
http://uddi.microsoft.com/inquire</discoveryURL>
</discoveryURLs>
- identifierBag represents the complete IdentifierBag structure:
<identifierBag>
<keyedReference tModelKey="1254" keyValue="ASf" _
keyName="125-PLO" />
<keyedReference tModelKey="96" keyValue="sdf" _
keyName="124-PLG" />
<keyedReference tModelKey="962" keyValue="sdsd" _
keyName="165-RLA" />
</identifierBag>
- tModelBag represents the TModelBag structure:
<tModelBag>
<tModelKey>969-DRW-857-AWF</tModelKey>
<tModelKey>945-AW-984-AHF</tModelKey>
<tModelKey>987-2XW-123-SEWF</tModelKey>
</tModelBag>
- UDDI's Find Qualifiers: UDDI allows its users to specify search preferences. For example, you can make both case-sensitive and case-insensitive searches. It also allows exact match searches and permits you to look for any one specified key. The FindQualifiers structure in Listing 3 is more complex and has several child elements. I designed an inner utility class called FindQualifiers that provides methods to add qualifier tags and then returns the complete XML Element node.
All these nodes are objects of the class Element that provides two utility methods to create a tag in a required format. The first of these methods is a constructor where you provide the name of the tag to be created. The second method is an addChild() method, through which you add child tags.
The BusinessSpec class contains set methods for each of these fields. Each field will be created and populated by calling its proper set method with the required attributes.
For example, have a look at the following method. This setName method takes a string (nameStr), creates a name element, and adds the nameStr string as a text child inside the name element:
// Write business name.
public void setName(String nameStr){
this.name = doc.createElement(Xml.NO_NAMESPACE, "name");
name.addChild(Xml.TEXT, nameStr);
}// end setName()
At this stage, these tags are individual and not yet part of a document. The toString method of the BusinessSpec class is meant to join them together in the Document class and return the complete XML string.