websphere_WebSphere Enterprise Service Bus和WebSphere Integration Developer入门

websphere

IBM®WebSphere®Enterprise Service Bus(ESB)服务器及其关联的工具WebSphere Integration Developer是两个新的IBM产品,使您能够改善异构系统之间的连接。 本质上,WebSphere Integration Developer可以帮助您开发一个框架(中介流),通过该框架来处理传入的数据(消息),根据需要调整和记录内容,然后再适当地路由到不同的目的地。 然后,您可以使用WebSphere ESB运行这些流程,并处理其他功能,例如安全性,性能,可靠性和事务管理。 本文向您展示如何:

  • 开发一个简单的中介来公开Web服务。
  • 开发更复杂的中介以连接到此Web服务,提供逻辑来适当地筛选,转换和路由传入消息。
  • 使用WebSphere Integration Developer测试客户端和基于Web的JSP前端调用生成的中介流,并检查生成的输出。

首先,通过定义一个接口,然后使用该工具自动生成必要的代码,来设置与中介流连接的简单Web服务,如下一节所述。

创建一个库界面

Web服务由接口定义,这些接口提供调用它们所需的所有信息,即所需输入和输出参数的类型以及Web服务的位置。 尽管您可以使用WebSphere Integration Developer中的Web服务资源管理器导入现有的外部Web服务接口,但本文将向您展示如何从头开始开发Web服务以演示整个过程。

打开WebSphere Integration Developer,然后关闭欢迎窗格以进入“业务集成”透视图。 如果碰巧关闭了此透视图,则可以通过选择Window => Open Perspective => Other => Business Integration重新打开它:

图1.1。 业务整合角度
图1.1。业务整合角度

首先,创建一个合适的项目来存储Web服务接口:

  1. 选择File => New => Other,然后从向导中选择Library
    图1.2。 新建项目向导
    图1.2。新建项目向导
  2. 指定StockQuoteLibrary作为库名称,然后单击Finish
    图1.3。 新建库向导
    图1.3。新建库向导

现在创建界面本身:

  1. 在工具左侧的Business Integration Navigator中,展开StockQuoteLibrary项目,然后右键单击Interfaces => New => Interface
    图1.4。 创建一个新界面
    图1.4。创建一个新界面
  2. 提供StockQuoteService的名称,然后单击Finish
    图1.5。 新界面向导
    图1.5。新界面向导

现在,新界面将在主显示屏中打开,尽管在此阶段,由于我们尚未定义任何内容,因此在很大程度上将是空白的。 每个Web服务都具有有效的功能,我们需要在定义接口时对其进行指定。 为简单起见,我们将使用传统的“股票报价”服务-该服务接受代表股票名称的字符串,并返回代表该股票价格的浮点数。 我们需要将这种服务类型定义为“双向”,因为其中涉及请求和响应消息:

  1. 单击“ 添加请求响应操作” (“定义操作”右边的第一个图标),向接口表添加一行。
  2. 将该行中的默认名称从operation1更改为getQuote ,然后单击“定义定义”右侧的第三个图标“ 添加输入 ”。
  3. 将输入参数的默认名称从input1更改为inputGetQuote
  4. 单击“ 类型”列,然后选择“ 新建”以创建新类型的业务对象以用作输入。 在“数据类型选择”弹出窗口中,单击“ 新建”
    图1.6。 定义接口
    图1.6。定义接口
  5. 在打开的“新业务对象”框中(图1.7),命名为StockName并单击Finish => OK
    图1.7。 新建业务对象向导
    图1.7。新建业务对象向导
  6. 现在,新的StockName业务对象应出现在“类型”列中。 右键单击它,然后选择“ 在业务对象编辑器中打开” 。 将打开一个新的编辑器,您可以在其中详细定义此新业务对象。
  7. 单击“ 业务对象 ”右侧的“ 向业务对象添加属性”,并将默认值attribute1更改为name
    图1.8。 StockName业务对象接口
    图1.8。 StockName业务对象接口
  8. 关闭面板,选择保存更改; 已经定义了一个仅包装String值的简单业务对象。 返回界面面板,完成一个类似的过程,以新类型的StockQuote定义一个名为outputGetQuote的输出参数,该类型将一个浮点值包装为名称price
  9. 保存界面:按Ctrl-S或关闭编辑器窗口,并在出现提示时单击“ 是”

您已经完全定义了接口,其外观应类似于下面的图1.9。 尽管可以在使用接口的中介项目中直接定义和存储接口,但是通过在一个单独的库项目(例如该接口库)中创建它们,您可以使它们易于被其他中介项目重用。

图1.9。 完成的StockQuote界面
图1.9。完成的StockQuote界面

实施网络服务

现在,您已经定义了Web服务接口,您需要创建此服务的本地实现,可以通过中介流对其进行访问。 与接口一样,首先创建一个合适的项目来容纳此服务:

  1. 选择File => New => Other,然后从向导中选择Mediation Module
  2. 在“新中介模块”弹出窗口中,输入StockQuoteService作为“模块名称”,并确保将指定的“获取运行时”设置为实际的WebSphere ESB服务器或WebSphere ESB服务器存根。 保持选中默认设置,然后单击“ 下一步”
  3. 在下一个面板中,选择先前创建的StockQuoteLibrary ,然后单击Finish

现在,工具左侧的Business Integration Navigator将显示新项目。 展开并找到子组件StockQuoteService 。 它表示中介模块的组装图,其中指定了高级中介组件的配置(例如,导入和导出连接,中介流的数量和安排,等等)。 要实现它:

  1. 双击此子组件。 组装图编辑器将打开,其中包含单个中介流组件Mediation1 。 该编辑器的重要功能如下所示:
    图2.1。 新StockQuoteService中介模块的组装图
    图2.1。新StockQuoteService中介模块的组装图
  2. 单击中介流组件两次,以将其名称更改为StockQuoteServiceMediation 。 (这些图中指定的名称实际上未被底层代码使用,但是它们使流程从用户的角度更易于理解,并简化了向系统日志输出的信息。)
  3. 从面板左侧的图标菜单中,选择带有绿色箭头的图标(如上图2.1所示)以展开菜单。 然后选择向下的箭头图标,它代表一个导出组件。 单击“装配图”画布,以将“导出”添加到装配图,并将其重命名为StockQuoteServiceExport
  4. 在图标菜单点击底部的图标, 电线 ,然后点击StockQuoteServiceExportStockQuoteServiceMediation两个连接在一起。 (您可以通过单击“导出”组件并将产生的导线拖动到“中介”组件上来创建相同的连接,然后释放鼠标按钮。)
  5. 现在将显示一个面板(添加电线),该面板说明了接线操作会将与中介组件使用的接口相匹配的接口添加到导出中,从而公开了此接口供其他模块使用。 选择始终创建而不提示 ,然后单击确定
  6. 在下一个窗口的Add Interface中,选择先前定义的StockQuoteService接口,然后单击OK
  7. 现在,“装配图编辑器”应该显示“导出”和“中介”组件之间的链接。 请注意,每个组件上都有指定的匹配接口,由包含“ I”的圆圈表示。 到目前为止,在该图中,我们有一个Export(暴露)以公开该中介流以供其他流使用,还有一个Mediation组件,其中将包含实际中介流的详细信息。 所需的最后一个组件是要调用的Web服务的表示。 要创建它,请单击信封图标,选择上面带有“ J”的底部图标,然后单击画布。
  8. 以与以前相同的方式,将此组件重命名为StockQuoteService ,并将中介组件连接到该组件,选择StockQuoteLibrary接口作为要添加的引用。 该参考允许链接中介组件StockQuoteServiceMediation访问Java组件。 它在编辑器中以图形形式显示为包含1..1的框。
  9. 最后,要整理内容,请右键单击编辑器画布,然后选择“ 自动排列内容” ,然后保存更改。

现在,我们有了调解流程的基础,其外观应类似于下面的图2.2。 蓝色感叹号表示该组件的基础实现尚未完成。

图2.2。 完成的StockQuoteService组装图
图2.2。完成的StockQuoteService组装图

首先,我们将实现Java组件:

  1. 双击Java组件图标,然后选择默认选项。 基于StockQuoteService库的Java类StockQuoteServiceImpl将在文本编辑器中自动打开。 该类提供了接口中详细介绍的所有方法的基本框架。 在我们的简单情况下,这意味着我们只有一个getQuote方法和一个getMyService方法来返回该类的实例。
  2. 用下面部分中的代码替换getQuote方法,除了提供适当的输出日志记录之外,它还使用Web服务接口创建并填充要输出的有效业务对象。 返回值取决于输入消息的内容,如下所述。
    清单1. StockQuoteServiceImpl.java中getQuote方法的代码
    public DataObject getQuote(DataObject inputGetQuote) throws
       ServiceBusinessException {
    
       // retrieve the String value of the 'name' attribute
       System.out.println("StockQuoteServiceImpl - getQuote : Get name from inputGetQuote");
       String name = inputGetQuote.getString("name");
       System.out.println("StockQuoteServiceImpl -	getQuote : name = " + name);
    
       // Now get the BO Factory to create the reply from
       System.out.println("StockQuoteServiceImpl - getQuote : Create BOFactory");
       ServiceManager serviceManager = new ServiceManager();
       BOFactory bofactory =
          (BOFactory) serviceManager.locateService("com/ibm/websphere/bo/BOFactory");
    
       // Create the output message structure - as specified by the StockQuoteSerice interface
       System.out.println("StockQuoteServiceImpl - getQuote : Create getQuoteResponse");
       DataObject getQuoteResponse = bofactory.createByElement(
          "http://StockQuoteLibrary/StockQuoteService",
          "getQuoteResponse");
    
       // Now create the Data Object to populate with the return value
       System.out.println("StockQuoteServiceImpl - getQuote : Create outputGetQuote");
       DataObject outputGetQuote = getQuoteResponse.createDataObject("outputGetQuote");
    
       // And finally, set the appropriate return value
       if (name.equals("IBMvetted")) {
          System.out.println("StockQuoteServiceImpl - getQuote : Set the price to 100.00f");
          outputGetQuote.setFloat("price", 100.00f);
       } else if (name.equals("IBM")) {
          System.out.println("StockQuoteServiceImpl - getQuote : Accessed with not vetted input"
             + " - return old stockquote price, 80.00f");
          outputGetQuote.setFloat("price", 80.00f);
       } else {
          System.out.println("StockQuoteServiceImpl - getQuote : Unrecognised stockquote name"
             + " - set price to 0.00f");
          outputGetQuote.setFloat("price", 0.00f);
       }
    
       return outputGetQuote; 
    }
  3. WebSphere Integration Developer应该在此新代码中突出显示一些由于无法解析的类引用而引起的错误。 要导入这些内容,请右键单击并选择Source => Organize Imports

关闭并保存Java类,然后通过双击它并选择默认值来实现中介组件。 将打开一个两面板的中介流编辑器。 顶部窗格(“操作连接”窗格)显示了中介组件可用的接口和引用。 底部窗格(中介流)窗格显示了实际的中介流:

图2.3。 中介流编辑器
图2.3。中介流编辑器

此中介模块允许调用由Java组件表示的服务,因此流程应为简单的直通连接。 要完成实施:

  1. 在顶部窗格左侧的界面框中单击getQuote操作,以在下面的“中介流”窗格中打开该流。 最初,此流包含两个未连接的节点,分别表示消息进入流组件( StockQuoteService_getQuote_Input )和退出流( StockQuoteService_getQuote_InputResponse )的点。 由于顶部窗格中的StockQuoteServicePartner引用未连接到该接口,因此该流只能直接返回消息,而不能将其传递以供更高版本的中介组件进行进一步处理。
  2. 要使中介组件能够访问先前定义的Java组件,请在两个getQuote操作之间单击并从左向右拖动,以在顶部面板中加入接口和引用。 在底部窗格中创建一个新节点StockQuoteService_getQuote_Callout
    图2.4。 在中介流编辑器中连接界面和参考
    图2.4。在中介流编辑器中连接界面和参考

现在,我们创建适当的第一个调解流程。 由于此流程的主要目的是提供与Java组件的连接,因此我们将使内容保持简单。 中介流面板左侧菜单中的图标表示可用的中介原语集。 这些原语提供了预先构建的功能单元,如图2.5所示,用作中介流的基本构建块:

图2.5。 调解原语调色板
图2.5。调解原语调色板
  1. 选择Message Logger中介原语(叠加在页面上的信封),然后单击Mediation Flow画布。 将在流( MessageLogger1 )中创建一个Message Logger原语,其工作是将通过它的消息的内容自动写入数据库,以便以后进行检查(有关详细信息,请参阅检查消息部分)。记录器默认数据库 )。
  2. 右键单击MessageLogger1并选择Show in Properties以在WebSphere Integration Developer的底部打开一个视图,您可以在其中找到更多信息并指定配置详细信息,如图2.6所示。 特别感兴趣的是“详细信息”子视图,该视图可让您指定不同的数据库详细信息。 由于默认的Cloudscape数据库是自动创建的,因此请保留初始设置:
    图2.6。 检查消息记录器原语的详细信息
    图2.6。检查消息记录器原语的详细信息
  3. 注意编辑器画布中中介节点左右两侧的小框。 这些代表输入,输出和故障终端,这些终端用于提供与其他中介原语的连接,从而创建有用的中介流(要查看是哪个中介流,请将鼠标指针悬停在它们之上)。 单击“输入”节点的输出端子,然后将结果导线拖动到MessageLogger1的输入端子以将它们连接在一起。 同样,将MessageLogger1加入Callout节点。 要处理错误,可以使用故障终端指定一个单独的路由,以便Message Logger原语抛出异常。 为了暂时保持简单,请保持此端子未连接。 完成的流程如下所示:
    图2.7:StockQuoteService的已完成请求中介流
    图2.7:StockQuoteService的已完成请求中介流
  4. 在“中介流”窗格的底部,单击“ 响应:getQuote”选项卡以切换到代表在调用Web服务后访问的中介流(响应流)的画布。
  5. 重复上述过程,添加一个Message Logger原语并将其连接到CalloutResponse和InputResponse节点:
    图2.8。 StockQuoteService的已完成响应中介流
    图2.8。 StockQuoteService的已完成响应中介流
  6. 关闭“中介流”编辑器,保存更改,然后将更改保存到随附的“装配图”中。 您现在已经完成了第一个中介模块!

创建更高级的中介模块

下一步是开发一个涉及更多的中介模块,以连接到刚刚创建的模块。 此模块将过滤和调整传入的消息,根据消息的内容提供不同的中介路由和不同的结果。 此处的示例基于现实场景,其中单个Web服务可能以多种不同方式连接。 在这里,我们将股票报价服务与其他业务逻辑合并,以根据输入消息内容模拟“服务水平”的强加:

  1. 重复上一节中使用的过程,使用StockQuoteLibrary接口创建一个名为StockQuoteMediation的中介模块。
  2. 打开组装图编辑器,添加一个Export组件,然后将其连接到中介组件,并像以前一样选择现有接口StockQuoteService
  3. 由于此中介模块旨在提供与我们刚刚定义的模块的连接,因此需要导入组件。 您可以使用侧面菜单(带有绿色箭头的图标)添加它,但这需要其他手动配置才能建立与StockQuoteService模块的连接。 相反,您可以自动定义此配置。 为此,请在Business Integration Navigator中扩展StockQuoteService模块,然后扩展基础StockQuoteService文件夹以显示此模块的导出组件StockQuoteServiceExport 。 将其拖放到当前的中介模块“装配图编辑器”中,选择“ 使用SCA绑定导入” 。 将添加一个Import组件,提供与StockQuoteService模块中Export组件的直接连接:
    图3.1。 从现有的导出组件创建导入组件
    >图3.1。从现有的导出组件创建导入组件
  4. 连接此新导入,适当地重命名编辑器的内容,并保存更改:
    图3.2。 StockQuoteMediation的已完成装配图
    图3.2。 StockQuoteMediation的已完成装配图

现在,双击中介组件,接受提供的默认设置,并执行以下操作:

  1. 像以前一样加入接口和引用操作,以允许连接到StockQuoteService导入组件,从而可以连接到StockQuoteService模块。
  2. 将消息过滤器原语(带有两个箭头的信封图标)添加到“中介流编辑器”画布中。 此原语使消息可以根据其有效负载内容路由到不同的目的地。 您可以创建额外的输出端子,然后将其与选择条件相关联:
    1. 将输入节点的输出端子连接到过滤器基元的输入。
    2. 右键单击过滤器,选择“ 添加输出端子” ,然后在弹出框中接受默认值。 名为match1的新终端将添加到中介原语。
    3. 再次右键单击过滤器,这次选择“在属性中显示”,然后访问下部视图中的“ 详细信息”选项卡。 现在,您的显示应如下所示:
      图3.3。 StockQuoteMediation流,添加了消息过滤器原语并显示了详细信息
      图3.3:StockQuoteMediation流程,其中添加了Message Filter原语并显示了Details
    4. 在此详细信息视图中,单击添加 ,然后选择自定义XPath
    5. 在XPath Expression Builder窗口中,完全展开body:getQuoteRequestMsg结构,然后单击name:string以在XPath Location:框中将其选中。
    6. 单击“条件:”行中的“ 位置值”,然后选择self :: node()
    7. 单击“ 值” ,选择“ 字符串” ,然后输入字符串IBM
    8. 现在,面板底部的Full XPath Expression值应显示为/body/getQuote/inputGetQuote/name[self::node()="IBM"] ,如图3.4所示。 单击确定,并验证终端名称是否与您刚刚添加的新名称匹配( match1 )。 然后点击完成
      图3.4。 完成的XPath Expression Builder
      图3.4。完成的XPath Expression Builder
    9. 重复步骤2至8,添加一个名为match2的新输出终端,这次将其匹配到IBMold而不是IBM
    10. 将此新终端连接到StockQuoteServicePartner标注节点。
    11. 要配置的最后一件事是分发模式:从“分发”下拉菜单中,选择“ 全部”以启用通过传入消息满足过滤条件的所有输出终端的访问。

    最终安排应如下所示:

    图3.5。 具有完整的消息过滤器原语的StockQuoteMediation流
    图3.5。具有完整的消息过滤器原语的StockQuoteMediation流

    正如您可能已经解决的那样,我们现在有一个过滤器,用于检查输入消息的名称值(假设正在使用接口指定的正确格式)。 如果等于IBMIBMold ,则将指定的终端传递给输入消息,并访问后续的连接。

  3. 将Message Logger原语添加到画布,并将Message Filter的默认终端连接到此输入。 如果其他终端上没有用户定义的过滤器针对传入消息产生有效匹配,则将触发默认过滤器终端。
  4. 添加一个Stop原语(红色正方形图标)。 将消息记录器原语的输出连接到它,如图3.6所示。 Stop原语可以使中介流完全停止。 在这种情况下,一旦消息记录器原语记录了它们的消息,它就可以用来终止通过消息过滤器默认终端路由的任何流。 换句话说,只有当传入消息的名称值为IBM才可以访问StockQuoteService模块。
    图3.6。 添加了Message Logger和Stop原语的StockQuoteMediation流
    图3.6。添加了Message Logger和Stop原语的StockQuoteMediation流
  5. 将XSL Transformation原语(具有大页面和大页面的图标)添加到画布。 该原语使您可以调整传入消息的内容。 您可以使用它在输入的股票报价名称后附加一个字符串:
    1. 将消息过滤器原语的match1输出连接到XSL Transformation原语的输入。
    2. 将XSL Transformation输出端子连接到Callout节点的输入。
    3. 右键单击XSL原语,选择Show In Properties ,然后访问下部视图中的Details选项卡。
    4. 保持默认的Root:设置为body ,这将原语限制为仅更改消息正文的内容。
    5. 单击“ 新建”以开始定义映射变换。 在“新建XSLT映射”窗口中,输入和输出消息类型已经预先定义,如图3.7所示,因为输入和输出端子都已经连接,所以原语知道期望和传递的消息类型。上。 如果需要其他消息类型,请通过“ 浏览”按钮直接从现有界面中选择来指定它们。 通过单击完成接受默认值:
      图3.7。 XSLT映射向导
      图3.7:XSLT映射向导
    6. XSL转换编辑器现在打开,显示传入和传出消息的正文结构。 在两个消息中完全展开smo (服务消息对象-中介流中使用的数据对象的类型)元素:
      图3.8。 XSL转换编辑器,具有扩展的输入(源)和输出(目标)消息结构
      图3.8。 XSL转换编辑器,具有扩展的输入(源)和输出(目标)消息结构
    7. 单击两条消息的smo根元素,然后右键单击并选择Match Mapping ,它将输入消息的内容复制到输出消息以确保它们相同。
    8. 右键单击传出(目标)消息的名称[0..1]元素,然后选择定义XSLT功能
    9. 在弹出窗口中,选择字符串 ,然后单击下一步
    10. 从下拉菜单中,选择concat ,单击Add ,然后输入字符串'vetted' (包括单引号)。 现在,此新功能应出现在中间表中:
      图3.9。 XLST功能向导
      图3.9。 XLST功能向导
    11. 退出转换编辑器,保存更改。 回到中介流编辑器中,此新创建的映射文件应显示在“属性”视图中。 最后需要执行的步骤是将此映射文件转换为正确的XSL文件,以执行实际的转换。 单击重新生成XSL并保存流:
      图3.10。 实现了XSL Transformation原语的StockQuoteMediation流和显示详细信息
      图3.10。实现了XSL Transformation原语的StockQuoteMediation流和显示详细信息

    现在,您已经配置了该中介原语,以将经过vetted的字符串附加到输入的股票报价名称值中。

  6. 最后要做的是添加一个Fail原语(红色感叹号图标-您可能需要单击红色正方形图标才能找到它)。 该原语类似于Stop原语,因为它提供了一种干净的方式来停止流。 区别在于传递给它的任何异常消息的处理方式:Stop原语将在堆栈中传播接收到的所有异常,将其传递回中介的调用者,而Fail原语将干净地吞噬它。 请注意,这可能不是理想的行为,因为它可能最终隐藏了系统的问题。 但是,在这种情况下,我们使用它来覆盖第二个Message Logger原语的错误(例如,由于数据库访问问题而可能引发的错误)。 由于这提供了非必需的功能,因此将消息记录在“死端”流上,因此在此处使用Fail原语是合适的。
  7. 现在,请求流程已完成,应如下所示:
    图3.11。 完整的StockQuoteMediation流程
    图3.11。完整的StockQuoteMediation流程
  8. 配置中介流的最后一步是连接响应流。 像以前一样执行此操作,包括Message Logger原语。 结果应类似于StockQuoteService中介中使用的流程, 如图2.7所示。

现在,新的中介模块已完成,根据输入名称String的值,提供三种不同的中介行为:

name=IBM
该消息被传递到StockQuoteService模块,具有该字符串之后vetted添加到它,而得到名称值IBMvetted
name=IBMold
该消息未更改地传递到StockQuoteService模块。
name=anything else
该消息将记录到本地Message Logger数据库中,并且流程停止。

查看服务实现清单StockQuoteServiceImpl.java ,我们可以理解以下逻辑:有效地,路线1提供了高质量的服务,返回了最新的IBM库存值。 该服务仅限于StockQuoteMediation流的用户-因此需要附加经过vetted字符串。 路线2提供了一个旧的IBM股票价值,该股票价值已过时。 路线3将服务限制为仅用于IBM股票价值。 Web服务的实时方面未实现,但是这种安排有助于显示使用WebSphere ESB和WebSphere Integration Developer可以实现的目标。

公开Web服务

现在我们已经设置了提供服务的中介模块和提供访问该服务的流程逻辑的模块,我们需要创建的最后一件事是调用完整的中介流。 在业务环境中,最后一步有些虚假,因为生产的模块很可能直接通过其发布的界面进行访问。 但是,演示正在调用的完整流程仍然很有启发性-并且您将需要在测试期间调用完整的流程。

有几种方法可以调用我们已实现的StockQuoteService Web服务。 我们将尝试两种:WebSphere Integration Developer通用测试环境(UTE)和运行JSP的Web页面。

设置测试环境

在测试此处开发的任何模块之前,您需要在运行中的WebSphere ESB服务器(或WebSphere Process Server)实例上部署并启动它们。 以下步骤假定服务器已经安装:

  1. 在下部的WebSphere Integration Developer视图中,在“业务集成”透视图中,单击“ 服务器”选项卡。
  2. 在这个新窗口中右键单击,然后选择New => Server
  3. 在“新服务器”弹出窗口中,选择IBM => WebSphere ESB Server V6 ,然后单击下一步
  4. 单击浏览并找到系统上安装的ESB-在Windows上,默认位置为C:\\ Program Files \\ IBM \\ WebSphere \\ ESB:
    图4.1。 新服务器向导
    图4.1。新服务器向导
  5. 单击两次下一步 ,接受所有默认设置。
  6. 在下一个面板中,单击全部添加以将此处开发的两个项目都添加到服务器,然后单击完成 。 服务器启动,并将这些项目发布到服务器并自动启动。
  7. 单击下部面板中的“ 控制台”选项卡,以检查服务器启动期间在服务器输出日志中列出的错误,该服务器默认情况下位于<ESB安装目录> \ profilesESB01 \ logs \ server1 \ SystemOut中.log。 如果在此过程中引发了任何异常,请通过在“服务器”面板中单击服务器并选择“ 重新启动服务器”图标(两个相对的箭头)来重新启动服务器 。 启动服务器和部署项目可能需要几分钟,因此请耐心等待。

服务器现在应该正在运行(在“服务器”视图中由started状态指示),并且已部署项目,可以进行测试。 调用中介之前的最后一件事-打开服务器中的额外日志记录详细信息以生成有关调用期间发生的情况的详细报告:

  1. 将Web浏览器指向http:// localhost:9060 / ibm / console /,将您带到WebSphere ESB管理控制台的登录页面-WebSphere WebB GUI界面,用于配置WebSphere ESB服务器的运行实例:
    图4.2。 WebSphere ESB管理控制台“登录”面板
    图4.2。 WebSphere ESB管理控制台“登录”面板
  2. 单击登录 ,然后从任务过滤选择器列表中选择服务器和总线 ,然后单击应用
    图4.3。 在管理控制台中选择任务过滤器
    图4.3。在管理控制台中选择任务过滤器
  3. 展开左侧菜单中的“疑难解答”菜单,然后选择“ 日志和跟踪”
  4. 在新面板中,选择server1
  5. 在这里,您可以调整历史副本的大小和数量,以保存生成的各种服务器日志文件。 目前,我们仅对调整记录到跟踪文件的详细程度感兴趣,因此请单击“ 更改日志详细程度”
  6. 在此新页面的文本框中,输入*=info:com.ibm.ws.sibx.*=fine ,然后单击确定并保存更改。
  7. 要获取这些更改,请重新启动服务器:返回WebSphere Integration Developer,访问“ 服务器”视图,然后单击“ 重新启动服务器”图标。

现在,您已将服务器配置为使用非常详细的日志记录形式,该日志记录输出在中介流中每个组件的入口和出口点通过中介模块传递的消息的全部内容。 。 尽管这是一个出色的初始调试工具,但是由于性能开销和冗长的日志文件,您通常不会将其用于商业部署的应用程序。

通过通用测试环境(UTE)调用

UTE提供了一个接口,可以通过中介模块中特定组件上的特定操作直接调用流:

  1. 在左侧的Business Integration Navigator中,右键单击StockQuoteMediation项目,然后选择Test => Test Module
  2. 将打开一个新的编辑器,显示与所选中介模块关联的界面提供的各种调用选项。 接受缺省值,然后输入IBM作为名称值,如下图4.4所示。 单击继续以启动测试客户端。
    图4.4。 初始UTE面板,输入了IBM输入值
    图4.4。初始UTE面板,输入了IBM输入值
  3. 在“部署位置”弹出窗口中,展开WebSphere ESB Server V6位置,选择基础的localhost服务器,然后单击“ 完成”
  4. 客户端现在将开始运行-首先启动服务器,然后发布测试客户端,并使用它通过指定的输入参数IBM来访问StockQuoteMediation模块。 As shown in Figure 4.5 below, the UTE displays the route taken by the message between mediation modules, together with the final result -- in this case, the expected price of 100.0:
    Figure 4.5. UTE panel following invocation of getQuote operation with input IBM
    Figure 4.5. UTE panel following invocation of getQuote operation with input IBM
  5. Repeat the service invocation using the Invoke icon (first icon in the palette at top right of editor). Enter values such as IBMold and xxx to verify the expected results -- 80.0 and null , respectively.

Further checking of output logging

Whilst the previous section verified that the flows work as expected, using the UTE alone gives little detail about what is actually happening to messages during flow invocation. There are two ways to obtain this such information: checking the SystemOut log file, and checking the Message Logger default database.

Checking the SystemOut log file

As mentioned previously, WebSphere ESB outputs its system logging information by default to <ESB-install-directory>\profilesESB01\logs\server1\SystemOut.log. Open this file and examine the contents, concentrating on the end of the file where the output from the UTE test runs is stored. Thanks to the detailed logging specified in the previous section, "Setting up the test environment," the full messages will be printed at the entry and exit point of each mediation primitive. For example, Listing 2 below shows the information logged at the point of exit from the XSL Transformation primitive, with an input name value of IBM :

Listing 2. Sample content of the WebSphere ESB SystemOut.log file, illustrating a typical message content, with important features highlighted
[26/01/06 11:46:34:430 GMT] 00000058 SystemOut     O 
++++++++++++++++++++++++++++++++++++++++
ProcessMessage
Flow metadata   :
    Port type   : {http://StockQuoteLibrary/StockQuoteService}StockQuoteService
    Operation   : getQuote	--> invoked operation
    Interaction : Request	--> direction of mediation flow
    Component   : com.ibm.ws.sca.internal.scdl.impl.ManagedComponentImpl@2db851d4 (description: null) 
    		(displayName: StockQuoteMediationMediation) (name: StockQuoteMediationMediation)
Node name        : XSLTransformation1	--> current mediation primitive
Node name        : XSLTransformation1
Node display name: XSLTransformation1
Node type (class): com.ibm.ws.sibx.mediation.primitives.xslt.XSLTMediation
Node properties  : {XSLTransform=xslt/XSLTransformation1_req_1.xsl, root=/body, 
		associatedXSL=xslt/XSLTransformation1_req_1.xsl, sibxMayChangeMessage=true, 
		XMXMap=xslt/XSLTransformation1_req_1.xmx, validateInput=false}
Terminal name    : out
Terminal type    : Output	--> current mediation terminal
Message          : com.ibm.ws.sibx.smobo.impl.ServiceMessageObjectImpl@9511ec 
		{ <?xml version="1.0" encoding="UTF-8"?>
<smo:smo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xmlns:service="http://StockQuoteLibrary/StockQuoteService" 
		xmlns:smo="http://www.ibm.com/websphere/sibx/smo/v6.0.1">
  <context/>
  <headers>
    <SMOHeader>	--> message header information
      <MessageUUID>fe498906-0901-0000-0080-91d5c1b505a5</MessageUUID>
      <Version>
        <Version>6</Version>
        <Release>0</Release>
        <Modification>1</Modification>
      </Version>
      <MessageType>Request</MessageType>
    </SMOHeader>
  </headers>
  <body xsi:type="service:getQuoteRequestMsg">
    <getQuote>
      <inputGetQuote>
        <name>IBMvetted</name>	
        		--> actual message body content -- with 'vetted' appended as expected
      </inputGetQuote>
    </getQuote>
  </body>
</smo:smo> }

As mentioned earlier, the same information is available from the WebSphere Integration Developer Console, but it has a small buffer size (which can be adjusted in the Preferences settings) and therefore the SystemOut.log file is usually used in problem diagnosis. Also, in addition to logging the content of the output messages, the log file contains any output logging from Java code run on the server and written to System.out. Check for the output generated by the service implementation, StockQuoteServiceImpl.java .

Checking the Message Logger default database

The mediation flows defined here use several Message Logger primitives, whose function is to write the contents of messages passing through to a specified database. In deploying these primitives, we used the default Cloudscape database. To access it:

  1. Access the Servers view and stop the server, since whilst running, it holds a lock on the Cloudscape database.
  2. Run <ESB install directory>\cloudscape\bin\embedded\cview.bat to access a GUI interface to the database.
  3. Select File => Open and select <ESB install directory>\profiles\ESB01\databases\EsbLogMedDB in the browser window.
  4. Expand Tables in the side menu and click MSGLOG , which is the default table used to store the message contents.
  5. Click on the Data tab in the right-hand panel. It gives access to the full information logged, including when and where (both primitive and module name) the message was logged, as well as the message content itself. Since the table is quite small, use the Text Editor icon to display the full message information in another editor, as shown in Figure 4.6 below. Since we chose the default Message Logger settings, only the message body is logged in this database table. Compare it to the contents of SystemOut.log to clarify the difference:
    Figure 4.6. Contents of Message Logger DB table, showing contents of a typical message logged
    Figure 4.6. Contents of Message Logger DB table, showing contents of a typical message logged

Creating and running via a JSP

Now that we've demonstrated that the mediation modules work as expected, we can put together a Web based front-end to the service using a JSP. (If you need more information on JSP technology, see Related topics below.)

To start with, we need to add a reference to the mediation module to act as an input point for the JSP:

  1. Open the Assembly Diagram Editor for the StockQuoteMediation module.
  2. From the icon palette on the left side of the editor, expand the green arrow icon and select the blue arrow icon (Stand-alone References).
  3. Add this component to the editor canvas and wire it to the StockQuoteMediationMediation component, choosing No in the Add Wire window. The editor should now look like this:
    Figure 4.7. Assembly Diagram for StockQuoteMediation module with stand-alone reference added
    Figure 4.7. Assembly Diagram for StockQuoteMediation module with stand-alone reference added
  4. Save the changes and hover the mouse over the new reference name (the 1..1 icon) to display its name. The name ( StockQuoteServicePartner ) acts as the entry point to the flow and will be used by the JSP below.

Now that a valid reference has been set up to act as an entry point to the flow, define an appropriate JSP:

  1. In the Business Integration Navigator, right-click on StockQuoteMediation and select New => Other .
  2. In the New window, expand Web (check the Show All Wizards check box if this option is not initially available), click JSP File , and then click Next .
  3. Click Browse and expand StockQuoteMediationWeb in the new window. Select the underlying WebContent folder, which is where the JSP file will be stored to make it available to Web browsers.
  4. Back in the New JSP File pop-up window, enter invokeStockQuoteService as the JSP name:
    Figure 4.8. Completed New JSP File wizard
    Figure 4.8. Completed New JSP File wizard
  5. 点击完成 。 WebSphere Integration Developer generates a basic skeleton for this file and opens it in a JSP editor, with three tabs below the main pane: Design, Source, and Preview:
    Figure 4.9. JSP Editor with basic code skeleton displayed
    Figure 4.9. JSP Editor with basic code skeleton displayed
  6. Select the Source tab and replace the existing template with the following code:
    Listing 3. Code for the invokeStockQuoteService JSP
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    
    <HTML>
    <HEAD>
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
        <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <META name="GENERATOR" content="IBM Software Development Platform">
        <META http-equiv="Content-Style-Type" content="text/css">
        <LINK href="theme/Master.css" rel="stylesheet"
        type="text/css">
        <TITLE>invokeStockQuoteService.jsp</TITLE>
    </HEAD>
    
    <BODY>
    
    <%@ page import="com.ibm.websphere.sca.ServiceManager" %>
    <%@ page import="com.ibm.websphere.sca.Service" %>
    <%@ page import="commonj.sdo.DataObject" %>
    <%@ page import="com.ibm.websphere.bo.BOFactory" %>
    <%@ page import="com.ibm.websphere.sca.ServiceBusinessException;" %>
    
    <H1 align="center">StockQuote Application</H1>
    <form action="invokeStockQuoteService.jsp" method="get">
            
    <TABLE border="0" cellpadding="5" cellspacing="0">
       <TBODY>
          <TR>
             <TD>Enter a StockQuote name (e.g. IBM): </TD>
             <TD><INPUT type="text" name="name" size="30" maxlength="30"></TD>
          </TR>
       </TBODY>
    </TABLE>
    <P><INPUT type="submit" name="Submit" value="Submit"></P>
    
    </form>
    
    <%
    System.out.println("Client accessed");
    System.out.println("invokeStockQuoteService.jsp : Check for name");
    
    // retrieve name value input in HTML text box
    String name = request.getParameter("name");	
    String ref = "StockQuoteServicePartner";	
    if (name != null) {
    
       System.out.println("invokeStockQuoteService.jsp : 
             Retrieved stockquote name: " + name + " from browser");
    
       // now attempt to invoke the StockQuote mediation flow
       try {
    
          // First retrieve an instance of the service to invoke
          ServiceManager serviceManager = new ServiceManager();
          Service service = (Service) serviceManager.locateService(ref);
    		
          // Locate the BOFactory via its 'well known' location name
          // com/ibm/websphere/bo/BOFactor
          // this is used to generate a Business Object -- the data structure used by
          // the message passed to the mediation flow 
          System.out.println("invokeStockQuoteService.jsp : Locating BOFactory");		
          BOFactory bofactory = 
                (BOFactory) serviceManager.locateService("com/ibm/websphere/bo/BOFactory");
    		
          // Use BOFactory with  service interface to create a correctly formatted input message
          System.out.println("invokeStockQuoteService.jsp : Get message getQuote");
          DataObject getQuote = 
                bofactory.createByElement("http://StockQuoteLibrary/StockQuoteService", "getQuote");
    		
          // Now get hold of necessary part of this input message and add the value input at browser
          System.out.println("invokeStockQuoteService.jsp : Get input parameter inputGetQuote");
          DataObject inputGetQuote = getQuote.createDataObject("inputGetQuote");
    		
          System.out.println("invokeStockQuoteService.jsp : Set inputGetQuote::name = " + name);
          inputGetQuote.setString("name", name);
    
          DataObject getQuoteResponse = null;
    		
          try {
      
             // Now invoke the operation 'getQuote' operation - note, the 'getQuoteResponse'
             // object represents the returned message
             System.out.println("invokeStockQuoteService.jsp : Invoke getQuote with " + name);
             getQuoteResponse = (DataObject)service.invoke("getQuote", inputGetQuote);
    
             // Retrieve the output, using the format specified in the interface
             System.out.println("invokeStockQuoteService.jsp : Retrieving the outputGetQuote");
             DataObject outputGetQuote = getQuoteResponse.getDataObject("outputGetQuote");
    			
             if (outputGetQuote == null) {
                out.println("No message returned - this may be due to the " +
                   "flow encountering a Stop or Fail mediation primitive.");
             } else {
                System.out.println("invokeStockQuoteService.jsp : Retrieving the price");
                float result = outputGetQuote.getFloat("price");
                System.out.println("invokeStockQuoteService.jsp : 
                      outputGetQuote::price = " + result);				
                // Finally print the return value to the browser page
                out.println("<p>" + name + " stock price: " + result + "</p>");
             }
    
          } catch (ServiceBusinessException sbe) {
    		
             out.println("invokeStockQuoteService.jsp : 
                   ServiceBusinessException caught - content as follows:</br>");
             out.println("invokeStockQuoteService.jsp : " + sbe.getMessage() + "</br>");
          }
    
       } catch (Exception e) {
          System.out.println(e);
       }
    }
    %>    
    </BODY>
    </HTML>

    The ref variable in the code, used to look up the service to invoke, has been set to the value of the reference displayed in the Assembly Diagram for the StockQuoteMediation module , as shown in Figure 4.7. The logging out.println is directed to the Web browser where the page generated by the JSP is displayed, whereas the logging to System.out.println is directed to the WebSphere ESB SystemOut log.

  7. Save the changes and close the JSP editor.

The JSP is stored in the StockQuoteMediation module, so you need to redeploy it to the server in order for the changes to be picked up: access the Servers view, right-click on the localhost server instance, and select Restart Project => StockQuoteMediation .

Once the project has been restarted, check the Console output for errors, open a Web browser, and enter the URL:

http://localhost:9080/StockQuoteMediationWeb/invokeStockQuoteService.jsp

It will load a Web page that looks like this:

Figure 4.10. StockQuoteService JSP Web page, with results for IBM StockQuote input
Figure 4.10. StockQuoteService JSP Web page, with results for IBM StockQuote input

As in the UTE section, experiment with different input values for the StockQuote name and verify that the expected response is returned. In particular, enter a name outside of the expected values IBM and IBMold, and check the SystemOut logging to verify that the alternative mediation route has been taken.

结论

In this article we have developed and deployed a Web-based service and mediation flow using WebSphere Enterprise Service Bus and WebSphere Integration Developer. In particular, we have:

  1. Developed a simple Java-based Web service, providing a basic StockQuote service.
  2. Developed a mediation flow to connect to this service, with logic to route requests to different destinations depending on their message payload.
  3. Deployed these projects to a running instance of WebSphere ESB server and invoked them using both the provided test environment and a stand-alone JSP front-end.
  4. Explored the available output logging facilities.

I hope that this fairly simple example has provided a useful introduction to the extensive capabilities of WebSphere Enterprise Service Bus and WebSphere Integration Developer.

致谢

The author would like to thank Chris Markes of IBM for his help in developing this article.


翻译自: https://www.ibm.com/developerworks/websphere/library/techarticles/0602_byrom/0602_byrom.html

websphere

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值