查找和使用信息
現在已經有了所有信息(至少從理論上是這樣),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 Moon 和 Daily 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>
|
對于滿足搜索條件的每個 businessEntity
,businessList
都包含一個對應的 businessInfo
元素。其中的每個 serviceInfo
元素都包含實際的 businessEntity
的 businessKey
。其中還包含將在 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
元素。其中可用的有 exactNameMatch
、caseSensitiveMatch, sortByNameDesc, sortByDateAsc
和 sortByDateDesc
,或者 LikeKeys
(告知注冊中心,如果 categoryBag
或 identifierBag
中的鍵共享相同的 tModelKey
,則將其作為“OR”條件對待),以及 combineCategoryBags
(無論實際屬于 businessEntity
、businessService
或 bindingTemplate
,都將 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 包提供的類或任何類似的類。
最后,他設置了注冊中心的 inquiryURL
和 publishURL
值(通常二者將不同,這其中的部分原因是因為發布通常是使用 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 矢量、identifierBag
和 categoryBag
,并將其添加到 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
來請求服務的 ServiceDetail
。ServiceDetail
具有零個或零個以上與其關聯的 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 閱讀(1604)
評論(1) 編輯 收藏 所屬分類:
AXIS 、
JAVA