定義 z/OS Connect 訊息有效負載轉換

藉由 IBM® z/OS® Connect,您能夠選擇性地轉換要求和回應有效負載,以用於呼叫 z/OS 作業系統上的商業資產。您可以實作 z/OS Connect 隨附的 com.ibm.wsspi.zos.connect.DataXform 服務提供者介面 (SPI),來建立訊息有效負載轉換器,以滿足特定的需求。

關於這項作業

z/OS Connect 所提供的實作需要 JSON 格式的要求和回應訊息。這項特性支援將要求轉換成位元組陣列,以供原生語言 Cobol、PL/I 或 C 結構對映。利用 z/OS Connect 提供的公用程式,會使用目標程式或記錄定義檔的這種語言結構(包括 inout 參數的說明),來產生連結檔及 JSON 要求和回應綱目檔。這個公用程式產生的連結檔,供 z/OS Connect 在要求送達及回應傳回時,用來完成 JSON 與原生資料格式之間的資料轉換。您可以使用 z/OS Connect 提供的 REST API 呼叫,來擷取要求和回應訊息的 JSON 綱目。

z/OS Connect 會提供 zosConnectService 配置元素,可讓管理者配置一組屬性,來套用至特定的服務。其中有一個屬性是 dataXformRef,它會指向一個要用於特定服務的資料轉換配置。這項作業說明如何要求使用 z/OS Connect 提供的資料轉換器。

程序

  1. server.xml 檔中定義 zosConnectDataXform 元素。
    <!-- z/OS Connect data transformation provider -->
    <zosConnectDataXform id="zosConnectXform"
    	bindFileLoc="/zosConnect/banking/bind/" 
            bindFileSuffix=".bnd"   
            requestSchemaLoc="/zosConnect/banking/reqSchema" 
            requestSchemaSuffix=".json"
    	responseSchemaLoc="/zosConnect/banking/respSchema" 
            responseSchemaSuffix=".json"/>  

    使用這個範例,為完整起見,已指定檔案位置相關的所有屬性定義,例如 bindFileLocrequestSchemaLocresponseSchemaLoc。 只有 bindFileLocrequestSchemaLoc 是必要的屬性定義。 如果未配置 responseSchemaLoc 屬性,則會使用 requestSchemaLoc 屬性的值。

    使用相同的範例,為完整見起,已指定字尾相關的所有屬性定義,例如 <bindFileSuffix><requestSchemaSuffix><responseSchemaSuffix>。 全部都是選用的。如果未指定,則 z/OS Connect 載入的連結檔和綱目檔不會有字尾。

    z/OS Connect 所需的資料轉換相關檔案要有符合配置的特定格式。
    • 連結檔:<serviceName><bindFileSuffix>
    • 要求綱目檔:<serviceName>_request<requestSchemaSuffix>
    • 回應綱目檔:<serviceName>_response<requestSchemaSuffix>
    使用下列 zosConnectService 配置範例及前一個 zosConnectDataXform 配置範例。
    <!-- z/OS Connect service definition -->
    <zosConnectService id="zosConnectCustomer" 
    	serviceName="customer" 
    	serviceRef="wolaCustomerCreate" 
    	dataXformRef="zosConnectXform"/> 
    資料轉換檔案的名稱如下:
    • 連結檔:customer.bnd
    • 要求綱目檔:customer_request.json
    • 回應綱目檔:customer_response.json

    如需 zosConnectDataXform 元素相關聯的可配置屬性定義的相關資訊,請參閱 z/OS Connect 特性的相關說明文件。

  2. 針對 server.xml 配置中您要啟用 z/OS Connect 提供之資料轉換的每一項服務,更新 zosConnectService 元素。
    <!-- z/OS Connect service definition -->
    <zosConnectService id="zosConnectCustomer" 
    	serviceName="customer" 
    	serviceRef="wolaCustomerCreate" 
    	dataXformRef="zosConnectXform"/> 
  3. 選用:配置一個要套用至所有服務的資料轉換器。zosConnectManager 元素的 globaDataXformRef 設定為所配置的資料轉換器 ID,這個 ID 是要供廣域使用的。如果同時定義了廣域和服務的資料轉換器,當服務的要求與所配置的資料轉換器一起送入時,z/OS Connect 會使用專為該服務所配置的資料轉換器。
    <zosConnectManager id="zosConnectGlobalDefinitions
            globalDataXformRef="zosConnectGlobalDataXform"/>   
    
    <!-- z/OS Connect data transformation provider -->
    <zosConnectDataXform id="globalDataXform" 
    	bindFileLoc="/zosConnect/banking/bind/"
            bindFileSuffix=".bnd"   
            requestSchemaLoc="/zosConnect/banking/reqSchema"
            requestSchemaSuffix=".json"
            responseSchemaLoc="/zosConnect/banking/respSchema"
            responseSchemaSuffix=".json"/>      
  4. 選用:配置 pollingRateupdateTrigger 之類的設定,以細部調整監視動作。 依預設,會監視與資料轉換定義相關聯的目錄,看看是否有新檔案與檔案更新。如需這些配置屬性的相關資訊,請參閱 z/OS Connect 1.0z/OS Connect 1.2 之下的 zosConnectDataXform 元素區段。
    <zosConnectDataXform id="globalDataXform" 
            bindFileLoc="/zosConnect/banking/bind/"
            bindFileSuffix=".bnd"   
            requestSchemaLoc="/zosConnect/banking/reqSchema"
            requestSchemaSuffix=".json"
            responseSchemaLoc="/zosConnect/banking/respSchema"
            responseSchemaSuffix=".json"
            pollingRate="500ms"> 
    </zosConnectDataForm>      

    在範例中,每隔 500 毫秒,就會輪詢 /zosConnect/banking/bind,/zosConnect/banking/reqSchema/zosConnect/banking/respSchema 目錄中是否有檔案更新。如果沒有配置 pollingRateupdateTrigger 配置屬性,會分別使用預設值 polled2 seconds。如果您不需要監視檔案,可以將 updateTrigger 屬性設為 disabled 來停用它。如果您偏好觸發手動重新整理特定的檔案,請將 updateTrigger 屬性設為 mbean,並使用檔案通知 MBean com.ibm.ws.kernel.filemonitor.FileNotificationMBean,來觸發更新;例如:

    String[] MBEAN_METHOD_SIGNATURE = new String[] {Collection.class.getName(),Collection.class.getName(),Collection.class.getName() };        
    JMXConnector jmxConnector = ...;        
    MBeanServerConnection mbsc = jmxConnector.getMBeanServerConnection();        
    ObjectName fileMonitorMBeanName = new ObjectName("WebSphere:service=com.ibm.ws.kernel.filemonitor.FileNotificationMBean");        
    
    List<String> paths = new ArrayList<String>();        
    paths.add("/zosConnect/banking/bind/customer.bnd");        
    paths.add("/zosConnect/banking/reqSchema/customer_request.json");       
    paths.add("/zosConnect/banking/respSchema/customer_response.json");        
    
    Object[] params = new Object[] { null, paths, null };        
    mbsc.invoke(fileMonitorMBeanName, "notifyFileChanges", params, MBEAN_METHOD_SIGNATURE);

    此範例使用 restConnector-1.0 特性來觸發 customer.bndcustomer_request.jsoncustomer_response.json 檔的更新。如需如何建立安全 JMX 連線的相關資訊,請參閱配置通往 Liberty 的安全 JMX 連線相關說明文件。


指示主題類型的圖示 作業主題

檔名:twlp_zconnect_msg_payload_conv.html