Java Web Services Programming Tips and tricks: developing UDDI Java applications for Web service registrations at the UDDI registry

Source: Internet
Author: User
Tags db2 wsdl



This technique establishes a WEB service instance that uses unified description, Discovery, and integration (Universal Description, Discovery, and Integration,uddi) to register application-level consumption. The author provides detailed code examples and an extension API for Java-based unified description, Discovery, and integration (Universal Description, Discovery,and integration for java,uddi4j) APIs that enable you to Use UDDI for your own development.



0 Reviews:



Andrew J. Bradfield ([email protected]), Author, EMC



August 01, 2004


    • Content
Introduction


Unified description, Discovery, and Integration (UDDI) is rapidly becoming the standard for storing available business processes on the WEB. While UDDI can store a large number of different types of data, for this tip, I will focus on how to use UDDI to register Web services so that Web services can be consumed at the application level.



Back to top of page


Assume
    • You are using Ibm®websphere®studio application Developer V5.0 (application Developer) or other Java EE-compatible development environments, such as the Eclipse IDE.
    • Db2® has been installed and a sample database has been created (this example uses the Employee table and the Department table.) To create a sample database, open DB2 first Steps, and then click the Create Sample link).
    • The UDDI Registry has been installed and configured correctly. See the Installuddi Checklist for automating the installation of the UDDI registry to use the Cloudscape database. Execute installuddilibs.bat from the command window to create the required directory structure.


Back to top of page


What this technique covers


This technique provides a quick and easy way for Java® developers to develop their own UDDI Java applications and use them to consume WEB services registered in the registry. The accompanying sample code contains a Payroll WEB service (deployed from an entity bean) and a UDDI session bean.



Back to top of page


Technical background


This tip is based primarily on the tutorial, "using WSDK V5.1 to discover Web services: UDDI" (developerWorks, November 2003), which is referenced in the Resources section. My goal is to provide an extension of the basic Java Unified Description, Discovery, and Integration (UDDI4J) class to help you quickly build your own Web Services UDDI registry. In the course of completing the Discover Web services with the WSDK V5.1:uddi tutorial, I developed an extension API that provides a more advanced Access uddi4j API. Because the purpose of this technique is to register, discover, and consume Web services stored in a UDDI registry, only a small portion of the UDDI4J functionality is expanded. For a broader discussion of UDDI and its applications on storage Web services, see Tom Bellwood's article, "Understanding UDDI" (developerWorks, July 2002).



Back to top of page


Payroll Web Services


The accompanying Payroll.ear file contains an enterprise JavaBean (EJB) scenario named PAYROLLEJBPRJ. In this EJB scenario there are two entity beans (Department and Employee) and a session bean (Payroll). The two entity beans, Department and Employee, show getter and setter methods for the sample database. The Payroll Bean shows 12 methods that use the Getter method of the entity bean to query various pieces of information from the sample database. The sample code is easily extended to provide setter functions from within the Payroll bean. Displaying all of the sample database fields is not within the scope of this technique.



Back to top of page


Uddiclient Session EJB


The uddiclient session Bean is almost entirely composed of the UDDI utility API discussed in the next section.



A UDDI registry can include business, services, and TModel. The Uddiclient Bean provides a publish () method and two Delete () methods for each type of UDDI entry. As shown in Listing 1 below, the method signature method is as simple as possible when the task is handed over to the UDDI utility API for processing.


Listing 1. Method signatures

public String publishBusiness (String busName)
{
return BusinessUtilities.publishBusiness (busName);
}
The
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);
}
The
public void deleteTModelByName (String tModelName)
{
ModelUtilities.deleteTModelByName (tModelName);
}
public void deleteTModelByKey (String tModelKey)
{
ModelUtilities.deleteTModelByKey (tModelKey);
}
getService and executeService methods
The getService and executeService methods of the UDDIClient bean demonstrate how to retrieve our Payroll Web service and call some of these methods. The executeService method uses a string to represent the name of a service stored in the registry. In the sample code, the registered service is Payroll Web service. To achieve the desired effect of this technique, I hard-coded two methods for the Payroll Web service created in the registry to call, as shown in Listing 2.

Listing 2. getService and executeService methods
/ **
* 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);
The
// Create a set of accespoints
Set accessSet = accessPoints.keySet ();
Iterator it = accessSet.iterator ();
The
Payroll payroll = null;
Object obj = null;
The
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);
The
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;
The
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 ());
}
The
return payroll;
}
 
Back to top

UDDI Utility API
There are four main classes of UDDI utility API, and I will describe three of them in detail in Listings 3, 4 and 5. The fourth (Utilities.class) contains all the setting information of UDDI registration. "Using WSDK V5.1 to publish services to the UDDI registry" (developerWorks, November 2003) This tutorial explains the values and structure in detail.

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)
 
Back to top

Conclusion
As you can see, UDDI programming is a very effective way to share information on the network using the UDDI registry. The sample code here, and more specifically, the UDDI utility API provides a starting point from which you can develop more customized solutions.

 

http://www.ibm.com/developerworks/cn/webservices/ws-tip-uddijava.html


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.