I want to access an RFC function on sap from my java program.
When I call getDestination("connect") I can connect and run my function without problems.
But I will have more than one config file because I will be connecting to different SAP servers.
I want to collect all of these files in one folder, but when I write getDestination("src/JcoDestinations/connect") it does not read my config file that I put in the folder and does not connect.
How do I get all my connect jcoDestination config files together and run?
The error I get is this :
(106) JCO_ERROR_RESOURCE: Destination 'connect' does not exist. –
I tried:
File file = new File("src/JcoDestinations/connect");
JCoDestination destination = JCoDestinationManager.getDestination(file.toString());
and:
File file = new File("C:\\connect");
JCoDestination destination = JCoDestinationManager.getDestination(file.toString());
these did not work for me.
you can define a Custom DestinationDataProvider to hold more than one Connection Profile. We dont use Property - Files here ,but I think this example should work.
Here a DataProvider to hold different Property Files, stored in a HashMap. The method JCoDestinationManager.getDestination calls the method getDestinationProperties inside the DataProvider and expects to get a Properties Object back. The method addConnectionProperties adds new Properties Objects to the HashMap.
Here you can also implement a method to read one big Property file. But I'm too lazy for that ;)
Here an example
Then register the provider in your main programm
Now read all your property files from disk and place the files in the Custom DestinationDataProvider.
Now you have 2 connections. You can access the connections via JCoDestinationManager.getDestination.
I never tried it, cause i use an external database to build up the Propertie Objects, but i think it should work. Let me know, how it works ;)