Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. static class MyDestinationDataProvider implements DestinationDataProvider {
  2. private DestinationDataEventListener eL;
  3. private HashMap<String, Properties> secureDBStorage = new HashMap<String, Properties>();
  4.  
  5. public Properties getDestinationProperties(String ABAP_AS) {
  6. try {
  7. //read the destination from DB
  8. Properties p = secureDBStorage.get(ABAP_AS);
  9.  
  10. if(p!=null) {
  11. //check if all is correct, for example
  12. if(p.isEmpty())
  13. throw new DataProviderException(DataProviderException.Reason.INVALID_CONFIGURATION, "destination configuration is incorrect", null);
  14.  
  15. return p;
  16. }
  17.  
  18. return null;
  19. } catch(RuntimeException re) {
  20. throw new DataProviderException(DataProviderException.Reason.INTERNAL_ERROR, re);
  21. }
  22. }
  23.  
  24. //An implementation supporting events has to retain the eventListener instance provided
  25. //by the JCo runtime. This listener instance shall be used to notify the JCo runtime
  26. //about all changes in destination configurations.
  27. public void setDestinationDataEventListener(DestinationDataEventListener eventListener) {
  28. this.eL = eventListener;
  29. }
  30.  
  31. public boolean supportsEvents() {
  32. return true;
  33. }
  34.  
  35. //implementation that saves the properties in a very secure way
  36. void changeProperties(String ABAP_AS, Properties properties) {
  37. synchronized(secureDBStorage) {
  38. if(properties==null) {
  39. if(secureDBStorage.remove(ABAP_AS)!=null)
  40. eL.deleted(ABAP_AS);
  41. } else {
  42. secureDBStorage.put(ABAP_AS, properties);
  43. eL.updated(ABAP_AS); // create or updated
  44. }
  45. }
  46. }
  47. } // end of MyDestinationDataProvider
  48.  
  49. //business logic
  50. void executeCalls(String ABAP_AS) {
  51. JCoDestination dest;
  52. try {
  53. dest = JCoDestinationManager.getDestination(ABAP_AS);
  54. dest.ping();
  55. System.out.println("Destination " + ABAP_AS + " works");
  56. } catch(JCoException e) {
  57. e.printStackTrace();
  58. System.out.println("Execution on destination " + ABAP_AS + " failed");
  59. }
  60. }
  61.  
  62. static Properties getDestinationPropertiesFromUI() {
  63. //adapt parameters in order to configure a valid destination
  64. Properties connectProperties = new Properties();
  65. connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "XXX");
  66. connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "XX");
  67. connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "XXX");
  68. connectProperties.setProperty(DestinationDataProvider.JCO_USER, "XXX");
  69. connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "XXX");
  70. connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "XX");
  71. createDestinationDataFile(ABAP_AS, connectProperties);
  72. return connectProperties;
  73. }
  74.  
  75. static void createDestinationDataFile(String ABAP_AS, Properties connectProperties) {
  76. File destCfg = new File(ABAP_AS + ".jcoDestination");
  77. try {
  78. FileOutputStream fos = new FileOutputStream(destCfg, false);
  79. connectProperties.store(fos, "for tests only!");
  80. fos.close();
  81. } catch (Exception e) {
  82. throw new RuntimeException("Unable to create the destination files", e);
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement