The WebLogic UDDI Client Proxy


The UDDI client proxy offers convenience classes that facilitate the writing of Java clients which interact with a UDDI registry. Specifically, these proxies obviate the need for your Java client to be aware of the various UDDI API Inquiry and Publish SOAP message formats. They provide an abstraction layer that closely mirrors the UDDI API data structures and interactions. All these classes are packaged in the main WebLogic Server library:

 
 <  wl_home  >\weblogic700\server\lib\weblogic.jar 

The proxy layer is composed of several Java packages that implement the following: UDDI data structures, the Inquiry and Publish calls, classes that simplify invoking the API, and classes that facilitate consumption of API responses.

UDDI Data Structures Implementation: weblogic.uddi.client.structures.datatypes

The Java package weblogic.uddi.client.structures.datatypes implements some of the data structures used by the UDDI API, as documented in the "UDDI Version 2.0 Data Structure Reference" specification. It also implements a few new convenience structures that are not part of the specifications. Some of the main classes in this package that will be used in the following examples are

  • BusinessEntity , BusinessKey , BusinessInfo , BusinessInfosBusinessService , ServiceKey , ServiceInfo , ServiceInfosBindingTemplate , BindingKey , BindingTemplates ” Main structures used in the Inquiry and Publish APIs

  • AuthInfo ” Used to specify the opaque authentication token that is required for the publish API

  • FindQualifier , FindQualifiers ” Used for specifying search parameters when invoking the Inquiry API find_ xxx calls

API Request Data Objects: weblogic.uddi.client.structures.request

The Java Package weblogic.uddi.client.structures.request contains more convenience classes that provide data objects used for invoking the UDDI API. One distinct object needs to be "filled out" and then passed into each API call. For instance, the FindBusiness class needs to be instantiated , configured, and then passed to the inquiry.findBusiness() method. These structures are not part of the UDDI specifications. You will learn more about this in the ensuing examples.

API Response Data Objects: weblogic.uddi.client.structures.response

The Java Package weblogic.uddi.client.structures.response implements classes for each response message structure documented in the UDDI Data Structures specification. For instance, this package provides a BusinessList object that would be returned by the inquiry.findBusiness() call.

The Inquiry Class: weblogic.uddi.client.service.Inquiry

The Java Package weblogic.uddi.client.service.Inquiry class implements the UDDI Inquiry API described in Table 31.1, providing methods to accomplish the Find and Obtain Details functionality. Listing 31.3 shows the main methods in this class, which help tie all these proxy packages together.

Listing 31.3 Methods in the Inquiry Proxy
 import weblogic.uddi.client.structures.response.*; import weblogic.uddi.client.structures.request.*; import weblogic.uddi.client.structures.exception.*; BindingDetail findBinding(FindBinding x) throws UDDIException, XML_SoapException; BusinessList findBusiness(FindBusiness x) throws UDDIException, XML_SoapException; ServiceList findService(FindService x) throws UDDIException, XML_SoapException; TModelList findTModel(FindTModel x) throws UDDIException, XML_SoapException; BindingDetail getBindingDetail(GetBindingDetail x) throws UDDIException, XML_SoapException; BusinessDetail getBusinessDetail(GetBusinessDetail x) throws UDDIException, XML_SoapException; BusinessDetailExt getBusinessDetailExt(GetBusinessDetailExt x) throws UDDIException, XML_SoapException; ServiceDetail getServiceDetail(GetServiceDetail x) throws UDDIException, XML_SoapException; TModelDetail getTModelDetail(GetTModelDetail x) throws UDDIException, XML_SoapException; void setURL(String x); // set URL of target UDDI operator to inquire of String getURL(); 

Note the following "holistic" observations:

  • All the return types shown are in the response package.

  • All first parameter types are in the request package.

  • All method exceptions are in the weblogic.uddi.client.structures.exception package.

  • Compare these signatures to Table 31.1 and note that the response message types shown there correspond to each of the return types in Listing 31.3.

The Publish Class: weblogic.uddi.client.service.Publish

The Java Package weblogic.uddi.client.service.Publish class implements the UDDI Publish API described in Table 31.2, providing methods to accomplish the Create New and Delete functionality. Listing 31.4 shows the main methods in this class, which help tie all these proxy packages together.

