如何在不创建* .JcoDestination文件的情况下使用JCo连接
我正在尝试使用JCo连接到SAP ECC 6.0.我正在关注
this教程.但是,有一个注释说:
For this example the destination configuration is stored in a file that is called by the program. In practice you should avoid this for security reasons. 这是合理的,也是理解的.但是,没有说明如何设置安全目标提供程序. 这是我的代码,以进一步澄清我正在尝试做什么. public static void main(String... args) throws JCoException { CustomDestinationProviderMap provider = new CustomDestinationProviderMap(); com.sap.conn.jco.ext.Environment.registerDestinationDataProvider(provider); Properties connectProperties = new Properties(); connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST,"host.sap.my.domain.com"); connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR,"00"); connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT,"100"); connectProperties.setProperty(DestinationDataProvider.JCO_USER,"user"); connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD,"password"); connectProperties.setProperty(DestinationDataProvider.JCO_LANG,"en"); provider.addDestination(DESTINATION_NAME1,connectProperties); connect(); } public static void connect() throws JCoException { String FUNCTION_NAME = "BAPI_EMPLOYEE_GETDATA"; JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME1); JCoContext.begin(destination); JCoFunction function = destination.getRepository().getFunction(FUNCTION_NAME); if (function == null) { throw new RuntimeException(FUNCTION_NAME + " not found in SAP."); } //function.getImportParameterList().setValue("EMPLOYEE_ID","48"); function.getImportParameterList().setValue("FSTNAME_M","ANAKIN"); function.getImportParameterList().setValue("LASTNAME_M","SKYWALKER"); try { function.execute(destination); } catch (AbapException e) { System.out.println(e.toString()); return; } JCoTable table = function.getTableParameterList().getTable("PERSONAL_DATA"); for (int i = 0; i < table.getNumRows(); i++) { table.setRow(i); System.out.println(table.getString("PERNO") + 't' + table.getString("FIRSTNAME") + 't' + table.getString("LAST_NAME") +'t' + table.getString("BIRTHDATE")+'t' + table.getString("GENDER")); } JCoContext.end(destination); } 解决方法
好的,所以我得到了这个,并且认为我会分享我的研究.
您需要在Portal中添加自己的目标.为此,您需要访问NetWeaver Administrator,位于:host:port / nwa.所以它会像sapportal.your.domain.com:50000/nwa. 然后你去配置 – >基础设施 – >目的地并在那里添加您的目的地.您可以将大多数字段留空,如Message Server.重要的部分是目标名称,因为它是如何检索它和目标类型,在我的情况下应该设置为RFC目标.尝试ping新创建的目标,以检查其是否正常运行. 最后,你应该能够通过简单地调用来获取目的地:JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME);因为它被添加到您的Portal环境并从那里进行管理. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |