1 / 27

J2EE —— 第 10 章 Java API for XML Registries

J2EE —— 第 10 章 Java API for XML Registries. JAXR 概述. XML Registries 用于构建、部署、发现 Web 服务 (ebXML,UDDI) JAXR 体系结构. 实现 JAXR 客户端. 查找连接工厂 import javax.xml.registry.*; import javax.naming.*; ... Context context = new InitialContext();

eyad
Download Presentation

J2EE —— 第 10 章 Java API for XML Registries

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. J2EE——第10章Java API for XML Registries

  2. JAXR概述 • XML Registries用于构建、部署、发现Web服务(ebXML,UDDI) • JAXR体系结构

  3. 实现JAXR客户端 • 查找连接工厂 import javax.xml.registry.*; import javax.naming.*; ... Context context = new InitialContext(); ConnectionFactory connFactory = (ConnectionFactory) context.lookup("java:comp/env/eis/JAXR"); • 创建连接工厂 ConnectionFactory connFactory = ConnectionFactory.newInstance();

  4. 创建连接 Properties props = new Properties(); props.setProperty("javax.xml.registry.queryManagerURL", "http://uddi.ibm.com/testregistry/inquiryapi"); props.setProperty("javax.xml.registry.lifeCycleManagerURL", "https://uddi.ibm.com/testregistry/publishapi"); connFactory.setProperties(props); Connection connection = connFactory.createConnection();

  5. 设置连接属性 • javax.xml.registry.queryManagerURL • javax.xml.registry.lifeCycleManagerURL • javax.xml.registry.semanticEquivalences • javax.xml.registry.security.authenticationMethod • javax.xml.registry.uddi.maxRows • javax.xml.registry.postalAddressScheme • com.sun.xml.registry.http.proxyHost (https) • com.sun.xml.registry.http.proxyPort (https) • com.sun.xml.registry.http.proxyUserName • com.sun.xml.registry.http.proxyPassword • com.sun.xml.registry.useCache • com.sun.xml.registry.userTaxonomyFilenames

  6. 获取和使用RegistyService对象 RegistryService rs = connection.getRegistryService(); BusinessQueryManager bqm = rs.getBusinessQueryManager(); BusinessLifeCycleManager blcm = rs.getBusinessLifeCycleManager();

  7. 按名称查找组织 Collection findQualifiers = new ArrayList(); findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC); //findQualifiers.add(FindQualifier.CASE_SENSITIVE_MATCH); Collection namePatterns = new ArrayList(); namePatterns.add(qString); //namePatterns.add("%" + qString + "%"); BulkResponse response =bqm.findOrganizations(findQualifiers, namePatterns, null, null, null, null); Collection orgs = response.getCollection();

  8. 按类别查找组织 ClassificationScheme cScheme= bqm.findClassificationSchemeByName(null, "ntis-gov:naics"); Classification classification = blcm.createClassification(cScheme, “Snack and Nonalcoholic Beverage Bars", “722213"); Collection classifications = new ArrayList(); classifications.add(classification); BulkResponse response = bqm.findOrganizations(null, null, classifications, null, null, null); Collection orgs = response.getCollection();

  9. 基于WSDL提供服务的组织 String schemeName = “uddi-org:types"; ClassificationScheme uddiOrgTypes = bqm.findClassificationSchemeByName(null, schemeName); Classification wsdlSpecClassification = blcm.createClassification(uddiOrgTypes, "wsdlSpec", "wsdlSpec"); Collection classifications = new ArrayList(); classifications.add(wsdlSpecClassification); BulkResponse br = bqm.findConcepts(null, null, classifications, null, null);

  10. 搜查概念 Collection specConcepts = br.getCollection(); Iterator iter = specConcepts.iterator(); while (iter.hasNext()) { Concept concept = (Concept) iter.next(); //getKey(concept) String name = getName(concept); //getDescription(concept) Collection links = concept.getExternalLinks(); if (links.size() > 0) { ExternalLink link = (ExternalLink) links.iterator().next(); System.out.println("\tURL of WSDL document: '" + link.getExternalURI() + "'"); } Collection specConcepts1 = new ArrayList(); specConcepts1.add(concept); br = bqm.findOrganizations(null, null, null, specConcepts1, null, null); }

  11. 查找服务和服务绑定 Iterator orgIter = orgs.iterator(); while (orgIter.hasNext()) { Organization org = (Organization) orgIter.next(); Collection services = org.getServices(); Iterator svcIter = services.iterator(); while (svcIter.hasNext()) { Service svc = (Service) svcIter.next(); Collection serviceBindings = svc.getServiceBindings(); Iterator sbIter = serviceBindings.iterator(); while (sbIter.hasNext()) { ServiceBinding sb = (ServiceBinding) sbIter.next(); } } }

  12. 管理注册数据 • 从注册获取授权 • 创建组织 • 添加类别 • 将服务和服务绑定添加到组织 • 发布组织 • 发布规范概念 • 从注册删除数据

  13. 从注册获取授权 String username = "myUserName"; String password = "myPassword"; // Get authorization from the registry PasswordAuthentication passwdAuth = new PasswordAuthentication(username, password.toCharArray()); Set creds = new HashSet(); creds.add(passwdAuth); connection.setCredentials(creds);

  14. 创建组织 InternationalString s = blcm.createInternationalString("The Coffee Break"); Organization org = blcm.createOrganization(s); s = blcm.createInternationalString("Purveyor of " + "the finest coffees. Established 1914"); org.setDescription(s); User primaryContact = blcm.createUser(); PersonName pName = blcm.createPersonName("Jane Doe"); primaryContact.setPersonName(pName); TelephoneNumber tNum = blcm.createTelephoneNumber(); tNum.setNumber("(800) 555-1212"); Collection phoneNums = new ArrayList(); phoneNums.add(tNum); primaryContact.setTelephoneNumbers(phoneNums); org.setPrimaryContact(primaryContact);

  15. 添加类别 ClassificationScheme cScheme= bqm.findClassificationSchemeByName(null, "ntis-gov:naics"); Classification classification = blcm.createClassification(cScheme, “Snack and Nonalcoholic Beverage Bars", “722213"); Collection classifications = new ArrayList(); classifications.add(classification); org.addClassifications(classifications);

  16. 将服务和服务绑定添加到组织 Collection services = new ArrayList(); InternationalString s = blcm.createInternationalString("My Service Name"); Service service = blcm.createService(s); s = blcm.createInternationalString("My Service Description"); service.setDescription(s); Collection serviceBindings = new ArrayList(); ServiceBinding binding = blcm.createServiceBinding(); s = blcm.createInternationalString(“My Service Binding ” +“Description”); binding.setDescription(s); binding.setValidateURI(false); binding.setAccessURI("http://TheCoffeeBreak.com:8080/sb/"); serviceBindings.add(binding); service.addServiceBindings(serviceBindings); services.add(service); org.addServices(services);

  17. 发布组织 Collection orgs = new ArrayList(); orgs.add(org); BulkResponse response = blcm.saveOrganizations(orgs); Collection exceptions = response.getException(); if (exceptions == null) { Collection keys = response.getCollection(); Iterator keyIter = keys.iterator(); if (keyIter.hasNext()) { javax.xml.registry.infomodel.Key orgKey = (javax.xml.registry.infomodel.Key) keyIter.next(); String id = orgKey.getId(); System.out.println("Organization key is " + id); } }

  18. 发布规范概念 InternationalString s = blcm.createInternationalString("HelloConcept"); Concept specConcept = blcm.createConcept(null, s, ""); s = blcm.createInternationalString( "Concept for Hello Service"); specConcept.setDescription(s); s = blcm.createInternationalString("Hello WSDL document"); ExternalLink wsdlLink = blcm.createExternalLink( "http://localhost:8080/hello-jaxrpc/hello?WSDL", s); specConcept.addExternalLink(wsdlLink); ClassificationScheme uddiOrgTypes= bqm.findClassificationSchemeByName(null, “uddi-org:types”); Classification wsdlSpecClassification = blcm.createClassification(uddiOrgTypes, "wsdlSpec", "wsdlSpec"); specConcept.addClassification(wsdlSpecClassification);

  19. 检索概念关键字 Collection concepts = new ArrayList(); concepts.add(specConcept); BulkResponse concResponse = blcm.saveConcepts(concepts); String conceptKeyId = null; Collection concExceptions = concResponse.getExceptions(); javax.xml.registry.infomodel.Key concKey = null; if (concExceptions == null) { Collection keys = concResponse.getCollection(); Iterator keyIter = keys.iterator(); if (keyIter.hasNext()) { concKey = (javax.xml.registry.infomodel.Key) keyIter.next(); conceptKeyId = concKey.getId(); } }

  20. 将概念设置到服务绑定 Concept specConcept = (Concept) bqm.getRegistryObject(conceptKeyId, LifeCycleManager.CONCEPT); SpecificationLink specLink = blcm.createSpecificationLink(); specLink.setSpecificationObject(specConcept); binding.addSpecificationLink(specLink); • 使用名称和类别查找概念 Collection namePatterns = new ArrayList(); namePatterns.add("HelloConcept"); BulkResponse br = bqm.findConcepts(null, namePatterns, classifications, null, null);

  21. 从注册删除数据 String id = key.getId(); Collection keys = new ArrayList(); keys.add(key); BulkResponse response = blcm.deleteOrganizations(keys); Collection exceptions = response.getException(); if (exceptions == null) { Collection retKeys = response.getCollection(); Iterator keyIter = retKeys.iterator(); javax.xml.registry.infomodel.Key orgKey = null; if (keyIter.hasNext()) { orgKey = (javax.xml.registry.infomodel.Key) keyIter.next(); id = orgKey.getId(); System.out.println("Organization key was " + id); } }

  22. 添加用户定义的分类法 ClassificationScheme cScheme = blcm.createClassificationScheme("MyScheme", "A Classification Scheme"); ClassificationScheme uddiOrgTypes = bqm.findClassificationSchemeByName(null, "uddi-org:types"); if (uddiOrgTypes != null) { Classification classification = blcm.createClassification(uddiOrgTypes, "postalAddress", "postalAddress" ); cScheme.addClassification(classification); ExternalLink externalLink =blcm.createExternalLink( "http://www.mycom.com/myscheme.html", "My Scheme"); cScheme.addExternalLink(externalLink); Collection schemes = new ArrayList(); schemes.add(cScheme); BulkResponse br = blcm.saveClassificationSchemes(schemes); }

  23. 得到scheme uuid if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) { System.out.println("Saved ClassificationScheme"); Collection schemeKeys = br.getCollection(); Iterator keysIter = schemeKeys.iterator(); while (keysIter.hasNext()) { javax.xml.registry.infomodel.Key key = (javax.xml.registry.infomodel.Key) keysIter.next(); System.out.println("The postalScheme key is " + key.getId()); System.out.println("Use this key as the scheme" + " uuid in the taxonomy file"); } }

  24. 将分类法添加到JAXR提供者 <JAXRClassificationScheme id="uuid:nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn“ name="MyScheme"> <JAXRConcept id="uuid:C0B9FE13-179F-413D-8A5B-5004DB8E5BB2/11" name="Agriculture, Forestry, Fishing and Hunting" parent="uuid:C0B9FE13-179F-413D-8A5B-5004DB8E5BB2" code="11"></JAXRConcept> props.setProperty("com.sun.xml.registry.userTaxonomyFilenames", "c:\mydir\xxx.xml|c:\mydir\xxx2.xml");

  25. 运行客户端示例 • JAXRQuery.java显示如何为组织搜索注册 • JAXRQueryByNAICSClassification.java显示如何使用通用分类方案搜索注册 • JAXRQueryByWSDLClassification.java显示如何为使用WSDL文档方法进行自我描述的Web服务搜索注册 • JAXRPublish.java显示如何将组织发布到注册 • JAXRDelete.java显示如何从注册删除组织 • JAXRSaveClassificationScheme.java显示如何将分类方案发布到注册 • JAXRPublishPostal.java显示如何从组织检索邮政地址 • JAXRDeleteScheme.java显示如何从注册删除分类方案 • JAXRPublishConcept.java显示如何发布WSDL文档概念

  26. 运行客户端示例 • JAXRPublishHelloOrg.java显示如何发布带有引用WSDL文档的服务绑定的组织 • JAXRDeleteConcept.java显示如何删除概念 • JAXRMyObjects.java列出你在注册中拥有的所有对象 • build.xml • JAXRExamples.properties • postalconcepts.xml

  27. 在J2EE应用程序中使用JAXR客户端 • 编码应用程序客户端MyAppClient.java,它使用JNDI lookup获取一个到PubQuery企业bean的远程home接口的句柄,使用句柄创建bean的实例并调用其executePublish和executeQuery方法 • 编码PubQuery会话bean • 编译源文件 • 导入证书 • 启动Application Server • 创建JAXR资源(通过连接器资源访问JAXR资源适配器) • 创建、打包、部署应用程序 • 运行应用程序客户端

More Related