posts - 495,comments - 227,trackbacks - 0

查找和使用信息

现在已经有了所有信息(至少从理论上是这样),Gene 需要再次对查找的过程进行处理。

UDDI 搜索的工作方式:查找公司

在 UDDI 中进行搜索将涉及到两个步骤。首先,查找所需对象的键,然后获取有关该对象的信息。因此,为了查找公司,Gene 需要创建 find_business 请求,如清单 16 中所示。


清单 16. 按类别查找公司
                    
<find_business generic="2.0" xmlns="urn:uddi-org:api_v2" >
   <categoryBag>
      <keyedReference
 tModelKey="C0B9FE13-179F-413D-8A5B-5004DB8E5BB2" 
           keyName="optional" keyValue="511110" />
   </categoryBag>
</find_business>

此请求将查找所有与 categoryBag 中引用的类别匹配的公司。对 categoryBag 值的搜索被作为“AND”搜索对待。也就是说,任何匹配的项至少属于一个要匹配的类别。您还可以通过这样的方式指定 identifierBag 搜索。不过,Gene 并非真的对按类别搜索感兴趣。他只是暂时希望知道公司的信息是否位于注册中心中,因此,他完全可以采用按名称搜索的方式,如清单 17 中所示。


清单 17. 按名称查找公司
                    
<find_business generic="2.0" xmlns="urn:uddi-org:api_v2" >
   <name>daily</name>
</find_business>

请注意,名称搜索将以像所查找的名称后面跟有通配符一样的方式处理。也就是说,此处的搜索与 "daily*" 搜索一样,因此 Daily MoonDaily Star 以及其他以“daily”开头的公司都将被列出。这些搜索还不区分大小写。





回页首


搜索的结果

find_business 请求将返回一个 businessList。请参见清单 18


清单 18. 搜索返回的公司
                    
<businessList generic="2.0" operator="uddi.sourceOperator" 
    truncated="true" xmlns="urn:uddi-org:api_v2">

   <businessInfos>

      <businessInfo 
            businessKey="1A3DB880-D5F4-11DA-B880-F94D3591C691" >
          <name>The Daily Moon</name>
          <serviceInfos>
             <serviceInfo serviceKey=
                     "064B4170-D5F5-11DA-8170-A74C17FA61A7">
                <name>ClassifiedService</name>
             </serviceInfo>
          </serviceInfos>
      </businessInfo>

      <businessInfo>
         ...
      </businessInfo>

   </businessInfos>

</businessList>

对于满足搜索条件的每个 businessEntitybusinessList 都包含一个对应的 businessInfo 元素。其中的每个 serviceInfo 元素都包含实际的 businessEntitybusinessKey。其中还包含将在 businessEntity 中列出的信息的缩略版,以便您确定其是否是您所要查找的公司。

获得了相应的 businessKey 后,需要获得有关 businessEntity 的更多信息。





回页首


获得了键后的后续操作

要基于 businessKey 获得有关特定 businessEntity 的更多信息,需要执行 get_businessDetail 请求。请参见清单 19


清单 19. 获取公司信息
                    
<get_businessDetail generic="2.0" xmlns="urn:uddi-org:api_v2" >
 <businessKey>1A3DB880-D5F4-11DA-B880-F94D3591C691
</businessKey>
</get_businessDetail>

可以在 get_businessDetail 请求中列出任意多的 businessKey。而后者在结果中均有自己对应的 businessDetail 元素。请参见清单 20


清单 20. 返回的公司详细信息
                    
<businessDetail generic="2.0" operator="uddi.sourceOperator" 
    truncated="false" xmlns="urn:uddi-org:api_v2">

   <businessEntity
 businessKey="1A3DB880-D5F4-11DA-B880-F94D3591C691">
      <name>The Daily Moon</name>
      <name lang="fr-ca">La Lune Quotidienne</name>
      <contacts>
...
         <keyedReference 
              tModelKey="C0B9FE13-179F-413D-8A5B-5004DB8E5BB2" 
              keyName="optional" keyValue="511110" />
      </categoryBag>
   </businessEntity> 

</businessDetail>

每个 businessDetail 元素均包含所涉及公司的完整 businessEntity





回页首


更改搜索工作方式

