日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

JCO 自定义DestinationDataProvider

發布時間:2023/12/13 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JCO 自定义DestinationDataProvider 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

  要讓JAVA程序能訪問SAP系統,一般通過SAP JCO接口進行通訊,在獲取到SAP的連接時需求提供一些連接參數,這些參數在最新的 JCO 3.0 中需要被保存到一個帶有擴展名.jcoDestination的文件中,這個文件同時被保存在應用程序的安裝目錄中。因為這只中一個純文本文件,所有的連接參數并沒有被加密,這樣對于公用程序可能有安全問題。要使用登陸連接更加安全可以實現自定義的 DestinationDataProvider 實現:
此接口只有簡單的三個方法:

interface DestinationDataProvider {Properties getDestinationProperties(java.lang.String destinationName);void setDestinationDataEventListener(DestinationDataEventListener eventListener);boolean supportsEvents(); }

getDestinationProperties 當Java程序獲取到SAP的連接時,jco會從這里讀取連接屬性,你可以編程動態的設定這些屬性
setDestinationDataEventListener 設置一個連接事件監聽器,實現一個監聽器,當JCO連接SAP以獲得通知
supportsEvents 返回是否被實現的DestinationDataProvider有事件監聽器

實現一個自定義Provider:

static class MyDestinationDataProvider implements DestinationDataProvider{private DestinationDataEventListener eL;private Properties ABAP_AS_properties; public Properties getDestinationProperties(String destinationName){if(destinationName.equals("ABAP_AS") && ABAP_AS_properties!=null)return ABAP_AS_properties;return null;//alternatively throw runtime exception//throw new RuntimeException("Destination " + destinationName + " is not available"); }public void setDestinationDataEventListener(DestinationDataEventListener eventListener){this.eL = eventListener;}public boolean supportsEvents(){return true;}void changePropertiesForABAP_AS(Properties properties){if(properties==null){eL.deleted("ABAP_AS");ABAP_AS_properties = null;}else {if(ABAP_AS_properties!=null && !ABAP_AS_properties.equals(properties))eL.updated("ABAP_AS");ABAP_AS_properties = properties;}}}

測試連接:

public static void main(String[] args) throws Exception{Properties connectProperties = new Properties();connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "binmain");connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "53");connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "000");connectProperties.setProperty(DestinationDataProvider.JCO_USER, "JCOTEST");connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "JCOTEST");connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "en");MyDestinationDataProvider myProvider = new MyDestinationDataProvider();com.sap.conn.jco.ext.Environment.registerDestinationDataProvider(myProvider);myProvider.changePropertiesForABAP_AS(connectProperties);JCoDestination ABAP_AS = JCoDestinationManager.getDestination("ABAP_AS");ABAP_AS.ping();System.out.println("ABAP_AS destination is ok");}

?

轉載于:https://www.cnblogs.com/rinack/p/8041582.html

總結

以上是生活随笔為你收集整理的JCO 自定义DestinationDataProvider的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。