引言

统一描述、发现和集成(UDDI) 正在快速成为在 Web 上存储可用业务流程的标准。虽然 UDDI 能够存储大量不同类型的数据,但就本技巧而言,我将把重点放在如何使用 UDDI 来注册 Web 服务,从而使 Web 服务可用于应用程序级的消费。

假设

已经安装了DB2 ®,并且创建了示例数据库(本示例要用到 Employee 表和 Department 表。要创建示例数据库,打开“DB2 First Steps”,然后单击“Create Sample Database”链接)。

已经安装并正确配置了 UDDI 注册中心。请参阅用于自动安装 UDDI 注册中心来使用 Cloudscape 数据库的 InstallUDDI 清单。从命令窗口执行installuddilibs.bat来创建必需的目录结构。

本技巧涵盖了哪些内容

本技巧给 Java® 开发人员提供了一种快速并且简单的方法来开发他们自己的 UDDI Java 应用程序,并使用这些应用程序来消费在注册中心注册了的 Web 服务。附带的示例代码包含一个 Payroll Web 服务(从一个实体 bean 部署而来的)和一个 UDDI 会话 bean。

技巧背景

本技巧主要是基于教程“使用 WSDK V5.1 发现 Web 服务:UDDI”(developerWorks, 2003 年 11 月),参考资料部分引用了该教程。我的目的是提出基础的 Java 的统一描述、发现和集成 (UDDI4J) 类的扩展,从而帮助您快速建立您自己的 Web 服务 UDDI 注册中心。完成“Discover Web services with the WSDK V5.1: UDDI”这个教程的过程中,我开发了一个提供更高级访问 UDDI4J API 的扩展 API。因为本技巧的目的是注册、发现和消费存储在 UDDI 注册中心的 Web 服务,所以只展开了 UDDI4J 功能的一小部分。有关 UDDI 以及它在存储 Web 服务上的应用的更广泛的讨论,请参阅 Tom Bellwood 的文章“理解 UDDI”(developerWorks,2002 年 7 月)。

Payroll Web 服务

附带的Payroll.ear文件包含一个名为PayrollEjbPrj的企业 JavaBean (EJB) 方案。在这个 EJB 方案里有两个实体 bean(Department 和 Employee)以及一个会话 bean (Payroll)。Department 和 Employee 这两个实体 bean 显示了用于示例数据库的 getter 和 setter 方法。Payroll bean 显示了 12 种方法,它使用实体 bean 的 getter 方法从示例数据库中查询各种信息片断。示例代码很容易被扩展,从 Payroll bean 内部提供 setter 函数。显示所有的示例数据库字段不在本技巧的范围之内。

UDDIClient 会话 EJB

UDDIClient 会话 bean 几乎全部由下一部分讨论的 UDDI 实用 API 构成。

UDDI 注册中心可以包括业务、服务以及 TModel。UDDIClient bean 为每类 UDDI 条目提供了一个 publish() 方法和两个 delete() 方法。如下面的清单 1所示,把任务移交给 UDDI 实用 API 处理时,方法签名(method signature)方法尽可能的简单。

清单 1.方法签名

public String publishBusiness(String busName)

{

return BusinessUtilities.publishBusiness(busName);

}

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);

}

public void deleteTModelByName(String tModelName)

{

ModelUtilities.deleteTModelByName(tModelName);

}

public void deleteTModelByKey(String tModelKey)

{

ModelUtilities.deleteTModelByKey(tModelKey);

}

getService 和 executeService 方法

UDDIClient bean 的 getService 和 executeService 方法演示了如何重新获得我们的 Payroll Web 服务并调用其中的一些方法。executeService 方法用一个字符串表示一个存储在注册中心的服务的名称。在示例代码中,注册的服务是 Payroll Web 服务。为了达到本技巧的预期效果,我硬编码了两个方法,供注册中心内创建的 Payroll Web 服务调用,如清单 2所示。

清单 2. getService 和 executeService 方法

/**

* 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);

//Create a set of accespoints

Set accessSet = accessPoints.keySet();

Iterator it = accessSet.iterator();

Payroll payroll = null;

Object obj = null;

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);

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;

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());

}

return payroll;

}

UDDI 实用 API

UDDI 实用 API 有四个主要的类,我将在清单3、4以及5中详细描述其中的三个。第 4 个 (Utilities.class) 包含所有的 UDDI 注册的设置信息。 "使用 WSDK V5.1 将服务发布到 UDDI 注册中心"(developerWorks,2003 年 11 月)这个教程详细解释了其中的值和结构。

清单 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)

清单 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)

清单 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)

结束语

正如您所看到的,UDDI 程序设计是在使用 UDDI 注册中心的网络上共享信息的非常有效的途径。这里的示例代码,更具体地说,UDDI 实用 API 提供了一个起点,从这个起点出发您能够开发更加用户化的解决方案。

uddi java_【Java】Web 服务编程技巧与窍门: 在 UDDI 注册中心为 Web 服务注册开发 UDDI Java 应用程序...相关推荐

  1. java抽取公共方法的诀窍_Web服务编程技巧和窍门,Java应用程序的旧式集成技术...

    存档日期:2019年5月15日 | 首次发布:2000年11月16日 您可以按照此处介绍的四种常见集成策略中的一种或多种,​​轻松地将基于Java,J2EE和EJB的应用程序与现有的旧系统集成. 此内 ...

  2. 关于《Java数字图像处理-编程技巧与应用实践》一书 源代码

    关于<Java数字图像处理-编程技巧与应用实践>一书 源代码 本书所有的源代码我已经整理上传到华章图书的官方网站与 我自己的GITHUB上,本人GITHUB的地址如下: https://g ...

  3. 微服务 注册中心_4.微服务架构的第二个组件:注册中心

    在微服务架构下,主要有三种角色: 服务提供者(RPC Server) 服务消费者(RPC Client) 服务注册中心(Registry) RPC Server:服务提供者,启动时根据服务发布文件se ...

  4. 蚂蚁金服服务注册中心 SOFARegistry 解析 | 服务发现优化之路

    SOFAStack Scalable Open Financial  Architecture Stack 是蚂蚁金服自主研发的金融级分布式架构,包含了构建金融级云原生架构所需的各个组件,是在金融场景 ...

  5. 注册中心集群 服务负载均衡 雪崩效应Hystrix

    集群 为什么需要集群? 如果只有一个注册中心服务器,会存在单点故障所以要集群. 什么是集群? 一组协同工作的服务实体,用以提供比单一服务实体更具扩展性和可用性的服务平台. 多台服务器集中在一起,实现同 ...

  6. 微服务注册中心:Consul——服务注册

    系列文章: 微服务架构:网关概念与 zuul 微服务网关:Spring Cloud Gateway -- Zuul 微服务网关:Spring Cloud Config- 配置中心 微服务网关方案:Ko ...

  7. 蓝桥杯java初赛本科组,2012年第三届蓝桥杯全国软件专业人才设计与开发大赛Java本科组初赛试题...

    这是2012年第三届蓝桥杯全国软件专业人才设计与开发大赛Java本科组初赛试题的完整版 2012第三届蓝桥杯软件大赛Java语言本科组初赛试题 (说明:1-4题为结果填空,5-7为程序填空,8-10为 ...

  8. 用redis做注册中心如何感知服务的上线和下线?

    最近记录了一些java中常踩的坑.设计思路和小知识点,大家可以看看 详细记录一次接入xxl-job的踩坑路径 30s快速解决循环依赖 idea中一个小小的操作竟能解决如此多的问题 docker中的服务 ...

  9. 基于注册中心的Dubbo服务

    作为主流的服务治理组件,Dubbo提供了很多丰富的功能,那么最根本的就是要解决大规模集群之后的服务注册和发现的问题.而dubbo中对于注册中心这块是使用zookeeper来支撑的.当然在目前最新的版本 ...

最新文章

  1. Ant Design源码分析(三):Wave组件
  2. 消息中间件:为什么我们选择 RocketMQ
  3. Tree前序反序列化
  4. MS SQL Server2008大数、小数转varchar
  5. IDEA访问数据库时,某一个字段数据库中有值但是访问到的数据始终是null
  6. 5kb大小的云洗衣机HTML源码 朋友圈在线洗衣服
  7. 爬虫-ProxyHandler代理类-通过代理发起请求
  8. vue调用数组_vue数组的运用
  9. 北京理工大学计算机系郭伟,【记忆辉煌2014】品学兼优榜样——郭伟(2012级研究生)...
  10. 在matlab环境中实现图像的傅里叶变换,matlab用傅里叶变换实现图像的低通滤波
  11. 判断double_深入解析单例模式之懒汉模式---Double-Check及volatile关键字
  12. Laravel5.1/Homestead (0.2.7) 开发环境的部署和设置
  13. 如何比较两个EXCEL 文件的不同(各个EXCEL版本的方法)
  14. time库:Python的时间时钟处理
  15. 不是“饭饭之交”! 李彦宏丁磊CP乌镇神同步
  16. 程序员因加班错失77万年会大奖,该不该补发?-千氪
  17. OpenCV 图片去水印(不需要自己做水印模板)
  18. 批处理怎么调用计算机名,Reg命令使用详解 批处理操作注册表必备
  19. zjfc---1120 对称串
  20. 如何刻录VCD防盗光盘

热门文章

  1. 电子规范管理系统(2)
  2. 基于TI DRV10970驱动直流无刷电机
  3. 机械故障诊断02-基于HHT的轴承振动分析
  4. 在网站测试中如何做好安全性测试
  5. ARM通用中断控制器GIC之中断控制
  6. 嵌入式编程和PC编程的区别
  7. 深度学习PyTorch(二)卷积神经网络
  8. 安装程序“发布者:未知 ”问题
  9. 为什么服务器需要备份?
  10. 中关村手机卖场Gphone火爆Ophone黯淡