Universal Description, Discovery, and Integration (UDDI) is fast becoming a standard for storing business processes available on the Web. Although UDDI is capable of storing many different types of data, for the purposes of this tip, I’ll focus on how UDDI can be used to register Web services, thereby making them available for application-level consumption.
- You are using IBM® WebSphere® Studio Application Developer V5.0 (Application Developer) or another J2EE compliant development environment, such as the Eclipse IDE.
- DB2® has been installed, and the sample database has been created (this sample uses the Employee and Department tables. To create the sample database, open DB2 First Steps and click on the "Create Sample Database" link).
- UDDI registry is installed and properly configured. Please see the InstallUDDI listing for an automated setup of a UDDI registry to use the Cloudscape database. Execute installuddilibs.bat from a command window to create the necessary directory structure.
This tip provides Java developers with a fast and simple way to develop their own UDDI Java applications to consume Web services registered within a UDDI registry. The sample code included contains a Payroll Web service (deployed from an entity bean) and a UDDI session bean.
This tip is based heavily on the tutorial "Discover Web services with the WSDK V5.1: UDDI" (developerWorks, November 2003), which is cited in the Resources section. My intention is to present an extension to the basic Universal Description, Discovery, and Integration for Java (UDDI4J) classes in order to help you quickly stand up your own UDDI registry of Web services. While working through the "Discover Web services with the WSDK V5.1: UDDI" tutorial, I developed an extension API that provides a higher-level approach to the UDDI4J API. This tip extends only a small subset of the UDDI4J functionality, since its purpose is to register, discover, and consume a Web service stored within a UDDI registry. For a more broad discussion of UDDI and its uses beyond storing Web services, please see "Understanding UDDI" (developerWorks, July 2002), by Tom Bellwood.
The Payroll.ear file included contains an Enterprise JavaBeans (EJB) project named PayrollEjbPrj. Within this EJB project are two entity beans: Department and Employee, and one session bean, Payroll. The Department and Employee entity beans expose getter and setter methods for the sample database. The Payroll bean, which exposes 12 methods, uses the getter methods of the entity beans to query various pieces of information from the sample database. The sample code might easily be extended to provide setter functionality from within the Payroll bean. Exposing all of the sample database fields is beyond the scope of this tip.
The UDDIClient session bean makes almost exclusive use of the UDDI utility API discussed in the next section.
A UDDI registry might contain Businesses, Services, and TModels. The UDDIClient bean provides a publish() and two delete() methods for each type of UDDI entry. As shown in Listing 1 below, method signature methods are as simple as possible, while shifting the work to the UDDI Utility API.
Listing 1. Method signatures
public String publishBusiness(String busName)
{
return BusinessUtilities.publishBusiness(busName);
}
public void deleteBusinessByName(String busName)
{
BusinessUtilities.deleteBusinessByName(busName);
}
public void deleteBusinessByKey(String busKey)
{
BusinessUtilities.deleteBusinessByKey(busKey);
}
public String publishService(String serviceName, String busName,
String tModelName, String tModelOverviewDoc,
String accessPointStr, String description)
{
return
ServiceUtilities.publishService(serviceName,busName,tModelName,
tModelOverviewDoc,accessPointStr,description);
}
public void deleteServiceByName(String serviceName)
{
ServiceUtilities.deleteServiceByName(serviceName);
}
public void deleteServiceByKey(String serviceKey)
{
ServiceUtilities.deleteServiceByKey(serviceKey);
}
public String publishTModel(String tModelName, String overviewDocString)
{
return
ModelUtilities.publishTModel(tModelName,overviewDocString);
}
public void deleteTModelByName(String tModelName)
{
ModelUtilities.deleteTModelByName(tModelName);
}
public void deleteTModelByKey(String tModelKey)
{
ModelUtilities.deleteTModelByKey(tModelKey);
}
|
Methods getService and executeService
The getService and executeService methods of the UDDIClient bean demonstrate how to retrieve our Payroll Web service and invoke some of its methods. The executeService method takes a string representing the name of a service stored in the registry. In the sample code, the service registered is the Payroll Web service. For the purposes of this tip, I’ve hard coded two methods that are called from the Payroll Web service found within the registry, as shown in Listing 2.
Listing 2. Methods getService and executeService
/**
* Execute a Service found in the UDDI registry
* @param serviceName Service name used to search for
and execute available UDDI Services
*/
public void executeService(String serviceName)
{
//Obtain all access points for services providing this
service
Map accessPoints =
ServiceUtilities.getServiceAccessPoints(serviceName);
//Create a set of accespoints
Set accessSet = accessPoints.keySet();
Iterator it = accessSet.iterator();
Payroll payroll = null;
Object obj = null;
while(it.hasNext())
{
try
{
//For each access point, create an
PayrollService object
String accessPoint = (String)it.next();
System.out.println("Service Access Point: " +
accessPoint);
payroll = getService(accessPoint);
if(payroll != null)
{
System.out.println("Employee 000010's
bonus is " + payroll.getBonus("000010"));
System.out.println("Employee 000010's
phone number is " + payroll.getPhoneNo("000010"));
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
/**
* Create a Service object, to communicate with the
Web service defined by the URL
* @param urlString the URL of the Web service
* @return A PayrollService object.
*/
private Payroll getService(String urlString)
{
PayrollServiceLocator payrollServiceLocator =
new PayrollServiceLocator();
Payroll payroll = null;
try
{
URL url = new URL(urlString);
System.out.println("Payroll URL: " + url.toString());
System.out.println("Getting Payroll object");
payroll =
payrollServiceLocator.getPayroll(url);
System.out.println("Payroll object retrieved
successfully");
}
catch (MalformedURLException e)
{
System.out.println("URL Exception: " + e.toString());
}
catch(javax.xml.rpc.ServiceException se)
{
System.out.println("Service Exception: " +
se.toString());
}
return payroll;
}
|
The UDDI Utility API has four main classes, three of which I will cover in detail in Listings 3, 4, and 5. The fourth, Utilities.class, contains all of the setup information for the UDDI registry. The values and structure are explained in detail in the "Publishing your services on UDDI with the WSDK V5.1" (developerWorks, November 2003) tutorial.
Listing 3. BusinessUtilities
/** * Display business information of a BusinessEntity * @param businessKey The businessKey of the BusinessEntity whose detail is to be displayed */ public static void showBusinessDetail(String businessKey) /** * Locate a Business by name * @param busName The business name used to search for a business * @return Vector: This method returns a Vector of Strings. Each String represents the businessKey of a business matching the query */ public static Vector findBusinessByName(String busName) /** * Locate a Business by key * @param businessKey The business key used to search for a business * @return BusinessList: This function returns a BusinessList on success. In the event that no matches were located for the specified criteria, a BusinessList structure with zero BusinessInfo structures is returned. */ public static BusinessList findBusinessByKey(String businessKey) /** * Delete a Business by name * @param busName Business name used to find and delete a business */ public static void deleteBusinessByName(String busName) /** * Delete a Business by key * @param businessKey A Business key used to find and delete a business */ public static void deleteBusinessByKey(String businessKey) /** * Publish a Business * @param busName The name of the business to be published * @return String: This method returns a String representing the key of the newly published Business */ public static String publishBusiness(String busName) |
Listing 4. ModelUtilities
/** * Locate a technical Model by name * @param tModelName the Name * @return Vector: This method returns a Vector of tModelKey Strings */ public static Vector findTModelByName(String tModelName) /** * Locate a technical Model by key * @param tModelName The TModel key used to search for a TModel * @return TModelList: This method returns a TModelList of TModelInfos objects */ public static TModelList findTModelByKey(String tModelKey) /** * Delete a technical Model by name * @param tModelKey TModel name used to delete a TModel */ public static void deleteTModelByName(String tModelName) /** * Delete a technical Model by key * @param tModelKey TModel key used to delete a TModel */ public static void deleteTModelByKey(String tModelKey) /** * Publish a technical Model * @param tModelName The TModel name * @param overviewDocString This parameter expects a URL-String representation of the WSDL address. EX: http://localhost:9080/MyRouter/Test.wsdl * @return String: This method returns a String representing the key of the newly published TModel */ public static String publishTModel(String tModelName, String overviewDocString) |
Listing 5. ServiceUtilities
/** * Locate a Service by name * @param serviceNames A vector of Name objects * @return Map: This method returns a Map of service and business key pairs */ public static Map findServiceByName(Vector serviceNames) /** * Locate a Service by key * @param serviceKey A key used to search for a Service * @return ServiceList: This method returns a ServiceList of ServiceInfos objects */ public static ServiceList findServiceByKey(String serviceKey) /** * Delete a Service by name * @param serviceName Service name used to find and delete a Service */ public static void deleteServiceByName(String serviceName) /** * Delete a Service by key * @param serviceKey Service key used to find and delete a Service */ public static void deleteServiceByKey(String serviceKey) /** * Publish a Service * @param serviceName The name of the Service to be published * @param businessName The Business name used to associate the service to. If Business name does not exist in the registry, a Business entry will be created. * @param tModelName The TModel that the service implements. If TModel is not found in the registry and the TModelOverviewDoc parameter is not null, a TModel entry will be created. * @param tModelOverviewDoc Required only if the TModel name provided in the tModelName parameter is not found in the registry. This parameter expects a URL-String representation of the WSDL address. EX: http://localhost:9080/MyRouter/Test.wsdl * @param accessPointStr * @param description Optional Service description. * @return String: This method returns a String representing the key of the newly published Service */ public static String publishService(String serviceName, String busName, String tModelName, String tModelOverviewDoc, String accessPointStr, String description) |
As you have seen, UDDI programming can be a very powerful way to share information on the Web using the UDDI registry. This sample code, and more specifically, the UDDI Utility API are provided as a starting point from which you can develop a more customized solution.
| Name | Size | Download method |
|---|---|---|
| ws-uddiproxy.zip | HTTP |
Information about download methods
- Download the sample code packages contained in this article: UDDI Utilities API javadoc, UDDI Utilities API source, and UDDI Proxy.zip.
- Read the W3C Simple Object Access Protocol (SOAP) 1.1 specification.
- The UDDI specification can be accessed on the uddi.org Web site.
- Read the Web Services Description Language (WSDL) 1.1, the specification of WSDL.
- Get more details on Eclipse at the eclipse.org site.
- For more information on UDDI V2, read "Understanding UDDI: Tracking the evolving specification" article (developerWorks, May 2002).
- Take a look at UDDI4J, which provides full support of Version 2 of the UDDI specification.
- Visit the UDDI organization site.
- The Web Services Description Language for Java (WSDL4J) open source project is available on IBM developerWorks.
- Find additional SOA and Web services technology resources on the developerWorks SOA and Web services technology zone.
- Find a number of Web services programming tips from developerWorks.
- Browse for books on these and other technical topics.
Andrew J. Bradfield is an Advisory Software Engineer working in the IBM Software Division located at the IBM T.J. Watson Research Center in Hawthorne, New York. Andrew graduated with a degree in Computer Science from Hamilton College in Clinton, New York. His projects include J2EE development of Content Management and Data Management Solutions. He can be contacted at abrad@us.ibm.com.
Comments (Undergoing maintenance)