Listing 31.4 Methods in the Publish Proxy
 import weblogic.uddi.client.structures.response.*; import weblogic.uddi.client.structures.request.*; import weblogic.uddi.client.structures.exception.*; DispositionReport deleteBinding(DeleteBinding x) throws UDDIException, XML_SoapException; DispositionReport deleteBusiness(DeleteBusiness x) throws UDDIException, XML_SoapException; DispositionReport deleteService(DeleteService x) throws UDDIException, XML_SoapException; DispositionReport deleteTModel(DeleteTModel x) throws UDDIException, XML_SoapException; DispositionReport discardAuthToken(DiscardAuthToken x) throws UDDIException, XML_SoapException; AuthToken getAuthToken(GetAuthToken x) throws UDDIException, XML_SoapException; RegisteredInfo getRegisteredInfo(GetRegisteredInfo x) throws UDDIException, XML_SoapException; BindingDetail saveBinding(SaveBinding x) throws UDDIException, XML_SoapException; BusinessDetail saveBusiness(SaveBusiness x) throws UDDIException, XML_SoapException; ServiceDetail saveService(SaveService x) throws UDDIException, XML_SoapException; TModelDetail saveTModel(SaveTModel x) throws UDDIException, XML_SoapException; DispositionReport validateCategorization(ValidateCategorization x) throws UDDIException, XML_SoapException; void setURL(String x); // set URL of target UDDI operator to publish to String getURL(); 

Sample Client Code ( Tasks )

Now it's time to look at some sample UDDI tasks performed using the WebLogic UDDI client proxies.

Finding a Business

Listing 31.5 shows a business lookup by name , that is, using the "white pages" paradigm. This is only a code snippet; some code statements have been omitted for brevity.

Listing 31.5 Looking Up a Business by Name
 import weblogic.uddi.client.service.Inquiry; import weblogic.uddi.client.structures.datatypes.Name; import weblogic.uddi.client.structures.datatypes.Result; import weblogic.uddi.client.structures.datatypes.ErrInfo; import weblogic.uddi.client.structures.datatypes.BusinessInfo; import weblogic.uddi.client.structures.datatypes.BusinessInfos; import weblogic.uddi.client.structures.datatypes.FindQualifiers; import weblogic.uddi.client.structures.request.FindBusiness; import weblogic.uddi.client.structures.response.BusinessList; import weblogic.uddi.client.structures.response.DispositionReport; import weblogic.uddi.client.structures.exception.UDDIException; import weblogic.uddi.client.structures.exception.XML_SoapException; public void LookupBusiness() { // Init the Inquiry object Inquiry inquire = new Inquiry(); inquire.setURL("http://localhost:7001/uddi/uddilistener"); // uddi operator try { // Prepare to invoke find business method Name name = new Name("PaymentsRUs"); FindQualifiers searchParms = new FindQualifiers(); searchParms.addFindQualifier("exactNameMatch"); searchParms.addFindQualifier("caseSensitiveMatch"); // Obtain & fill out findBusiness data object FindBusiness findBizDO = new FindBusiness(); findBizDO.setFindQualifiers(searchParms); findBizDO.setName(name); // CALL FIND BUSINESS BusinessList bizList = inquire.findBusiness(findBizDO); // Process results BusinessInfos bizInfos = bizList.getBusinessInfos(); if (bizInfos == null) { System.out.println("Could not locate Business: " + name.getValue()); return; } // Assume biz name is unique - only one bizInfo returned Vector bizInfoVector = bizInfos.getBusinessInfoVector(); BusinessInfo bizInfo = (BusinessInfo) bizInfoVector.elementAt(0); // Print out results System.out.println("********* BUSINESS FOUND ********"); System.out.println("Attribute BusinessKey: " + bizInfo.getBusinessKey()); Name bizName = bizInfo.getName(); System.out.println("Name : " + bizName.getValue()); String bizKey = bizInfo.getBusinessKey(); } catch (UDDIException uex) { System.out.println("UDDIEXception: "); System.out.println(uex.getFaultActor()); System.out.println(uex.getFaultCode()); DispositionReport report = uex.getDispositionReport(); Vector results = report.getResultVector(); Result res = (Result) results.elementAt(0); ErrInfo errInfo = res.getErrInfo(); System.out.println("Error Info : " + errInfo.getValue()); } catch (XML_SoapException exc) { System.out.println("XML_SoapException: "); System.out.println(exc.getMessage()); exc.printStackTrace(); } catch (Exception e) { System.out.println("Exception: "); e.printStackTrace(); } } 
Finding a Service

Listing 31.6 shows a method that looks up a service from a known business (a known businessKey ). This is only a code snippet; some statements have been omitted for brevity. The omitted catch statements are the same as those shown in Listing 31.5.

Listing 31.6 Looking for a Service in a Particular Business
 import WebLogic.uddi.client.service.Inquiry; import WebLogic.uddi.client.structures.datatypes.FindQualifiers; import WebLogic.uddi.client.structures.datatypes.BusinessKey; import WebLogic.uddi.client.structures.datatypes.ServiceInfo; import WebLogic.uddi.client.structures.datatypes.ServiceInfos; import WebLogic.uddi.client.structures.request.FindService; import WebLogic.uddi.client.structures.response.ServiceList; import WebLogic.uddi.client.structures.exception.*; public void LookupServiceInBusiness(String bizKeyString) { // Init the Inquiry object Inquiry inquire = new Inquiry(); inquire.setURL("http://localhost:7001/uddi/uddilistener"); // uddi operator try { BusinessKey bizKey = new BusinessKey(bizKeyString); Name name = new Name("Authorize Payment"); FindQualifiers searchParms = new FindQualifiers(); searchParms.addFindQualifier("sortByNameDesc"); searchParms.addFindQualifier("caseSensitiveMatch"); // Obtain & fill out findService data object FindService findServiceDO = new FindService(); findServiceDO.setBusinessKey(bizKey.getValue()); findServiceDO.setFindQualifiers(searchParms); findServiceDO.setName(name); ServiceList serviceList = inquire.findService(findServiceDO); ServiceInfos serviceInfos = serviceList.getServiceInfos(); if (serviceInfos == null) { System.out.println("Could not locate service: " + name.getValue()); return; } // Assume service name is unique - only 1 service found Vector serviceInfoVector = serviceInfos.getServiceInfoVector(); ServiceInfo serviceInfo = (ServiceInfo) serviceInfoVector.elementAt(0); // Print results System.out.println("********* SERVICE FOUND ********"); System.out.println("Registered Service Name: " + serviceInfo.getName().getValue()); System.out.println("Service Key: " + serviceInfo.getServiceKey()); } catch (UDDIException ue) { ... } } 
Creating a New Business

The example in Listing 31.7 uses the Publish API to save a new business into the registry. Recall that authentication is required for publishing into the UDDI registry; therefore, you need to obtain an opaque authentication token by invoking the getAuthToken call.

Listing 31.7 Publishing a New Business into UDDI
 import weblogic.uddi.client.service.Publish; import weblogic.uddi.client.structures.request.GetAuthToken; import weblogic.uddi.client.structures.request.SaveBusiness; import weblogic.uddi.client.structures.request.DiscardAuthToken; import weblogic.uddi.client.structures.response.AuthToken; import weblogic.uddi.client.structures.response.BusinessDetail; import weblogic.uddi.client.structures.datatypes.BusinessEntity; import weblogic.uddi.client.structures.exception.*; public void createNewBusiness() { // Init the Publish object Publish publish = new Publish(); publish.setURL("http://localhost:7001/uddi/uddilistener"); // uddi operator try { // Obtain auth info, using user +pw for WLS Examples Server GetAuthToken getAuthTokenDO = new GetAuthToken(); getAuthTokenDO.setUserID("WebLogic"); getAuthTokenDO.setCred("WebLogic"); AuthToken authToken = publish.getAuthToken(getAuthTokenDO); AuthInfo authInfo = authToken.getAuthInfo(); // Obtain & fill out biz entity object BusinessEntity bizEntity = new BusinessEntity(); bizEntity.setBusinessKey(""); bizEntity.setName("PaymentsRUs"); bizEntity.addDescription("Payment Processing Center"); Vector bizEntityVector = new Vector(); bizEntityVector.add(bizEntity); // Obtain & fill out Save Business data object SaveBusiness saveBizDO = new SaveBusiness(); saveBizDO.setAuthInfo(authInfo); saveBizDO.setBusinessEntityVector(bizEntityVector); // CALL SAVE BUSINESS BusinessDetail bizDetails = publish.saveBusiness(saveBizDO); // Print results bizEntity = (BusinessEntity) bizDetails.getBusinessEntityVector().elementAt(0); System.out.println("********* BUSINESS SAVED *********"); System.out.println("BusinessName = " + bizEntity.getName().getValue() + "\nKey = " + bizEntity.getBusinessKey()); // Don't forget to log off! DiscardAuthToken discardAuthTokenDO = new DiscardAuthToken(); discardAuthTokenDO.setAuthInfo(authInfo); publish.discardAuthToken(discardAuthTokenDO); } catch (UDDIException ue) {  ...  } } 

This example shows only how to create a new business. Typically, you would next invoke a save service belonging to this new business and then a save binding for completeness.



BEA WebLogic Platform 7
BEA WebLogic Platform 7
ISBN: 0789727129
EAN: 2147483647
Year: 2003
Pages: 360

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net