虽然这可以正常工作,但有时候会希望更改搜索的行为。例如,或许您希望查找精确匹配,而不是通配符匹配,或者可能希望进行区分大小写的搜索。您可以使用 findQualifiers 来更改搜索的行为。请参见清单 21


清单 21. 使用 findQualifiers
                    
<find_business generic="2.0" xmlns="urn:uddi-org:api_v2" >
   <findQualifiers>
      <findQualifier>sortByNameAsc</findQualifier>
   <findQualifiers>
   <name>daily</name>
</find_business>

在这种情况下,搜索将会按通常的方式进行,但返回的结果将按照名称进行排序。可以添加任意多的 findQualifier 元素。其中可用的有 exactNameMatchcaseSensitiveMatch, sortByNameDesc, sortByDateAscsortByDateDesc,或者 LikeKeys(告知注册中心,如果 categoryBagidentifierBag 中的键共享相同的 tModelKey,则将其作为“OR”条件对待),以及 combineCategoryBags(无论实际属于 businessEntitybusinessServicebindingTemplate,都将 businessEntity 的所有 categoryBags 作为属于 businessService 的对象处理)。





回页首


查找某种类型的服务

Gene 还希望确保用户可以基于特定的接口查找任何服务。例如,以下查询将查找使用 ClassifiedService 接口构建的 bindingTemplates。请参见清单 22


清单 22. 查找 bindingTemplate
                    
<find_binding generic="2.0" xmlns="urn:uddi-org:api_v2" >
   <tModelBag>
     
 <tModelKey>66999A50-D5F4-11DA-9A50-FA44D6AD622A</tModelKey>
   </tModelBag>
</find_binding>

此查询将返回一个 serviceList。请参见清单 23


清单 23. 返回的服务
                    
<serviceList generic="2.0" operator="uddi.sourceOperator"    
                  xmlns="urn:uddi-org:api_v2">
   <serviceInfos>
      <serviceInfo 
            serviceKey="064B4170-D5F5-11DA-8170-A74C17FA61A7" 
            businessKey="1A3DB880-D5F4-11DA-B880-F94D3591C691">
          <name>ClassifiedService</name>
      </serviceInfo>
   </serviceInfos>
</serviceList>

find_business 的情况(必须随后再次进行相关操作,请求有关 businessEntity 的信息)一样,将随后基于 serviceKey 具体地请求有关服务器的信息。请参见清单 24


清单 24. 获得服务详细信息
                    
<get_serviceDetail generic="2.0" xmlns="urn:uddi-org:api_v2" >
   <serviceKey>064B4170-D5F5-11DA-8170-A74C17FA61A7
</serviceKey>
</get_serviceDetail>

此查询将为每个指定的 serviceKey 返回一个 serviceDetail。请参见清单 25


清单 25. 返回的服务详细信息
                    
<serviceDetail generic="2.0" operator="uddi.sourceOperator" 
    xmlns="urn:uddi-org:api_v2">
   <businessService 
          serviceKey="064B4170-D5F5-11DA-8170-A74C17FA61A7"
          businessKey="1A3DB880-D5F4-11DA-B880-F94D3591C691">
      <name>ClassifiedService</name>
      <bindingTemplates>
         <bindingTemplate 
             bindingKey="904BD800-D53A-11DA-B055-850A1DA99D79">
            <accessPoint>
      http://www.daily-moon.com:8080/axis2/services/ClassifiedService
            </accessPoint>
...
         <keyedReference 
              tModelKey="C0B9FE13-179F-413D-8A5B-5004DB8E5BB2" 
              keyName="ntis-gov:naics:1997" keyValue="511110" />
      </categoryBag>
   </businessService>
   <businessService>
...
   </businessService>
</serviceDetail>

Gene 现在已经明确了自己要进行的工作,可以开始进行编码了。





回页首

以编程方式使用 UDDI

Gene 最后的工作是建立一组概念验证应用程序,以说明其他团队可以如何基于 UDDI 注册中心构建应用程序。

设置

使用 UDDI 注册中心的第一步是注册软件本身,但 Gene 惊喜地发现,由于使用 Apache Geronimo 作为其 Web 应用服务器,该步骤已经完成;Geronimo 随机安装了 Apache jUDDI。

这个工作已经完成,Gene 接下来必须决定将实际如何访问注册中心了。此处,他有两个选择。第一个选择是使用基于 UDDI 的 API(如 jUDDI 或 UDDI4J 中包含的 API)直接访问。第二个选择是使用 Java API for XML Registries (JAXR) 实现。JAXR 旨在用于访问任何注册中心,其主要目标是提供 UDDI 和 ebXML 支持、

Gene 决定直接从源代码着手,并下载 UDDI4J。而 UDDI4J 依赖于随 Apache Axis 分发的一些库,因此他也将其下载了。(请注意,尽管本项目的前面部分使用了 Axis2,但 UDDI4J 依赖于随 Axis 1 分发的库。)

安装过程相当简单,仅需要确保所有必要的 UDDI4J 和 Axis *.jar 文件位于 CLASSPATH 上即可。请参见清单 26


清单 26. 设置 CLASSPATH
                    
 CLASSPATH=.;<UDDI4J_HOME>\lib\uddi4j.jar;<AXIS_HOME>\lib\axis.jar;
<AXIS_HOME>\lib\saaj.jar;<AXIS_HOME>\lib\jaxrpc.jar;<AXIS_HOME>\lib\
log4j-1.2.8.jar;<AXIS_HOME>\lib\commons-logging-1.0.4.jar;
<AXIS_HOME>\lib\commons-discovery-0.2.jar;

最后,Gene 需要一个用户名和密码,以连接到注册中心。就这方面而言,每个注册中心都彼此不同,因此我们不打算详细讨论细节。Apache Geronimo 中的 UDDI 缺省安装使用的用户名和密码均为 "juddi"





回页首


连接到注册中心

任何应用程序中的第一步都是连接到注册中心。请参见清单 27


清单 27. 连接到注册中心
                    
import org.uddi4j.client.UDDIProxy;
import org.uddi4j.response.AuthToken;
import org.uddi4j.transport.TransportFactory;

public class CreateNewBusiness {

   public static void main (String args[]){
      String inquiryURL = "http://localhost:8080/juddi/inquiry";
      String publishURL = "http://localhost:8080/juddi/publish";
      String userId = "juddi";
      String credential = "juddi";

      String transportClass = 
             "org.uddi4j.transport.ApacheAxisTransport";
      System.setProperty(TransportFactory.PROPERTY_NAME, 
                         transportClass);

      UDDIProxy proxy = new UDDIProxy();

      try {

         proxy.setInquiryURL(inquiryURL);
         proxy.setPublishURL(publishURL);

         AuthToken token = proxy.get_authToken(userId, credential);
         System.out.println("Security authToken:" + 
                                token.getAuthInfoString());

      } catch(Exception e ) {
         e.printStackTrace();         
      }
   }
}

从代码的起始处开始,Gene 设置了将在整个应用程序中使用的各个值。具体来说,Gene 设置了 TransportFactory 的类名称。UDDI4J 可以使用任意数量的相关类,如在此处看到的随 Apache Axis 提供的类、随旧 Apache SOAP 包提供的类或任何类似的类。

最后,他设置了注册中心的 inquiryURLpublishURL 值(通常二者将不同,这其中的部分原因是因为发布通常是使用 SSL 完成的)及请求和授权标记。

此标记很重要,因为每个请求都用其来指示自己已经过服务器的身份验证。由于每个注册中心的处理方式不同,因此随每个请求发送用户名和密码并不实际(也不安全)。

Gene 运行应用程序时,看到了以下的结果:
Security authToken:authToken:505A7DE0-D897-11DA-A5BF-ADFF17B378CF





回页首


创建业务实体

接下来 Gene 要创建业务实体。请参见清单 28


清单 28. 创建 businessEntity
                    
import org.uddi4j.client.UDDIProxy;
import org.uddi4j.response.AuthToken;
import org.uddi4j.transport.TransportFactory;

import org.uddi4j.datatype.business.BusinessEntity;
import org.uddi4j.response.BusinessDetail;
import org.uddi4j.datatype.business.Contact;
import org.uddi4j.datatype.business.Contacts;
import org.uddi4j.util.KeyedReference;
import org.uddi4j.util.IdentifierBag;
import org.uddi4j.util.CategoryBag;
import org.uddi4j.datatype.tmodel.TModel;
import java.util.Vector;

public class CreateNewBusiness {

   public static void main (String args[]){
      String inquiryURL = "http://localhost:8080/juddi/inquiry";
      String publishURL = "http://localhost:8080/juddi/publish";
      String userId = "juddi";
      String credential = "juddi";

      String businessName = "The Daily Moon";
      String alt_businessName = "Daily Moon";
      String contact_personName = "Pat Moonie";
      String contact_phone = "212-555-1212";
      String identifier_homepage = "http://www.daily-moon.com";
      String category_NAICS = "511110";

      String transportClass = 
               "org.uddi4j.transport.ApacheAxisTransport";
      System.setProperty(TransportFactory.PROPERTY_NAME, 
                         transportClass);

      UDDIProxy proxy = new UDDIProxy();

      try {

         proxy.setInquiryURL(inquiryURL);
         proxy.setPublishURL(publishURL);

         AuthToken token = proxy.get_authToken(userId, credential);
         System.out.println("Security authToken:" + 
                                token.getAuthInfoString());

         Vector entities = new Vector();

         BusinessEntity newBusiness = 
                        new BusinessEntity("", businessName);

         Contact newContact = new Contact(contact_personName);
         Vector contactsVector = new Vector();
         contactsVector.addElement(newContact);
         Contacts contacts = new Contacts(); 
         contacts.setContactVector(contactsVector);
         newBusiness.setContacts(contacts);
   
         KeyedReference taxid = 
               new KeyedReference(TModel.HOMEPAGE_TMODEL_KEY,    
                                  identifier_homepage);
         IdentifierBag idBag = new IdentifierBag();
         idBag.add(taxid);
         newBusiness.setIdentifierBag(idBag);

         KeyedReference category = 
               new KeyedReference(TModel.NAICS_TMODEL_KEY, 
                                  category_NAICS);
         CategoryBag catBag = new CategoryBag();
         catBag.add(category);

         entities.addElement(newBusiness);

         BusinessDetail bd = 
                     proxy.save_business(token.getAuthInfoString(), 
                                         entities);

         Vector businessEntities = bd.getBusinessEntityVector();
         BusinessEntity returnedBusinessEntity = 
                       (BusinessEntity)(businessEntities.elementAt(0));

         System.out.println("The new businessKey:" 
                  + returnedBusinessEntity.getBusinessKey());

      } catch(Exception e ) {
         e.printStackTrace();         
      }
   }
}

创建 businessEntity 的过程所涉及的主要步骤是按照其在 XML 中的形式构建各个元素,而将“复数”(如 "contacts""tModelInfos" 等)作为矢量处理。

在本例中,Gene 构建了 contact 矢量、identifierBagcategoryBag,并将其添加到 BusinessEntity 对象中。对象本身会被添加到矢量中,此矢量中包含 save_business() 方法和授权标记。

所得到的结果是一个 BusinessDetail 对象,其中包含一个或多个 BusinessEntity 对象,与数据库中的情况一样。在本例中,Gene 在没有为 businessKey 指定值的情况下提交了 BusinessEntity,从而让注册中心知道要创建一个新对象和一个相应的新键。通过从矢量中检索第一个 BusinessEntity,Gene 可以随后获得新 businessKey

运行应用程序时,他获得了清单 29 中所示的结果:


清单 29. 获得新 businessKey
                    
Security authToken:authToken:1D05DB90-D899-11DA-A5BF-D3513DE466CA
The new businessKey:1D359E20-D899-11DA-A5BF-F9EAF6D4E3F7





回页首


创建服务接口 tModel

有了相关的业务信息后,Gene 接下来开始添加服务接口。请参见清单 30


清单 30. 创建 tModel
                    
import org.uddi4j.client.UDDIProxy;
import org.uddi4j.response.AuthToken;
import org.uddi4j.transport.TransportFactory;
import java.util.Vector;

import org.uddi4j.datatype.tmodel.TModel;
import org.uddi4j.response.TModelDetail;
import org.uddi4j.datatype.OverviewURL;
import org.uddi4j.datatype.OverviewDoc;
import org.uddi4j.util.CategoryBag;
import org.uddi4j.util.KeyedReference;

public class CreateNewInterface{

   public static void main (String args[]){
      String inquiryURL = "http://localhost:8080/juddi/inquiry";
      String publishURL = "http://localhost:8080/juddi/publish";
      String userId = "juddi";
      String credential = "juddi";

      String transportClass = 
            "org.uddi4j.transport.ApacheAxisTransport";
      System.setProperty(TransportFactory.PROPERTY_NAME, 
            transportClass);

      UDDIProxy proxy = new UDDIProxy();

      try {

         proxy.setInquiryURL(inquiryURL);
         proxy.setPublishURL(publishURL);

         AuthToken token = proxy.get_authToken(userId, credential);
         System.out.println("Security authToken:" + 
                                   token.getAuthInfoString());

         Vector tModels = new Vector();
         TModel tModel = new TModel("", 
             "http://www.daily-moon.com/classifieds-interface");

         tModel.setDefaultDescriptionString(
               "Interface for the Daily Moon Classified "+
               "Department web application");

         OverviewDoc overviewDoc = new OverviewDoc();
         overviewDoc.setDefaultDescriptionString(
                                   "WSDL interface document");
         OverviewURL overviewURL = new OverviewURL( 
"http://www.nicholaschase.com/ClassifiedsService-interface.wsdl");
         overviewDoc.setOverviewURL(overviewURL);
         tModel.setOverviewDoc(overviewDoc);

         KeyedReference wsdlNotation = 
            new KeyedReference(TModel.TYPES_TMODEL_KEY, 
                               "wsdlSpec", 
                 "C1ACF26D-9672-4404-9D70-39B756E62AB4");
         KeyedReference typeNotation = 
            new KeyedReference("ntis-gov:naics:1997", 
                               "511110", 
                 "C0B9FE13-179F-413D-8A5B-5004DB8E5BB2");
         CategoryBag catBag = new CategoryBag();
         catBag.add(wsdlNotation);
         catBag.add(typeNotation);
         tModel.setCategoryBag(catBag);

         tModels.add(tModel);

         TModelDetail tModelDetail =              
            proxy.save_tModel(token.getAuthInfoString(), tModels);

         Vector tModelVector = tModelDetail.getTModelVector();
         TModel tModelReturned = (TModel)(tModelVector.elementAt(0));
         System.out.println("TModel Saved: " + 
                                tModelReturned.getNameString());
         System.out.println("TModel Key  : " + 
                                tModelReturned.getTModelKey());

      } catch(Exception e ) {
         e.printStackTrace();         
      }
   }
}

和前面一样,Gene 着手使用 Java 代码建模 XML 元素。他首先创建 TModel,同样没有提供键,以指示他正在创建新项目,并设置其描述。他然后创建 OverviewDoc,并完成描述和 OverviewURL。接下来,他为 CategoryBag 创建 KeyedReferences。请注意,他引用的是特定的 tModels,因此为每个项提供了 tModelKey;此值是可选的。最后,他保存 TModel(一旦再次从返回的值检索到该对象)。

运行了应用程序后,Gene 得到了清单 31 中所示的结果:


清单 31. 获得新 tModelkey
                    
Security authToken:authToken:3312DF20-D8A1-11DA-A5BF-D754085751C9
TModel Saved: http://www.daily-moon.com/classifieds-interface
TModel Key  : uuid:332F67D0-D8A1-11DA-A5BF-DF15F533BFA1





回页首


创建服务

创建服务本身的任务遵循相同的基本过程。请参见清单 32


清单 32. 创建服务
                    
import org.uddi4j.client.UDDIProxy;
import org.uddi4j.response.AuthToken;
import org.uddi4j.transport.TransportFactory;
import java.util.Vector;

import org.uddi4j.datatype.business.BusinessEntity;
import org.uddi4j.datatype.service.BusinessService;
import org.uddi4j.datatype.binding.BindingTemplate;
import org.uddi4j.datatype.binding.BindingTemplates;
import org.uddi4j.util.CategoryBag;
import org.uddi4j.util.KeyedReference;
import org.uddi4j.datatype.binding.AccessPoint;
import org.uddi4j.datatype.binding.TModelInstanceDetails;
import org.uddi4j.datatype.binding.TModelInstanceInfo;
import org.uddi4j.datatype.binding.InstanceDetails;
import org.uddi4j.datatype.OverviewDoc;
import org.uddi4j.datatype.OverviewURL;
import org.uddi4j.datatype.tmodel.TModel;
import org.uddi4j.response.ServiceDetail;

public class CreateNewService{

   public static void main (String args[]){
      String inquiryURL = "http://localhost:8080/juddi/inquiry";
      String publishURL = "http://localhost:8080/juddi/publish";
      String userId = "juddi";
      String credential = "juddi";
      String businessKey =
 "1D359E20-D899-11DA-A5BF-F9EAF6D4E3F7";

      String transportClass = 
           "org.uddi4j.transport.ApacheAxisTransport";
      System.setProperty(TransportFactory.PROPERTY_NAME, 
                         transportClass);

      UDDIProxy proxy = new UDDIProxy();

      try {

         proxy.setInquiryURL(inquiryURL);
         proxy.setPublishURL(publishURL);

         AuthToken token = proxy.get_authToken(userId, credential);
         System.out.println("Security authToken:" + 
                                   token.getAuthInfoString());

         BusinessService businessService = new BusinessService("");
         businessService.setDefaultNameString(
                                   "ClassifiedService",null);
         businessService.setBusinessKey(businessKey);

         BindingTemplate bindingTemplate = new BindingTemplate();

         AccessPoint accessPoint = new AccessPoint(
"http://www.daily-moon.com:8080/axis2/services/ClassifiedService", 
                                                   "http");
         bindingTemplate.setAccessPoint(accessPoint);

         TModelInstanceDetails tModelDetails = 
                                 new TModelInstanceDetails();
         TModelInstanceInfo tModelInstanceInfo = 
                new TModelInstanceInfo(
                       "332F67D0-D8A1-11DA-A5BF-DF15F533BFA1");

         InstanceDetails instanceDetails = new InstanceDetails();
         OverviewDoc overviewDoc = new OverviewDoc();
         OverviewURL overviewURL = new OverviewURL(
"http://www.nicholaschase.com/ClassifiedService-impl.wsdl");
         overviewDoc.setOverviewURL(overviewURL);
         instanceDetails.setOverviewDoc(overviewDoc);

         tModelInstanceInfo.setInstanceDetails(instanceDetails);         

         tModelDetails.add(tModelInstanceInfo);
         bindingTemplate.setTModelInstanceDetails(tModelDetails);

         BindingTemplates bindingTemplates = new BindingTemplates();
         bindingTemplates.add(bindingTemplate);
         businessService.setBindingTemplates(bindingTemplates);

         KeyedReference wsdlNotation = 
            new KeyedReference(TModel.TYPES_TMODEL_KEY, 
                               "wsdlSpec", 
                 "C1ACF26D-9672-4404-9D70-39B756E62AB4");
         KeyedReference typeNotation = 
            new KeyedReference("ntis-gov:naics:1997", 
                               "511110", 
                 "C0B9FE13-179F-413D-8A5B-5004DB8E5BB2");
         CategoryBag catBag = new CategoryBag();
         catBag.add(wsdlNotation);
         catBag.add(typeNotation);
         businessService.setCategoryBag(catBag);

         Vector services = new Vector();
         services.addElement(businessService);
         
         ServiceDetail serviceDetail = proxy.save_service(
                        token.getAuthInfoString(),services);

         Vector businessServices = 
                 serviceDetail.getBusinessServiceVector();
         BusinessService businessServiceReturned = 
                (BusinessService)(businessServices.elementAt(0));

         String serviceKey = businessServiceReturned.getServiceKey();

         System.out.println("The Name: "+          
                businessServiceReturned.getDefaultNameString());
         System.out.println("The ServiceKey: "+ serviceKey);

      } catch(Exception e ) {
         e.printStackTrace();         
      }
   }
}

现在,Gene 发现此模式非常熟悉;按照其在 XML 文档中的形式创建这些对象。创建 BusinessService,添加 businessKey。创建 BindingTemplate,同时确保引用创建接口 tModel 时创建的 tModelKey 和实际 WSDL 文件的 URL。创建 categoryBag,添加它,并保存服务。检索服务及其名称和键。运行应用程序后,Gene 获得了清单 33 中所示的结果。


清单 33. 检索服务名称键
                    

Security authToken:authToken:E4203390-D8A5-11DA-A5BF-8F6C6FEDFEBD
The Name: ClassifiedService
The ServiceKey: E43F2D40-D8A5-11DA-A5BF-880A3C83523B





回页首


查找公司

接下来,Gene 开始着手将这些搜索投入实际使用。他首先进行公司搜索,尝试确保报社的信息已被输入注册中心中,且并未重复。请参见清单 34


清单 34. 查找公司
                    
