I'm working on a Java application that will connect to SAP, with the destination configuration coming from a file, and the user and password being entered at run time. I'm trying to implement this using the createCustomDestination() method on the JCoDestination.
Here is some sample code of how I am trying to do this. There is also a test.jcoDestination file that contains only the connection information; no user name, password, or client.
import com.sap.conn.jco.JCoCustomDestination; import com.sap.conn.jco.JCoDestination; import com.sap.conn.jco.JCoDestinationManager; import com.sap.conn.jco.JCoException; import com.sap.conn.jco.JCoRepository; import com.sap.conn.jco.JCoCustomDestination.UserData; public class Test { /** * @param args */ public static void main(String[] args) { try { JCoDestination destination = JCoDestinationManager.getDestination("test"); JCoCustomDestination customDestination = destination.createCustomDestination(); UserData userData = customDestination.getUserLogonData(); System.console().printf("Enter client:"); userData.setClient(System.console().readLine()); System.console().printf("Enter user:"); userData.setUser(System.console().readLine()); System.console().printf("Enter password:"); userData.setPassword(new String(System.console().readPassword())); System.console().printf("Enter language:"); userData.setLanguage(System.console().readLine()); // Try to connect - this works customDestination.ping(); // Try to connect to the repository - this fails JCoRepository repository = customDestination.getRepository(); } catch (JCoException e) { e.printStackTrace(); } } }
Everything works well down through the ping() call, which means the connection is being created. However, on the getRepository() call I get an exception saying that the client isn't specified. It's as if the getRepository method is ignoring the custom destination information I set and only looking at what's in the destination file.
Am I doing something wrong, or is this a bug in the JCo library?
Thanks,
Jonathan