import org.uddi4j.client.UDDIProxy;
import org.uddi4j.response.AuthToken;
import org.uddi4j.transport.TransportFactory;
import java.util.Vector;

import org.uddi4j.datatype.Name;
import org.uddi4j.response.BusinessInfo;
import org.uddi4j.response.BusinessList;
import org.uddi4j.util.FindQualifier;
import org.uddi4j.util.FindQualifiers;

public class FindBusiness{

   public static void main (String args[]){
      String inquiryURL = "http://localhost:8080/juddi/inquiry";
      String publishURL = "http://localhost:8080/juddi/publish";
      String userId = "juddi";
      String credential = "juddi";

      String transportClass = 
             "org.uddi4j.transport.ApacheAxisTransport";
      System.setProperty(TransportFactory.PROPERTY_NAME, 
                         transportClass);

      UDDIProxy proxy = new UDDIProxy();

      try {

         proxy.setInquiryURL(inquiryURL);
         proxy.setPublishURL(publishURL);

         AuthToken token = proxy.get_authToken(userId, credential);
         System.out.println("Security authToken:" + 
                                    token.getAuthInfoString());

         String businessToFind = "The Daily Moon";
         Vector names = new Vector();
         names.add(new Name(businessToFind));

         FindQualifiers findQualifiers = new FindQualifiers();
         Vector qualifier = new Vector();
         qualifier.add(new FindQualifier("exactNameMatch"));
         findQualifiers.setFindQualifierVector(qualifier);
         BusinessList businessList = 
                        proxy.find_business(names, null, null, 
                                   null,null,findQualifiers,5);

         Vector businessInfoVector  = 
             businessList.getBusinessInfos().getBusinessInfoVector();
         for( int i = 0; i < businessInfoVector.size(); i++ ){
            BusinessInfo businessInfo = 
                      (BusinessInfo)businessInfoVector.elementAt(i);
            System.out.println(businessInfo.getDefaultNameString() +
                               ": " +
 businessInfo.getBusinessKey());
         }

      } catch(Exception e ) {
         e.printStackTrace();         
      }
   }
}

Gene 正在查找特定的 name 值,因此这就是他所构建的搜索类型。他创建了具有单个项的 Name 对象的 Vector,并创建了 FindQualifier 来指定要查找精确匹配。最后,他将请求提交给 find_business() 方法,此方法接受以下参数:任何 discoveryURLs、一个 IdentifierBag、一个 CategoryBag、一个 TModelBag、任何 FindQualifiers 以及要返回的最大结果数。

所得到的结果是一个 BusinessList,Gene 将对其进行遍历,以查看所有的值,从而确定信息是否重复。对于每个值,他将打印出名称和 businessKey,如清单 35 中所示。


清单 35. 公司名称和 businessKey
                    
Security authToken:authToken:DBEAE280-D8A8-11DA-A5BF-A6D55D3D237D
The Daily Moon: 1D359E20-D899-11DA-A5BF-F9EAF6D4E3F7
The Daily Moon: 1A3DB880-D5F4-11DA-B880-F94D3591C691

在本例中,他可以看到信息出现了重复,因此可以将多余的 businessKey 提交给 UDDIProxy 对象的 delete_business() 方法。





回页首


查找服务

接下来,Gene 希望确保能够基于类别查找 ClassifiedService。请参见清单 36


清单 36. 查找某种类型的服务
                    
import org.uddi4j.client.UDDIProxy;
import org.uddi4j.response.AuthToken;
import org.uddi4j.transport.TransportFactory;
import java.util.Vector;

import org.uddi4j.util.CategoryBag;
import org.uddi4j.util.KeyedReference;
import org.uddi4j.datatype.tmodel.TModel;
import org.uddi4j.datatype.binding.BindingTemplate;
import org.uddi4j.datatype.binding.TModelInstanceInfo;
import org.uddi4j.datatype.binding.TModelInstanceDetails;
import org.uddi4j.datatype.binding.AccessPoint;
import org.uddi4j.datatype.binding.InstanceDetails;
import org.uddi4j.datatype.service.BusinessService;
import org.uddi4j.response.ServiceDetail;
import org.uddi4j.response.ServiceInfo;
import org.uddi4j.response.ServiceList;

public class FindTypeOfService{

   public static void main (String args[]){
      String inquiryURL = "http://localhost:8080/juddi/inquiry";
      String publishURL = "http://localhost:8080/juddi/publish";
      String userId = "juddi";
      String credential = "juddi";

      String transportClass = 
                "org.uddi4j.transport.ApacheAxisTransport";
      System.setProperty(TransportFactory.PROPERTY_NAME, 
                         transportClass);

      UDDIProxy proxy = new UDDIProxy();

      try {

         proxy.setInquiryURL(inquiryURL);
         proxy.setPublishURL(publishURL);

         AuthToken token = proxy.get_authToken(userId, credential);
         System.out.println("Security authToken:" + 
                                 token.getAuthInfoString());
         KeyedReference wsdlNotation = 
            new KeyedReference(TModel.TYPES_TMODEL_KEY, 
                               "wsdlSpec", 
                 "C1ACF26D-9672-4404-9D70-39B756E62AB4");
         KeyedReference typeNotation = 
            new KeyedReference("ntis-gov:naics:1997", 
                               "511110", 
                 "C0B9FE13-179F-413D-8A5B-5004DB8E5BB2");
         CategoryBag catBag = new CategoryBag();
         catBag.add(wsdlNotation);
         catBag.add(typeNotation);

         ServiceList serviceList = proxy.find_service(null, null, 
                                             catBag,null,null,5);

         Vector serviceInfoVector = 
               serviceList.getServiceInfos().getServiceInfoVector();
         for( int i = 0; i < serviceInfoVector.size(); i++ ){
            ServiceInfo serviceInfo = 
                   (ServiceInfo)serviceInfoVector.elementAt(i);

            System.out.println("Service name: " + 
                          serviceInfo.getDefaultNameString());
            System.out.println("Service key: " + 
                          serviceInfo.getServiceKey());

            ServiceDetail serviceDetail = 
                proxy.get_serviceDetail(serviceInfo.getServiceKey());

            BusinessService thisService =             
                    (BusinessService)serviceDetail
                           .getBusinessServiceVector().elementAt(0);
            if (thisService.getBindingTemplates().size() > 0){
               BindingTemplate thisBinding =                
                      (BindingTemplate)thisService
                                 .getBindingTemplates().get(0);

               TModelInstanceDetails tModelDetails = 
                              thisBinding.getTModelInstanceDetails();
               TModelInstanceInfo tModelInfo = tModelDetails.get(0);
               InstanceDetails instanceDetails = 
                              tModelInfo.getInstanceDetails();
               String wsdlDocument = 
                              instanceDetails.getOverviewDoc()
                                             .getOverviewURLString();
               System.out.println("Document located at " + 
                                             wsdlDocument);
            }
         }

      } catch(Exception e ) {
         e.printStackTrace();         
      }
   }
}

Gene 首先创建 CategoryBag,以便搜索与报纸有关的所有 WSDL 指定的服务。所得到的结果是一个 ServiceList,他可通过对其进行遍历来获得更多的信息。ServiceInfo 对象表示结果中的服务,他将对每个此类对象进行遍历,并同时显示其名称和 serviceKey

不过,如果 Gene 希望得到更多的详细信息,如 WSDL 文件的 URL,他必须使用 serviceKey 来请求服务的 ServiceDetailServiceDetail 具有零个或零个以上与其关联的 BindingTemplates,如果找到一个,则将通过 TModelInstanceDetails 对象向下获得 InstanceDetails 对象,此对象中包含 OverviewDoc,也能据此得到 OverviewURL。结果将不仅显示所查询服务的名称和 serviceKey,还会显示供用户查找更多信息的 URL。请参见清单 37


清单 37. 最终结果
                    
Security authToken:authToken:59FE37C0-D8AF-11DA-A5BF-A79333DB92F9
Service name: ClassifiedService
Service key: E43F2D40-D8A5-11DA-A5BF-880A3C83523B
Document located at 
         http://www.nicholaschase.com/ClassifiedService-impl.wsdl





回页首

posted on 2006-12-29 19:33 SIMONE 阅读(1575) 评论(1)  编辑  收藏 所属分类: AXISJAVA

FeedBack:
# re: 了解 Web 服务规范: 第 3 部分:统一描述、发现和集成 (UDDI) (3)
2007-11-08 18:40 | 核桃
如果能早看到您的这篇文章,我就省掉1周的郁闷时间了啊 !感谢高人讲解,真的很清楚啊!!  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: