From c0c720ac8c73a42482f48fe44a2176f24ba2ac03 Mon Sep 17 00:00:00 2001 From: AlejandroP Date: Tue, 20 Jul 2021 19:26:56 -0300 Subject: [PATCH 1/4] Issue: 90257 Document Management support for SAP ERP/Java (Download Only) --- .../com/genexus/sap/DestinationProvider.java | 76 ++++++- .../java/com/genexus/sap/DocumentClient.java | 95 +++++++++ .../com/genexus/sap/EnterpriseConnect.java | 19 +- .../java/com/genexus/sap/SessionManager.java | 187 +++++++++++++++--- 4 files changed, 341 insertions(+), 36 deletions(-) create mode 100644 java/src/main/java/com/genexus/sap/DocumentClient.java diff --git a/java/src/main/java/com/genexus/sap/DestinationProvider.java b/java/src/main/java/com/genexus/sap/DestinationProvider.java index 7fd6e6fd2..c77791990 100644 --- a/java/src/main/java/com/genexus/sap/DestinationProvider.java +++ b/java/src/main/java/com/genexus/sap/DestinationProvider.java @@ -6,9 +6,13 @@ import com.genexus.diagnostics.Log; import com.sap.conn.jco.ext.DestinationDataEventListener; import com.sap.conn.jco.ext.DestinationDataProvider; +import com.sap.conn.jco.ext.ServerDataEventListener; +import com.sap.conn.jco.ext.ServerDataProvider; import com.sap.conn.jco.ext.Environment; -public class DestinationProvider implements DestinationDataProvider + + +public class DestinationProvider implements DestinationDataProvider, ServerDataProvider { private static DestinationProvider _instance; @@ -23,6 +27,7 @@ public static DestinationProvider Instance() } private String SAP_SERVER = "SAP_SERVER"; + private String SAP_DOC_SERVER = "DMS_SERVER"; private Properties connectionProperties; private Hashtable connectionList = new Hashtable(); private DestinationDataEventListener eventListener; @@ -61,6 +66,75 @@ public void setDestinationDataEventListener(DestinationDataEventListener eventLi this.eventListener = eventListener; } + @Override + public Properties getServerProperties(String serverName) { + if (serverName != null) + { + Properties val = connectionList.get(serverName); + if (val != null) + { + return val; + } + else + { + return null; + } + } + else + { + return null; + } + } + + @Override + public void setServerDataEventListener(ServerDataEventListener arg0) { + // Our logon parameters don't change dynamically, so we don't need to fire events. See above comment on DestinationDataEventListener. + } + + + public void removeServerProperties(String serverName) + { + if (eventListener != null) + { + eventListener.deleted(serverName); + } + connectionProperties = null; + connectionList.remove(serverName); + } + + public void setServerProperties( String serverName, Properties properties) + { + if ( serverName == null || serverName.equals("")) + { + serverName = SAP_DOC_SERVER; + + } + if (!Environment.isServerDataProviderRegistered()) + { + Environment.registerServerDataProvider(this); + } + if (properties == null) + { + if (eventListener != null) + { + eventListener.deleted( serverName); + } + connectionProperties = null; + connectionList.remove( serverName); + } + else + { + Log.info("GX SAP Doc Server - Setting Properties : " + serverName + " total : " + Integer.toString(connectionList.size())); + connectionProperties = properties; + connectionList.put( serverName, connectionProperties); + if (eventListener != null) + { + eventListener.updated(serverName); + } + } + } + + public void removeConnectionProperties(String sessionName) { if (eventListener != null) diff --git a/java/src/main/java/com/genexus/sap/DocumentClient.java b/java/src/main/java/com/genexus/sap/DocumentClient.java new file mode 100644 index 000000000..6163f021a --- /dev/null +++ b/java/src/main/java/com/genexus/sap/DocumentClient.java @@ -0,0 +1,95 @@ +package com.genexus.sap; + +import java.io.FileOutputStream; +import java.io.IOException; + + +import com.sap.conn.jco.AbapClassException; +import com.sap.conn.jco.AbapException; + +import com.sap.conn.jco.JCoFunction; +import com.sap.conn.jco.JCoParameterList; +import com.sap.conn.jco.JCoTable; +import com.sap.conn.jco.server.JCoServer; +import com.sap.conn.jco.server.JCoServerContext; +import com.sap.conn.jco.server.JCoServerContextInfo; +import com.sap.conn.jco.server.JCoServerErrorListener; +import com.sap.conn.jco.server.JCoServerExceptionListener; + +import com.sap.conn.jco.server.JCoServerFunctionHandler; + +public class DocumentClient { + private static final int BLOB_LENGTH = 1022; + + static class ErrorHandler implements JCoServerErrorListener, JCoServerExceptionListener { + + @Override + public void serverExceptionOccurred(JCoServer server, String connectionID, JCoServerContextInfo serverCtx, Exception error) { + // Technical problem in server connection (network, logon data, etc.) + error.printStackTrace(); + } + + @Override + public void serverErrorOccurred(JCoServer server, String connectionID, JCoServerContextInfo serverCtx, Error error) { + // Technical problem in server connection (out-of-memory, etc.) + error.printStackTrace(); + } + + } + + // BAPI_DOCUMENT_CHECKOUTVIEW2 will send the file data via this function module. + static class FTP_R3_TO_CLIENTHandler implements JCoServerFunctionHandler { + + @Override + public void handleRequest(JCoServerContext serverCtx, JCoFunction function) throws AbapException, AbapClassException { + String fname; + int length; + JCoTable blob; + + // In the case of BAPI_DOCUMENT_CHECKOUTVIEW2, MODE is always binary, so the MODE and TEXT parameters of FTP_R3_TO_CLIENT can be ignored. + JCoParameterList imports = function.getImportParameterList(); + fname = imports.getString("FNAME"); + length = imports.getInt("LENGTH"); + blob = function.getTableParameterList().getTable("BLOB"); + FileOutputStream out = null; + System.out.println( " file handle " + fname); + try { + out = new FileOutputStream(fname); + boolean hasNextRow = false; + if (!blob.isEmpty()){ + hasNextRow = true; + blob.firstRow(); + } + while (length > BLOB_LENGTH){ + if (hasNextRow){ + System.out.println( " write .... " ); + out.write(blob.getByteArray(0), 0, BLOB_LENGTH); + length -= BLOB_LENGTH; + hasNextRow = blob.nextRow(); + } + else throw new IOException("Not enough data in table BLOB ("+String.valueOf(BLOB_LENGTH * blob.getNumRows())+") for requested file size (" + String.valueOf(length) + ")"); + } + if (length > 0){ + if (hasNextRow) out.write(blob.getByteArray(0), 0, length); + else throw new IOException("Not enough data in table BLOB ("+String.valueOf(BLOB_LENGTH * blob.getNumRows())+") for requested file size (" + String.valueOf(length) + ")"); + } + } + catch (IOException e) { + // Unfortunately there is no way of transmitting error details back to SAP, so we better log it here, + // if we want to keep the chance of trouble-shooting later, what exactly went wrong... + e.printStackTrace(); + function.getExportParameterList().setValue("ERROR", 3); + } + finally{ + if (out != null){ + try{ + out.close(); + } + catch (IOException ioe){} + } + } + } + + } + +} \ No newline at end of file diff --git a/java/src/main/java/com/genexus/sap/EnterpriseConnect.java b/java/src/main/java/com/genexus/sap/EnterpriseConnect.java index 034fbde65..f6318a53f 100644 --- a/java/src/main/java/com/genexus/sap/EnterpriseConnect.java +++ b/java/src/main/java/com/genexus/sap/EnterpriseConnect.java @@ -4,7 +4,7 @@ import java.util.Date; import java.util.GregorianCalendar; import java.util.Iterator; - +import java.text.DecimalFormat; import com.genexus.GXSimpleCollection; import com.genexus.ModelContext; import com.genexus.internet.IGxJSONAble; @@ -150,13 +150,22 @@ public void setValue(String parameterName, GXSimpleCollection value, Boolean inO { String key = (String)keys.next(); int jcoType = jTable.getRecordMetaData().getType(key); + //int len = jTable.getRecordMetaData().getLength(key); + int dec = jTable.getRecordMetaData().getDecimals(key); + if( jObj.get(key) instanceof String ) { - jTable.setValue(key, jObj.getString(key)); + if (jcoType == JCoMetaData.TYPE_NUM && dec == 0 ) + { + String sValue = new DecimalFormat("#").format(new BigDecimal(jObj.getString(key))); //"1.2" + jTable.setValue(key, sValue); + } + else { + jTable.setValue(key, jObj.getString(key)); + } } else if (jcoType == JCoMetaData.TYPE_NUM || jcoType == JCoMetaData.TYPE_INT) - { - //System.out.println( key + " : '" + jObj.getLong(key) + "'"); + { jTable.setValue(key, jObj.getLong(key)); } else if (jcoType == JCoMetaData.TYPE_FLOAT || jcoType == JCoMetaData.TYPE_BCD) @@ -165,7 +174,7 @@ else if (jcoType == JCoMetaData.TYPE_FLOAT || jcoType == JCoMetaData.TYPE_BCD) } else if (jcoType == JCoMetaData.TYPE_DATE) { - jTable.setValue(key, jObj.getString(key)); + jTable.setValue(key, jObj.getString(key)); } else if (jcoType == JCoMetaData.TYPE_INT2 || jcoType == JCoMetaData.TYPE_INT1 || jcoType == JCoMetaData.TYPE_BYTE) diff --git a/java/src/main/java/com/genexus/sap/SessionManager.java b/java/src/main/java/com/genexus/sap/SessionManager.java index 3d741b8e9..0f7ffaed1 100644 --- a/java/src/main/java/com/genexus/sap/SessionManager.java +++ b/java/src/main/java/com/genexus/sap/SessionManager.java @@ -11,11 +11,23 @@ import com.sap.conn.jco.JCoDestinationManager; import com.sap.conn.jco.JCoException; import com.sap.conn.jco.JCoFunction; +import com.sap.conn.jco.JCoMetaData; +import com.sap.conn.jco.JCoRecordMetaData; +import com.sap.conn.jco.server.JCoServer; +import com.sap.conn.jco.server.DefaultServerHandlerFactory; + import com.sap.conn.jco.ext.DestinationDataProvider; +import com.sap.conn.jco.ext.ServerDataProvider; +import com.sap.conn.jco.server.JCoServerFactory; +import com.sap.conn.jco.JCoCustomRepository; +import com.sap.conn.jco.JCoFunctionTemplate; +import com.sap.conn.jco.JCoListMetaData; +import com.sap.conn.jco.JCo; + public class SessionManager { - + private static final int BLOB_LENGTH = 1022; private String msHost = ""; private String msServ = ""; private String group = ""; @@ -41,12 +53,15 @@ public class SessionManager private String registrationCount = "3"; private String programID = ""; private String serverName = ""; + private String repository = ""; private ModelContext _context = null; DestinationProvider destinationProvider = null; Properties connectionProperties=null; - + JCoServer receiver = null; + JCoServer sender = null; + public SessionManager(ModelContext context) { _context = context; @@ -87,14 +102,20 @@ public void Connect() { connectionProperties.setProperty(DestinationDataProvider.JCO_MSSERV, msServ + ":" + port); } - } - connectionProperties.setProperty(DestinationDataProvider.JCO_GWHOST, gatewayHost); - connectionProperties.setProperty(DestinationDataProvider.JCO_GWSERV, gatewayService); - connectionProperties.setProperty(DestinationDataProvider.JCO_R3NAME, systemId); - connectionProperties.setProperty(DestinationDataProvider.JCO_SAPROUTER, sapRouter); - connectionProperties.setProperty(DestinationDataProvider.JCO_GROUP, group); - + } } + // Document Transfer server + connectionProperties.setProperty(DestinationDataProvider.JCO_GWHOST, gatewayHost); + connectionProperties.setProperty(DestinationDataProvider.JCO_GWSERV, gatewayService); + connectionProperties.setProperty(DestinationDataProvider.JCO_R3NAME, systemId); + connectionProperties.setProperty(DestinationDataProvider.JCO_SAPROUTER, sapRouter); + connectionProperties.setProperty(DestinationDataProvider.JCO_GROUP, group); + + connectionProperties.setProperty(ServerDataProvider.JCO_GWHOST,gatewayHost); + connectionProperties.setProperty(ServerDataProvider.JCO_GWSERV, gatewayService); + connectionProperties.setProperty(ServerDataProvider.JCO_PROGID, programID); + connectionProperties.setProperty(ServerDataProvider.JCO_CONNECTION_COUNT, registrationCount); + // connectionProperties.setProperty(DestinationDataProvider.JCO_SYSNR, instanceNumber); connectionProperties.setProperty(DestinationDataProvider.JCO_CLIENT, clientNumber); connectionProperties.setProperty(DestinationDataProvider.JCO_USER, userName); @@ -113,8 +134,16 @@ public void Connect() Log.info("GX SAP - Connecting " + sessionName); destinationProvider.setConnectionProperties( hashedSession, connectionProperties); + destinationProvider.setServerProperties(serverName, connectionProperties); _context.setContextProperty("SAPSessionName", hashedSession); + + _context.setContextProperty("SAPReceiverServerName", serverName); + _context.setContextProperty("SAPReceiverRepositoryName", repository); + _context.setContextProperty("SAPSenderServerName", serverName); + _context.setContextProperty("SAPSenderRepositoryName", repository); + + try { JCoDestination destination = JCoDestinationManager.getDestination(hashedSession); @@ -146,20 +175,107 @@ public void Connect() } } - public void DocumentReceiverStart() + + public JCoServer setupServer(String serverName, String repositoryName) throws JCoException { - } + JCoServer server = JCoServerFactory.getServer(serverName); + JCoCustomRepository repo = JCo.createCustomRepository(repositoryName); + JCoListMetaData imports, exports, tables; + JCoFunctionTemplate FTP_R3_TO_CLIENT; + - public void DocumentSenderStart() - { + imports = JCo.createListMetaData("IMPORTING"); + imports.add("FNAME", JCoMetaData.TYPE_CHAR, 256, 512, JCoListMetaData.IMPORT_PARAMETER); + imports.add("LENGTH", JCoMetaData.TYPE_INT, 4, 4, JCoListMetaData.IMPORT_PARAMETER); + imports.add("MODE", JCoMetaData.TYPE_CHAR, 1, 2, JCoListMetaData.IMPORT_PARAMETER | JCoListMetaData.OPTIONAL_PARAMETER); + imports.lock(); + + exports = JCo.createListMetaData("EXPORTING"); + exports.add("ERROR", JCoMetaData.TYPE_INT, 4, 4, JCoListMetaData.EXPORT_PARAMETER); + exports.lock(); + + JCoRecordMetaData tabLine = JCo.createRecordMetaData("BLOB"); + tabLine.add("LINE", JCoMetaData.TYPE_BYTE, BLOB_LENGTH, 0, BLOB_LENGTH, 0); + tabLine.lock(); + tables = JCo.createListMetaData("TABLES"); + tables.add("BLOB", JCoMetaData.TYPE_TABLE, tabLine, 0); + tables.lock(); + + FTP_R3_TO_CLIENT = JCo.createFunctionTemplate("FTP_R3_TO_CLIENT", imports, exports, null, tables, null); + repo.addFunctionTemplateToCache(FTP_R3_TO_CLIENT); + server.setRepository(repo); + + DefaultServerHandlerFactory.FunctionHandlerFactory handlerFactory = new DefaultServerHandlerFactory.FunctionHandlerFactory(); + handlerFactory.registerHandler("FTP_R3_TO_CLIENT", new DocumentClient.FTP_R3_TO_CLIENTHandler()); + server.setCallHandlerFactory(handlerFactory); + + DocumentClient.ErrorHandler hdl = new DocumentClient.ErrorHandler(); + server.addServerErrorListener(hdl); + server.addServerExceptionListener(hdl); + + return server; } - public void DocumentSenderStop() + public void DocumentReceiverStart() + { + Log.info("GX SAP - DMS Receiver Start " + serverName + " " + repository); + try { + receiver = setupServer(serverName, repository); + receiver.start(); + } + catch (JCoException ex) + { + Log.error("GX SAP - Error Starting " + ex.toString()) ; + } + } + + public void DocumentReceiverStop() { + Object receiverObj = _context.getContextProperty(serverName); + try { + if (receiverObj != null) + { + String receiverName = (String)receiverObj; + receiver = JCoServerFactory.getServer(receiverName); + if (receiver != null) receiver.stop(); + Log.info("GX SAP - DMS Receiver stop " + receiverName ); + } + } + catch (JCoException ex) + { + Log.error("GX SAP - Error Stopping " + ex.toString()) ; + } } - public void DocumentReceiverStop() + public void DocumentSenderStart() + { + Log.info("GX SAP - DMS Sender Start " + serverName + " " + repository); + try { + sender = setupServer(serverName, repository); + sender.start(); + } + catch (JCoException ex) + { + Log.error("GX SAP - Error Starting " + ex.toString()) ; + } + } + + public void DocumentSenderStop() { + Object senderObj = _context.getContextProperty(serverName); + try { + if (senderObj != null) + { + String senderName = (String)senderObj; + sender = JCoServerFactory.getServer(senderName); + if (sender != null) sender.stop(); + Log.info("GX SAP - DMS Sender stop " + senderName ); + } + } + catch (JCoException ex) + { + Log.error("GX SAP - Error Stopping " + ex.toString()) ; + } } public void TransactionBegin() @@ -332,6 +448,12 @@ public String getServerName() } + public String getRepository() + { + return repository; + } + + /* Setters */ public void setPort( String value ) @@ -374,34 +496,34 @@ public void setUserName( String value ) } public void setPassword( String value ) - { + { password = value; - } + } public void setInstanceNumber( String value ) - { + { instanceNumber = value; - } + } public void setAppServer( String value ) - { + { appServer = value; - } + } public void setRouterString( String value ) - { + { routerString = value; } public void setClientNumber( String value ) - { + { clientNumber = value; - } + } public void setSystemId( String value ) - { + { systemId = value; - } + } public void setSessionName( String value ) { @@ -429,14 +551,14 @@ public void setLanguage(String value) } public void setErrorCode( Integer value ) - { + { errorCode = value; - } + } public void setErrorMessage( String value ) - { + { errorMessage = value; - } + } public void setRegistrationCount(String value) { @@ -452,5 +574,10 @@ public void setServerName(String value) { serverName = value; } + + public void setRepository(String value) + { + repository = value; + } } \ No newline at end of file From 07ecb55162724c5e97e4e11660f58c3b49ad5f32 Mon Sep 17 00:00:00 2001 From: AlejandroP Date: Wed, 23 Nov 2022 12:27:16 -0300 Subject: [PATCH 2/4] - Soporte para SAP Cloud Destination - Separo Document receiver y DocumentSender de la connection SessionManager. Issue 100181 --- .../com/genexus/sap/DestinationProvider.java | 7 - .../java/com/genexus/sap/DocumentClient.java | 42 ++- .../com/genexus/sap/DocumentReceiver.java | 123 +++++++ .../java/com/genexus/sap/DocumentSender.java | 126 +++++++ .../com/genexus/sap/EnterpriseConnect.java | 46 ++- .../com/genexus/sap/ServerConnection.java | 136 ++++++++ .../java/com/genexus/sap/SessionManager.java | 327 ++++++------------ 7 files changed, 555 insertions(+), 252 deletions(-) create mode 100644 java/src/main/java/com/genexus/sap/DocumentReceiver.java create mode 100644 java/src/main/java/com/genexus/sap/DocumentSender.java create mode 100644 java/src/main/java/com/genexus/sap/ServerConnection.java diff --git a/java/src/main/java/com/genexus/sap/DestinationProvider.java b/java/src/main/java/com/genexus/sap/DestinationProvider.java index c77791990..22d3e0d66 100644 --- a/java/src/main/java/com/genexus/sap/DestinationProvider.java +++ b/java/src/main/java/com/genexus/sap/DestinationProvider.java @@ -10,8 +10,6 @@ import com.sap.conn.jco.ext.ServerDataProvider; import com.sap.conn.jco.ext.Environment; - - public class DestinationProvider implements DestinationDataProvider, ServerDataProvider { @@ -23,7 +21,6 @@ public static DestinationProvider Instance() _instance = new DestinationProvider(); } return _instance; - } private String SAP_SERVER = "SAP_SERVER"; @@ -57,7 +54,6 @@ public Properties getDestinationProperties(String sessionName) public boolean supportsEvents() { return true; - } /*@Override*/ @@ -90,7 +86,6 @@ public Properties getServerProperties(String serverName) { public void setServerDataEventListener(ServerDataEventListener arg0) { // Our logon parameters don't change dynamically, so we don't need to fire events. See above comment on DestinationDataEventListener. } - public void removeServerProperties(String serverName) { @@ -107,7 +102,6 @@ public void setServerProperties( String serverName, Properties properties) if ( serverName == null || serverName.equals("")) { serverName = SAP_DOC_SERVER; - } if (!Environment.isServerDataProviderRegistered()) { @@ -150,7 +144,6 @@ public void setConnectionProperties( String sessionName, Properties properties) if ( sessionName == null || sessionName.equals("")) { sessionName = SAP_SERVER; - } if (!Environment.isDestinationDataProviderRegistered()) { diff --git a/java/src/main/java/com/genexus/sap/DocumentClient.java b/java/src/main/java/com/genexus/sap/DocumentClient.java index 6163f021a..f6e92d017 100644 --- a/java/src/main/java/com/genexus/sap/DocumentClient.java +++ b/java/src/main/java/com/genexus/sap/DocumentClient.java @@ -1,8 +1,10 @@ package com.genexus.sap; +import java.io.*; import java.io.FileOutputStream; import java.io.IOException; - +import java.nio.file.Files; +import java.nio.file.Paths; import com.sap.conn.jco.AbapClassException; import com.sap.conn.jco.AbapException; @@ -19,6 +21,7 @@ import com.sap.conn.jco.server.JCoServerFunctionHandler; public class DocumentClient { + private static final int BLOB_LENGTH = 1022; static class ErrorHandler implements JCoServerErrorListener, JCoServerExceptionListener { @@ -52,7 +55,6 @@ public void handleRequest(JCoServerContext serverCtx, JCoFunction function) thro length = imports.getInt("LENGTH"); blob = function.getTableParameterList().getTable("BLOB"); FileOutputStream out = null; - System.out.println( " file handle " + fname); try { out = new FileOutputStream(fname); boolean hasNextRow = false; @@ -62,7 +64,6 @@ public void handleRequest(JCoServerContext serverCtx, JCoFunction function) thro } while (length > BLOB_LENGTH){ if (hasNextRow){ - System.out.println( " write .... " ); out.write(blob.getByteArray(0), 0, BLOB_LENGTH); length -= BLOB_LENGTH; hasNextRow = blob.nextRow(); @@ -92,4 +93,39 @@ public void handleRequest(JCoServerContext serverCtx, JCoFunction function) thro } + static class FTP_CLIENT_TO_R3Handler implements JCoServerFunctionHandler { + @Override + public void handleRequest(JCoServerContext serverCtx, JCoFunction function) throws AbapException, AbapClassException { + String fname; + + fname = function.getImportParameterList().getString("FNAME"); + fname = fname.replace("#",""); + + try (InputStream source = Files.newInputStream(Paths.get(fname));) { + + byte[] file2 = new byte[BLOB_LENGTH]; + int bytesread; + int totallenght =0; + + InputStream source2 = Files.newInputStream(Paths.get(fname)); + + JCoTable blobtable = function.getTableParameterList().getTable("BLOB"); + while((bytesread = source2.read(file2,0,file2.length)) >0 ) + { + + blobtable.appendRow(); + blobtable.setValue("LINE", file2); + totallenght += bytesread; + } + + JCoParameterList exports = function.getExportParameterList(); + exports.setValue("LENGTH", totallenght); + } + catch (IOException e) { + e.printStackTrace(); + function.getExportParameterList().setValue("ERROR", 3); + } + } + } + } \ No newline at end of file diff --git a/java/src/main/java/com/genexus/sap/DocumentReceiver.java b/java/src/main/java/com/genexus/sap/DocumentReceiver.java new file mode 100644 index 000000000..89f5458bd --- /dev/null +++ b/java/src/main/java/com/genexus/sap/DocumentReceiver.java @@ -0,0 +1,123 @@ +package com.genexus.sap; + +import com.genexus.ModelContext; +import com.sap.conn.jco.JCoException; + +import com.sap.conn.jco.JCoMetaData; +import com.sap.conn.jco.JCoRecordMetaData; +import com.sap.conn.jco.server.JCoServer; +import com.sap.conn.jco.server.DefaultServerHandlerFactory; + +import com.sap.conn.jco.server.JCoServerFactory; +import com.sap.conn.jco.JCoCustomRepository; +import com.sap.conn.jco.JCoFunctionTemplate; +import com.sap.conn.jco.JCoListMetaData; +import com.sap.conn.jco.JCo; +import com.genexus.diagnostics.Log; + +public class DocumentReceiver +{ + private static final int BLOB_LENGTH = 1022; + private String serverName = ""; + private String repositoryName = ""; + private ModelContext _context = null; + JCoServer receiver = null; + + + public DocumentReceiver(String server, String repository, ModelContext context) + { + this.serverName = server; + this.repositoryName = repository; + this._context = context; + } + + public void start() + { + Log.info("GX SAP - DMS Receiver Start " + serverName + " " + repositoryName); + try { + receiver = setupServerDownload(serverName, repositoryName); + receiver.start(); + } + catch (JCoException ex) + { + Log.error("GX SAP - Error Starting " + ex.toString()) ; + } + } + + public void stop() + { + + String receiverName = ""; + if (serverName == null || serverName.equals("")) + { + Object receiverObj = _context.getContextProperty("SAPReceiverServerName"); + if (receiverObj != null) + { + receiverName = (String)receiverObj; + } + } + else + { + receiverName = serverName; + } + + try { + if (!receiverName.equals("")) + { + receiver = JCoServerFactory.getServer(receiverName); + if (receiver != null) receiver.stop(); + Log.info("GX SAP - DMS Receiver stop " + receiverName ); + } + else + { + Log.error("GX SAP - Error Stopping receiver." ); + } + } + catch (JCoException ex) + { + Log.error("GX SAP - Error Stopping " + ex.toString()) ; + } + + } + + public JCoServer setupServerDownload(String serverName, String repositoryName) throws JCoException + { + JCoServer server = JCoServerFactory.getServer(serverName); + JCoCustomRepository repo = JCo.createCustomRepository(repositoryName); + JCoListMetaData imports, exports, tables; + JCoFunctionTemplate FTP_R3_TO_CLIENT; + + imports = JCo.createListMetaData("IMPORTING"); + imports.add("FNAME", JCoMetaData.TYPE_CHAR, 256, 512, JCoListMetaData.IMPORT_PARAMETER); + imports.add("LENGTH", JCoMetaData.TYPE_INT, 4, 4, JCoListMetaData.IMPORT_PARAMETER); + imports.add("MODE", JCoMetaData.TYPE_CHAR, 1, 2, JCoListMetaData.IMPORT_PARAMETER | JCoListMetaData.OPTIONAL_PARAMETER); + imports.lock(); + + exports = JCo.createListMetaData("EXPORTING"); + exports.add("ERROR", JCoMetaData.TYPE_INT, 4, 4, JCoListMetaData.EXPORT_PARAMETER); + exports.add("LENGTH", JCoMetaData.TYPE_INT, 4, 4, JCoListMetaData.EXPORT_PARAMETER); + exports.lock(); + + JCoRecordMetaData tabLine = JCo.createRecordMetaData("BLOB"); + tabLine.add("LINE", JCoMetaData.TYPE_BYTE, BLOB_LENGTH, 0, BLOB_LENGTH, 0); + tabLine.lock(); + tables = JCo.createListMetaData("TABLES"); + tables.add("BLOB", JCoMetaData.TYPE_TABLE, tabLine, 0); + tables.lock(); + + FTP_R3_TO_CLIENT = JCo.createFunctionTemplate("FTP_R3_TO_CLIENT", imports, exports, null, tables, null); + repo.addFunctionTemplateToCache(FTP_R3_TO_CLIENT); + server.setRepository(repo); + + DefaultServerHandlerFactory.FunctionHandlerFactory handlerFactory = new DefaultServerHandlerFactory.FunctionHandlerFactory(); + handlerFactory.registerHandler("FTP_R3_TO_CLIENT", new DocumentClient.FTP_R3_TO_CLIENTHandler()); + server.setCallHandlerFactory(handlerFactory); + + DocumentClient.ErrorHandler hdl = new DocumentClient.ErrorHandler(); + server.addServerErrorListener(hdl); + server.addServerExceptionListener(hdl); + + return server; + } + +} \ No newline at end of file diff --git a/java/src/main/java/com/genexus/sap/DocumentSender.java b/java/src/main/java/com/genexus/sap/DocumentSender.java new file mode 100644 index 000000000..f8a74797a --- /dev/null +++ b/java/src/main/java/com/genexus/sap/DocumentSender.java @@ -0,0 +1,126 @@ + + + +package com.genexus.sap; + +import com.genexus.ModelContext; +import com.sap.conn.jco.JCoException; +import com.sap.conn.jco.JCoMetaData; +import com.sap.conn.jco.JCoRecordMetaData; +import com.sap.conn.jco.server.JCoServer; +import com.sap.conn.jco.server.DefaultServerHandlerFactory; + +import com.sap.conn.jco.ext.DestinationDataProvider; +import com.sap.conn.jco.ext.ServerDataProvider; +import com.sap.conn.jco.server.JCoServerFactory; +import com.sap.conn.jco.JCoCustomRepository; +import com.sap.conn.jco.JCoFunctionTemplate; +import com.sap.conn.jco.JCoListMetaData; +import com.sap.conn.jco.JCo; +import com.genexus.diagnostics.Log; + +public class DocumentSender +{ + private static final int BLOB_LENGTH = 1022; + private String serverName = ""; + private String repositoryName = ""; + private ModelContext _context = null; + JCoServer sender = null; + + + public DocumentSender(String server, String repository, ModelContext context) + { + this.serverName = server; + this.repositoryName = repository; + this._context = context; + } + + public void start() + { + Log.info("GX SAP - DMS Sender Start " + serverName + " " + repositoryName); + + try { + sender = setupServerUpload(serverName, repositoryName); + sender.start(); + } + catch (JCoException ex) + { + Log.error("GX SAP - Error Starting " + ex.toString()) ; + } + } + + public void stop() + { + String senderName = ""; + if (serverName == null || serverName.equals("")) + { + Object senderObj = _context.getContextProperty("SAPSenderServerName"); + if (senderObj != null) + { + senderName = (String)senderObj; + } + } + else + { + senderName = serverName; + } + try { + if (!senderName.equals("")) + { + sender = JCoServerFactory.getServer(senderName); + if (sender != null) sender.stop(); + Log.info("GX SAP - DMS Sender stop " + senderName ); + } + else + { + Log.error("GX SAP - Error Stopping sender" ); + } + } + catch (JCoException ex) + { + Log.error("GX SAP - Error Stopping " + ex.toString()) ; + } + } + + public JCoServer setupServerUpload(String serverName, String repositoryName) throws JCoException + { + JCoServer server = JCoServerFactory.getServer(serverName); + + JCoCustomRepository repo = JCo.createCustomRepository(repositoryName); + JCoListMetaData imports, exports, tables; + JCoFunctionTemplate FTP_CLIENT_TO_R3; + + imports = JCo.createListMetaData("IMPORTING"); + imports.add("FNAME", JCoMetaData.TYPE_CHAR, 256, 512, JCoListMetaData.IMPORT_PARAMETER); + imports.add("MODE", JCoMetaData.TYPE_CHAR, 1, 2, JCoListMetaData.IMPORT_PARAMETER | JCoListMetaData.OPTIONAL_PARAMETER); + imports.lock(); + + exports = JCo.createListMetaData("EXPORTING"); + exports.add("ERROR", JCoMetaData.TYPE_INT, 4, 4, JCoListMetaData.EXPORT_PARAMETER); + exports.add("LENGTH", JCoMetaData.TYPE_INT, 4, 4, JCoListMetaData.EXPORT_PARAMETER); + exports.lock(); + + JCoRecordMetaData tabLine = JCo.createRecordMetaData("BLOB"); + tabLine.add("LINE", JCoMetaData.TYPE_BYTE, BLOB_LENGTH, 0, BLOB_LENGTH, 0); + tabLine.lock(); + + tables = JCo.createListMetaData("TABLES"); + tables.add("BLOB", JCoMetaData.TYPE_TABLE, tabLine, 0); + tables.lock(); + + FTP_CLIENT_TO_R3 = JCo.createFunctionTemplate("FTP_CLIENT_TO_R3", imports, exports, null, tables, null); + repo.addFunctionTemplateToCache(FTP_CLIENT_TO_R3); + server.setRepository(repo); + + DefaultServerHandlerFactory.FunctionHandlerFactory handlerFactory = new DefaultServerHandlerFactory.FunctionHandlerFactory(); + handlerFactory.registerHandler("FTP_CLIENT_TO_R3", new DocumentClient.FTP_CLIENT_TO_R3Handler()); + server.setCallHandlerFactory(handlerFactory); + + DocumentClient.ErrorHandler hdl = new DocumentClient.ErrorHandler(); + server.addServerErrorListener(hdl); + server.addServerExceptionListener(hdl); + + return server; + } + +} \ No newline at end of file diff --git a/java/src/main/java/com/genexus/sap/EnterpriseConnect.java b/java/src/main/java/com/genexus/sap/EnterpriseConnect.java index f6318a53f..6fa64fd47 100644 --- a/java/src/main/java/com/genexus/sap/EnterpriseConnect.java +++ b/java/src/main/java/com/genexus/sap/EnterpriseConnect.java @@ -155,13 +155,14 @@ public void setValue(String parameterName, GXSimpleCollection value, Boolean inO if( jObj.get(key) instanceof String ) { - if (jcoType == JCoMetaData.TYPE_NUM && dec == 0 ) - { - String sValue = new DecimalFormat("#").format(new BigDecimal(jObj.getString(key))); //"1.2" + String obj_value = jObj.getString(key); + if (jcoType == JCoMetaData.TYPE_NUM && dec == 0 && ( ! obj_value.trim().equals("") )) + { + String sValue = new DecimalFormat("#").format(new BigDecimal(obj_value)); jTable.setValue(key, sValue); } else { - jTable.setValue(key, jObj.getString(key)); + jTable.setValue(key, obj_value); } } else if (jcoType == JCoMetaData.TYPE_NUM || jcoType == JCoMetaData.TYPE_INT) @@ -174,7 +175,7 @@ else if (jcoType == JCoMetaData.TYPE_FLOAT || jcoType == JCoMetaData.TYPE_BCD) } else if (jcoType == JCoMetaData.TYPE_DATE) { - jTable.setValue(key, jObj.getString(key)); + jTable.setValue(key, jObj.getString(key)); } else if (jcoType == JCoMetaData.TYPE_INT2 || jcoType == JCoMetaData.TYPE_INT1 || jcoType == JCoMetaData.TYPE_BYTE) @@ -194,8 +195,7 @@ else if (jcoType == JCoMetaData.TYPE_INT2 || jcoType == JCoMetaData.TYPE_INT1 throw new RuntimeException(ex.toString()); } if (setValues) - { - //System.out.println( " TABLE " + jTable.toString() ); + { function.getTableParameterList().setActive(parameterName, true); } else @@ -276,16 +276,26 @@ public void getValue(String parameterName, GXSimpleCollection[] value) tbl.setRow(i); for(JCoField field : tbl) { - if ( field.getType() == JCoMetaData.TYPE_NUM || - field.getType() == JCoMetaData.TYPE_FLOAT || - field.getType() == JCoMetaData.TYPE_BCD ) + if (field.getType() == JCoMetaData.TYPE_INT || + (field.getType() == JCoMetaData.TYPE_NUM && field.getDecimals() == 0)) + { + jRow.put(field.getName(), field.getLong()); + } + else if (field.getType() == JCoMetaData.TYPE_INT2 || field.getType() == JCoMetaData.TYPE_INT1 + || field.getType() == JCoMetaData.TYPE_BYTE ) + { + jRow.put(field.getName(), field.getInt()); + } + else if ( field.getType() == JCoMetaData.TYPE_NUM || + field.getType() == JCoMetaData.TYPE_FLOAT || + field.getType() == JCoMetaData.TYPE_BCD ) { - jRow.put(field.getName(), field.getDouble()); + jRow.put(field.getName(), field.getDouble()); } else { - jRow.put(field.getName(), field.getString()); - } + jRow.put(field.getName(), field.getString()); + } } jCol.put(jRow); } @@ -376,7 +386,7 @@ public void executeStart(String functionName) } catch (JCoException e) { - throw new RuntimeException(e.toString()); + throw new RuntimeException("JCoException: " + e.toString()); } } @@ -392,12 +402,12 @@ public void executeStart(String functionName, boolean isTransaction) throws JCoE function = destination.getRepository().getFunction(functionName); if (function == null) { - throw new RuntimeException( functionName + " not found in SAP"); + throw new RuntimeException( "GeneXus cannot find SAP function " + functionName); } } catch (AbapException e) { - throw new RuntimeException(e.toString()); + throw new RuntimeException(" ABAP Exception: " + e.toString()); } } @@ -409,7 +419,7 @@ public int executeFunction(String functionName) } catch (JCoException e) { - throw new RuntimeException(e.toString()); + throw new RuntimeException("JCoException excecuting: " + e.toString()); } } @@ -428,7 +438,7 @@ public int executeFunction(String functionName, boolean isTransaction) throws JC } catch (AbapException e) { - throw new RuntimeException(e.toString()); + throw new RuntimeException( "ABAP exception executing: " + e.toString()); } return 0; } diff --git a/java/src/main/java/com/genexus/sap/ServerConnection.java b/java/src/main/java/com/genexus/sap/ServerConnection.java new file mode 100644 index 000000000..0641d787b --- /dev/null +++ b/java/src/main/java/com/genexus/sap/ServerConnection.java @@ -0,0 +1,136 @@ +package com.genexus.sap; + +import java.util.Properties; +import com.genexus.ModelContext; +import com.genexus.diagnostics.Log; +import com.sap.conn.jco.AbapException; +import com.sap.conn.jco.JCoContext; +import com.sap.conn.jco.JCoDestination; +import com.sap.conn.jco.JCoDestinationManager; +import com.sap.conn.jco.JCoException; +import com.sap.conn.jco.JCoFunction; +import com.sap.conn.jco.ext.DestinationDataProvider; +import com.sap.conn.jco.ext.ServerDataProvider; + +public class ServerConnection +{ + ModelContext _context; + SessionManager _manager; + DestinationProvider destinationProvider = null; + private Integer errorCode = 0; + private String errorMessage = ""; + + private String hashedSession = ""; + + public ServerConnection(SessionManager manager, ModelContext context) + { + _manager = manager; + _context = context; + } + + public void connect(Properties connectionProperties) + { + + if (destinationProvider == null) { + destinationProvider = DestinationProvider.Instance(); + } + + if (_manager.getMessageHost() == null || _manager.getMessageHost().equals("")) { + connectionProperties.setProperty(DestinationDataProvider.JCO_ASHOST, _manager.getRouterString() + _manager.getAppServer()); + } + else { + if (_manager.getPort() == null || _manager.getPort().equals("")) { + connectionProperties.setProperty(DestinationDataProvider.JCO_MSHOST, _manager.getMessageHost()); + connectionProperties.setProperty(DestinationDataProvider.JCO_MSSERV, _manager.getMessageSrv()); + } + else { + connectionProperties.setProperty(DestinationDataProvider.JCO_MSHOST, _manager.getMessageHost() + ":" + _manager.getPort()); + if (!_manager.getMessageSrv().equals("")) + { + connectionProperties.setProperty(DestinationDataProvider.JCO_MSSERV, _manager.getMessageSrv() + ":" + _manager.getPort()); + } + } + } + + // Document Transfer server + //connectionProperties.setProperty(DestinationDataProvider.JCO_GWHOST, gatewayHost); + //connectionProperties.setProperty(DestinationDataProvider.JCO_GWSERV, gatewayService); + // Set Destination Properties + + connectionProperties.setProperty(DestinationDataProvider.JCO_R3NAME, _manager.getSystemId()); + connectionProperties.setProperty(DestinationDataProvider.JCO_SAPROUTER, _manager.getSAPRouter()); + connectionProperties.setProperty(DestinationDataProvider.JCO_GROUP, _manager.getGroup()); + + connectionProperties.setProperty(ServerDataProvider.JCO_GWHOST, _manager.getGatewayHost()); + connectionProperties.setProperty(ServerDataProvider.JCO_GWSERV, _manager.getGatewaySrv()); + connectionProperties.setProperty(ServerDataProvider.JCO_PROGID, _manager.getProgramID()); + connectionProperties.setProperty(ServerDataProvider.JCO_CONNECTION_COUNT, _manager.getRegistrationCount()); + // + connectionProperties.setProperty(DestinationDataProvider.JCO_SYSNR, _manager.getInstanceNumber()); + connectionProperties.setProperty(DestinationDataProvider.JCO_CLIENT, _manager.getClientNumber()); + connectionProperties.setProperty(DestinationDataProvider.JCO_USER, _manager.getUserName()); + connectionProperties.setProperty(DestinationDataProvider.JCO_PASSWD, _manager.getPassword()); + + connectionProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, _manager.getPoolCapacity()); + connectionProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, _manager.getPeekLimit()); + + if ( ! _manager.getLanguage().equals("")) + { + connectionProperties.setProperty(DestinationDataProvider.JCO_LANG, _manager.getLanguage()); + } + + // Hash session name + hashedSession = _manager.getSessionName() + "H" + Integer.toString(connectionProperties.values().toString().hashCode()).replace("-","0"); + + Log.info("GX SAP - Connecting " + _manager.getSessionName()); + destinationProvider.setConnectionProperties( hashedSession, connectionProperties); + destinationProvider.setServerProperties(_manager.getServerName(), connectionProperties); + + _context.setContextProperty("SAPSessionName", hashedSession); + + _context.setContextProperty("SAPReceiverServerName", _manager.getServerName()); + + _context.setContextProperty("SAPReceiverRepositoryName", _manager.getRepositoryName()); + _context.setContextProperty("SAPSenderServerName", _manager.getServerName()); + _context.setContextProperty("SAPSenderRepositoryName", _manager.getRepositoryName()); + + try + { + JCoDestination destination = JCoDestinationManager.getDestination(hashedSession); + destination.ping(); + } + catch (AbapException ex) + { + errorCode = ex.getGroup(); + errorMessage = ex.toString(); + Log.warning("GX SAP - Error Connecting " + _manager.getSessionName() + " " + ex.toString()) ; + } + catch (JCoException ex) + { + if(ex.getGroup() == JCoException.JCO_ERROR_INTERNAL) + { + Log.error("GX SAP - Error Connecting " + _manager.getSessionName() + " " + ex.toString()) ; + throw new RuntimeException(ex.toString()); + } + errorCode = ex.getGroup(); + errorMessage = ex.toString(); + Log.warning("GX SAP - Error Connecting " + _manager.getSessionName() + " " + ex.toString()) ; + } + catch (Exception ex) + { + Log.error("GX SAP - Error Connecting " + _manager.getSessionName() + " " + ex.toString()) ; + throw new RuntimeException(ex.toString()); + } + } + + public Integer getErrorCode() + { + return errorCode; + } + + public String getErrorMessage() + { + return errorMessage; + } + +} \ No newline at end of file diff --git a/java/src/main/java/com/genexus/sap/SessionManager.java b/java/src/main/java/com/genexus/sap/SessionManager.java index 0f7ffaed1..7aaecb030 100644 --- a/java/src/main/java/com/genexus/sap/SessionManager.java +++ b/java/src/main/java/com/genexus/sap/SessionManager.java @@ -1,8 +1,6 @@ package com.genexus.sap; - import java.util.Properties; - import com.genexus.ModelContext; import com.genexus.diagnostics.Log; import com.sap.conn.jco.AbapException; @@ -11,23 +9,9 @@ import com.sap.conn.jco.JCoDestinationManager; import com.sap.conn.jco.JCoException; import com.sap.conn.jco.JCoFunction; -import com.sap.conn.jco.JCoMetaData; -import com.sap.conn.jco.JCoRecordMetaData; -import com.sap.conn.jco.server.JCoServer; -import com.sap.conn.jco.server.DefaultServerHandlerFactory; - -import com.sap.conn.jco.ext.DestinationDataProvider; -import com.sap.conn.jco.ext.ServerDataProvider; -import com.sap.conn.jco.server.JCoServerFactory; -import com.sap.conn.jco.JCoCustomRepository; -import com.sap.conn.jco.JCoFunctionTemplate; -import com.sap.conn.jco.JCoListMetaData; -import com.sap.conn.jco.JCo; - public class SessionManager { - private static final int BLOB_LENGTH = 1022; private String msHost = ""; private String msServ = ""; private String group = ""; @@ -43,7 +27,7 @@ public class SessionManager private String clientNumber = ""; private String systemId = ""; private String sessionName = ""; - private String hashedSession = ""; + private String sapGUI = ""; private Integer errorCode = 0; private String errorMessage = ""; @@ -53,14 +37,14 @@ public class SessionManager private String registrationCount = "3"; private String programID = ""; private String serverName = ""; - private String repository = ""; + private String repositoryName = ""; private ModelContext _context = null; - DestinationProvider destinationProvider = null; + Properties connectionProperties=null; - JCoServer receiver = null; - JCoServer sender = null; + DocumentReceiver documentReceiver=null; + DocumentSender documentSender=null; public SessionManager(ModelContext context) { @@ -79,86 +63,37 @@ public void Disconnect() //_context.setContextProperty("SAPSessionName", ""); } - public void Connect() + public void ConnectSession(String destination, String scope) { + Log.info("GX SAP - Connecting to Destination" + destination); + ConnectInternal(destination, destination, scope); + } + + public void ConnectInternal(String session, String sessionName, String scope) + { errorCode = 0; - errorMessage = ""; - connectionProperties = new Properties(); - if (destinationProvider == null) { - destinationProvider = DestinationProvider.Instance(); - } - - if (msHost == null || msHost.equals("")) { - connectionProperties.setProperty(DestinationDataProvider.JCO_ASHOST, routerString + appServer); - } - else { - if (port == null || port.equals("")) { - connectionProperties.setProperty(DestinationDataProvider.JCO_MSHOST, msHost); - connectionProperties.setProperty(DestinationDataProvider.JCO_MSSERV, msServ); - } - else { - connectionProperties.setProperty(DestinationDataProvider.JCO_MSHOST, msHost + ":" + port); - if (!msServ.equals("")) - { - connectionProperties.setProperty(DestinationDataProvider.JCO_MSSERV, msServ + ":" + port); - } - } - } - // Document Transfer server - connectionProperties.setProperty(DestinationDataProvider.JCO_GWHOST, gatewayHost); - connectionProperties.setProperty(DestinationDataProvider.JCO_GWSERV, gatewayService); - connectionProperties.setProperty(DestinationDataProvider.JCO_R3NAME, systemId); - connectionProperties.setProperty(DestinationDataProvider.JCO_SAPROUTER, sapRouter); - connectionProperties.setProperty(DestinationDataProvider.JCO_GROUP, group); - - connectionProperties.setProperty(ServerDataProvider.JCO_GWHOST,gatewayHost); - connectionProperties.setProperty(ServerDataProvider.JCO_GWSERV, gatewayService); - connectionProperties.setProperty(ServerDataProvider.JCO_PROGID, programID); - connectionProperties.setProperty(ServerDataProvider.JCO_CONNECTION_COUNT, registrationCount); - // - connectionProperties.setProperty(DestinationDataProvider.JCO_SYSNR, instanceNumber); - connectionProperties.setProperty(DestinationDataProvider.JCO_CLIENT, clientNumber); - connectionProperties.setProperty(DestinationDataProvider.JCO_USER, userName); - connectionProperties.setProperty(DestinationDataProvider.JCO_PASSWD, password); - - connectionProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, poolCapacity); - connectionProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, peekLimit); - - if ( ! language.equals("")) - { - connectionProperties.setProperty(DestinationDataProvider.JCO_LANG, language); - } - - // Hash session name - hashedSession = sessionName + "H" + Integer.toString(connectionProperties.values().toString().hashCode()).replace("-","0"); - - Log.info("GX SAP - Connecting " + sessionName); - destinationProvider.setConnectionProperties( hashedSession, connectionProperties); - destinationProvider.setServerProperties(serverName, connectionProperties); - - _context.setContextProperty("SAPSessionName", hashedSession); - - _context.setContextProperty("SAPReceiverServerName", serverName); - _context.setContextProperty("SAPReceiverRepositoryName", repository); - _context.setContextProperty("SAPSenderServerName", serverName); - _context.setContextProperty("SAPSenderRepositoryName", repository); - - + errorMessage = ""; + _context.setContextProperty("SAPSessionName", session); + _context.setContextProperty("SAPSessionScope", scope); try { - JCoDestination destination = JCoDestinationManager.getDestination(hashedSession); + JCoDestination destination = null; + if ( scope == null || scope.length() == 0 ) + destination = JCoDestinationManager.getDestination(session); + else + destination = JCoDestinationManager.getDestination(session, scope); destination.ping(); + } catch (AbapException ex) { - errorCode = ex.getGroup(); + errorCode = ex.getGroup(); errorMessage = ex.toString(); - Log.warning("GX SAP - Error Connecting " + sessionName + " " + ex.toString()) ; - + Log.warning("GX SAP - Error Connecting " + sessionName + " " + ex.toString()) ; } catch (JCoException ex) - { + { if(ex.getGroup() == JCoException.JCO_ERROR_INTERNAL) { Log.error("GX SAP - Error Connecting " + sessionName + " " + ex.toString()) ; @@ -167,129 +102,66 @@ public void Connect() errorCode = ex.getGroup(); errorMessage = ex.toString(); Log.warning("GX SAP - Error Connecting " + sessionName + " " + ex.toString()) ; - } + } catch (Exception ex) - { + { Log.error("GX SAP - Error Connecting " + sessionName + " " + ex.toString()) ; - throw new RuntimeException(ex.toString()); - } + throw new RuntimeException(ex.toString()); + } } - - public JCoServer setupServer(String serverName, String repositoryName) throws JCoException + public void Connect() { - JCoServer server = JCoServerFactory.getServer(serverName); - JCoCustomRepository repo = JCo.createCustomRepository(repositoryName); - JCoListMetaData imports, exports, tables; - JCoFunctionTemplate FTP_R3_TO_CLIENT; - - - imports = JCo.createListMetaData("IMPORTING"); - imports.add("FNAME", JCoMetaData.TYPE_CHAR, 256, 512, JCoListMetaData.IMPORT_PARAMETER); - imports.add("LENGTH", JCoMetaData.TYPE_INT, 4, 4, JCoListMetaData.IMPORT_PARAMETER); - imports.add("MODE", JCoMetaData.TYPE_CHAR, 1, 2, JCoListMetaData.IMPORT_PARAMETER | JCoListMetaData.OPTIONAL_PARAMETER); - imports.lock(); - - exports = JCo.createListMetaData("EXPORTING"); - exports.add("ERROR", JCoMetaData.TYPE_INT, 4, 4, JCoListMetaData.EXPORT_PARAMETER); - exports.lock(); - - JCoRecordMetaData tabLine = JCo.createRecordMetaData("BLOB"); - tabLine.add("LINE", JCoMetaData.TYPE_BYTE, BLOB_LENGTH, 0, BLOB_LENGTH, 0); - tabLine.lock(); - tables = JCo.createListMetaData("TABLES"); - tables.add("BLOB", JCoMetaData.TYPE_TABLE, tabLine, 0); - tables.lock(); - - FTP_R3_TO_CLIENT = JCo.createFunctionTemplate("FTP_R3_TO_CLIENT", imports, exports, null, tables, null); - repo.addFunctionTemplateToCache(FTP_R3_TO_CLIENT); - server.setRepository(repo); - - DefaultServerHandlerFactory.FunctionHandlerFactory handlerFactory = new DefaultServerHandlerFactory.FunctionHandlerFactory(); - handlerFactory.registerHandler("FTP_R3_TO_CLIENT", new DocumentClient.FTP_R3_TO_CLIENTHandler()); - server.setCallHandlerFactory(handlerFactory); - - DocumentClient.ErrorHandler hdl = new DocumentClient.ErrorHandler(); - server.addServerErrorListener(hdl); - server.addServerExceptionListener(hdl); + errorCode = 0; + errorMessage = ""; + connectionProperties = new Properties(); - return server; + ServerConnection connection = new ServerConnection(this, _context); + connection.connect(connectionProperties); } - + public void DocumentReceiverStart() { - Log.info("GX SAP - DMS Receiver Start " + serverName + " " + repository); - try { - receiver = setupServer(serverName, repository); - receiver.start(); - } - catch (JCoException ex) - { - Log.error("GX SAP - Error Starting " + ex.toString()) ; - } + documentReceiver = new DocumentReceiver(serverName, repositoryName, _context); + documentReceiver.start(); } public void DocumentReceiverStop() { - Object receiverObj = _context.getContextProperty(serverName); - try { - if (receiverObj != null) - { - String receiverName = (String)receiverObj; - receiver = JCoServerFactory.getServer(receiverName); - if (receiver != null) receiver.stop(); - Log.info("GX SAP - DMS Receiver stop " + receiverName ); - } - } - catch (JCoException ex) - { - Log.error("GX SAP - Error Stopping " + ex.toString()) ; - } + documentReceiver.stop(); } public void DocumentSenderStart() - { - Log.info("GX SAP - DMS Sender Start " + serverName + " " + repository); - try { - sender = setupServer(serverName, repository); - sender.start(); - } - catch (JCoException ex) - { - Log.error("GX SAP - Error Starting " + ex.toString()) ; - } + { + documentSender = new DocumentSender(serverName, repositoryName, _context); + documentSender.start(); } public void DocumentSenderStop() { - Object senderObj = _context.getContextProperty(serverName); - try { - if (senderObj != null) - { - String senderName = (String)senderObj; - sender = JCoServerFactory.getServer(senderName); - if (sender != null) sender.stop(); - Log.info("GX SAP - DMS Sender stop " + senderName ); - } - } - catch (JCoException ex) - { - Log.error("GX SAP - Error Stopping " + ex.toString()) ; - } + documentSender.stop(); } + public void TransactionBegin() { Object destinationObj = _context.getContextProperty("SAPSessionName"); + Object scopeObj = _context.getContextProperty("SAPSessionScope"); String destinationName = ""; + String scopeName = ""; if (destinationObj !=null) { try { destinationName = (String)destinationObj; + scopeName = (String)scopeObj; Log.info("GX SAP - Begin Transaction " + destinationName); - JCoDestination destination = JCoDestinationManager.getDestination(destinationName); + JCoDestination destination = null; + if (scopeName.length() == 0) + destination = JCoDestinationManager.getDestination(destinationName); + else + destination = JCoDestinationManager.getDestination(destinationName, scopeName); JCoContext.begin(destination); } catch (JCoException e) @@ -302,13 +174,22 @@ public void TransactionBegin() public void TransactionCommit() { Object destinationObj = _context.getContextProperty("SAPSessionName"); + Object scopeObject = _context.getContextProperty("SAPSessionScope"); String destinationName = ""; + String scopeName = ""; if (destinationObj !=null) { try { - destinationName = (String)destinationObj; - JCoDestination destination = JCoDestinationManager.getDestination(destinationName); + JCoDestination destination = null; + destinationName = (String)destinationObj; + if ( scopeObject == null || ((String)scopeObject).length() == 0 ) { + destination = JCoDestinationManager.getDestination(destinationName); + } + else { + scopeName = (String)scopeObject; + destination = JCoDestinationManager.getDestination(destinationName, scopeName); + } Log.info("GX SAP - Commit Transaction " + destinationName); JCoFunction commitFnc = destination.getRepository().getFunction("BAPI_TRANSACTION_COMMIT"); commitFnc.execute(destination); @@ -363,59 +244,59 @@ public String getGroup( ) } public String getUserName( ) - { + { return userName; - } + } public String getPassword() - { + { return password; - } + } public String getInstanceNumber( ) - { + { return instanceNumber; - } + } public String getAppServer( ) { return appServer; - } + } public String getRouterString() - { + { return routerString; - } + } public String getClientNumber( ) - { + { return clientNumber; - } + } public String getSystemId() - { + { return systemId; - } + } public String getSessionName( ) - { + { return sessionName; - } + } public String getSAPGUI() - { + { return sapGUI; - } + } public String getPeekLimit() - { + { return peekLimit; - } + } public String getPoolCapacity() - { + { return poolCapacity; - } + } public String getLanguage() { @@ -447,13 +328,11 @@ public String getServerName() return serverName; } - - public String getRepository() + public String getRepositoryName() { - return repository; + return repositoryName; } - /* Setters */ public void setPort( String value ) @@ -496,39 +375,39 @@ public void setUserName( String value ) } public void setPassword( String value ) - { + { password = value; - } + } public void setInstanceNumber( String value ) - { + { instanceNumber = value; - } + } public void setAppServer( String value ) - { + { appServer = value; - } + } public void setRouterString( String value ) - { + { routerString = value; - } + } public void setClientNumber( String value ) - { + { clientNumber = value; - } + } public void setSystemId( String value ) - { + { systemId = value; - } + } public void setSessionName( String value ) { sessionName = value; - } + } public void setSAPGUI( String value ) { @@ -551,12 +430,12 @@ public void setLanguage(String value) } public void setErrorCode( Integer value ) - { + { errorCode = value; - } + } public void setErrorMessage( String value ) - { + { errorMessage = value; } @@ -575,9 +454,9 @@ public void setServerName(String value) serverName = value; } - public void setRepository(String value) + public void setRepositoryName(String value) { - repository = value; + repositoryName = value; } } \ No newline at end of file From 2f5ec9ca0ac1fa61ebd5f779f8a790c8ea56fac8 Mon Sep 17 00:00:00 2001 From: AlejandroP Date: Wed, 23 Nov 2022 14:26:39 -0300 Subject: [PATCH 3/4] - Duplicate method --- java/src/main/java/com/genexus/sap/SessionManager.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/java/src/main/java/com/genexus/sap/SessionManager.java b/java/src/main/java/com/genexus/sap/SessionManager.java index 3abcd77e2..16d9abc0e 100644 --- a/java/src/main/java/com/genexus/sap/SessionManager.java +++ b/java/src/main/java/com/genexus/sap/SessionManager.java @@ -331,12 +331,6 @@ public String getRepositoryName() return repositoryName; } - public String getRepositoryName() - { - return repositoryName; - } - - /* Setters */ public void setPort( String value ) @@ -407,7 +401,6 @@ public void setSystemId( String value ) { systemId = value; } - public void setSessionName( String value ) { @@ -441,7 +434,6 @@ public void setErrorCode( Integer value ) public void setErrorMessage( String value ) { - errorMessage = value; } From ce05f0755f1b77fe30d559ded1e6a580679d2f8b Mon Sep 17 00:00:00 2001 From: AlejandroP Date: Wed, 30 Nov 2022 11:10:35 -0300 Subject: [PATCH 4/4] - Code Cleaning --- .../com/genexus/sap/DestinationProvider.java | 32 ++++---------- .../java/com/genexus/sap/DocumentClient.java | 38 +++++++---------- .../com/genexus/sap/DocumentReceiver.java | 13 +++--- .../java/com/genexus/sap/DocumentSender.java | 15 +++---- .../com/genexus/sap/EnterpriseConnect.java | 42 ++++++++----------- .../java/com/genexus/sap/SessionManager.java | 8 ++-- 6 files changed, 57 insertions(+), 91 deletions(-) diff --git a/java/src/main/java/com/genexus/sap/DestinationProvider.java b/java/src/main/java/com/genexus/sap/DestinationProvider.java index 22d3e0d66..939459e31 100644 --- a/java/src/main/java/com/genexus/sap/DestinationProvider.java +++ b/java/src/main/java/com/genexus/sap/DestinationProvider.java @@ -23,8 +23,8 @@ public static DestinationProvider Instance() return _instance; } - private String SAP_SERVER = "SAP_SERVER"; - private String SAP_DOC_SERVER = "DMS_SERVER"; + private static final String SAP_SERVER = "SAP_SERVER"; + private static final String SAP_DOC_SERVER = "DMS_SERVER"; private Properties connectionProperties; private Hashtable connectionList = new Hashtable(); private DestinationDataEventListener eventListener; @@ -33,16 +33,8 @@ public static DestinationProvider Instance() public Properties getDestinationProperties(String sessionName) { if (sessionName != null) - { - Properties val = connectionList.get(sessionName); - if (val != null) - { - return val; - } - else - { - return null; - } + { + return connectionList.get(sessionName); } else { @@ -65,16 +57,8 @@ public void setDestinationDataEventListener(DestinationDataEventListener eventLi @Override public Properties getServerProperties(String serverName) { if (serverName != null) - { - Properties val = connectionList.get(serverName); - if (val != null) - { - return val; - } - else - { - return null; - } + { + return connectionList.get(serverName); } else { @@ -118,7 +102,7 @@ public void setServerProperties( String serverName, Properties properties) } else { - Log.info("GX SAP Doc Server - Setting Properties : " + serverName + " total : " + Integer.toString(connectionList.size())); + Log.info("GX SAP Doc Server - Setting Properties : " + serverName + " total : " + connectionList.size()); connectionProperties = properties; connectionList.put( serverName, connectionProperties); if (eventListener != null) @@ -160,7 +144,7 @@ public void setConnectionProperties( String sessionName, Properties properties) } else { - Log.info("GX SAP - Setting Properties : " + sessionName + " total : " + Integer.toString(connectionList.size())); + Log.info("GX SAP - Setting Properties : " + sessionName + " total : " + connectionList.size()); connectionProperties = properties; connectionList.put( sessionName, connectionProperties); if (eventListener != null) diff --git a/java/src/main/java/com/genexus/sap/DocumentClient.java b/java/src/main/java/com/genexus/sap/DocumentClient.java index cc12f50fd..c76c5667d 100644 --- a/java/src/main/java/com/genexus/sap/DocumentClient.java +++ b/java/src/main/java/com/genexus/sap/DocumentClient.java @@ -1,24 +1,16 @@ package com.genexus.sap; -import java.io.*; -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; - -import com.sap.conn.jco.AbapClassException; -import com.sap.conn.jco.AbapException; - import com.sap.conn.jco.JCoFunction; import com.sap.conn.jco.JCoParameterList; import com.sap.conn.jco.JCoTable; -import com.sap.conn.jco.server.JCoServer; -import com.sap.conn.jco.server.JCoServerContext; -import com.sap.conn.jco.server.JCoServerContextInfo; -import com.sap.conn.jco.server.JCoServerErrorListener; -import com.sap.conn.jco.server.JCoServerExceptionListener; +import com.sap.conn.jco.server.*; -import com.sap.conn.jco.server.JCoServerFunctionHandler; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.Path; public class DocumentClient { private static final int BLOB_LENGTH = 1022; @@ -43,7 +35,7 @@ public void serverErrorOccurred(JCoServer server, String connectionID, JCoServer static class FTP_R3_TO_CLIENTHandler implements JCoServerFunctionHandler { @Override - public void handleRequest(JCoServerContext serverCtx, JCoFunction function) throws AbapException, AbapClassException { + public void handleRequest(JCoServerContext serverCtx, JCoFunction function) { String fname; int length; JCoTable blob; @@ -67,17 +59,17 @@ public void handleRequest(JCoServerContext serverCtx, JCoFunction function) thro length -= BLOB_LENGTH; hasNextRow = blob.nextRow(); } - else throw new IOException("Not enough data in table BLOB ("+String.valueOf(BLOB_LENGTH * blob.getNumRows())+") for requested file size (" + String.valueOf(length) + ")"); + else throw new IOException("Not enough data in table BLOB ("+ BLOB_LENGTH * blob.getNumRows() +") for requested file size (" + length + ")"); } if (length > 0){ if (hasNextRow) out.write(blob.getByteArray(0), 0, length); - else throw new IOException("Not enough data in table BLOB ("+String.valueOf(BLOB_LENGTH * blob.getNumRows())+") for requested file size (" + String.valueOf(length) + ")"); + else throw new IOException("Not enough data in table BLOB ("+ BLOB_LENGTH * blob.getNumRows() +") for requested file size (" + length + ")"); } } catch (IOException e) { // Unfortunately there is no way of transmitting error details back to SAP, so we better log it here, - // if we want to keep the chance of trouble-shooting later, what exactly went wrong... + // if we want to keep the chance of troubleshooting later, what exactly went wrong... e.printStackTrace(); function.getExportParameterList().setValue("ERROR", 3); @@ -96,19 +88,19 @@ public void handleRequest(JCoServerContext serverCtx, JCoFunction function) thro static class FTP_CLIENT_TO_R3Handler implements JCoServerFunctionHandler { @Override - public void handleRequest(JCoServerContext serverCtx, JCoFunction function) throws AbapException, AbapClassException { + public void handleRequest(JCoServerContext serverCtx, JCoFunction function) { String fname; fname = function.getImportParameterList().getString("FNAME"); fname = fname.replace("#",""); - - try (InputStream source = Files.newInputStream(Paths.get(fname));) { + Path inputFile = Paths.get(fname); + try (InputStream source = Files.newInputStream(inputFile)) { byte[] file2 = new byte[BLOB_LENGTH]; int bytesread; int totallenght =0; - InputStream source2 = Files.newInputStream(Paths.get(fname)); + InputStream source2 = Files.newInputStream(inputFile); JCoTable blobtable = function.getTableParameterList().getTable("BLOB"); while((bytesread = source2.read(file2,0,file2.length)) >0 ) diff --git a/java/src/main/java/com/genexus/sap/DocumentReceiver.java b/java/src/main/java/com/genexus/sap/DocumentReceiver.java index 89f5458bd..0a568e737 100644 --- a/java/src/main/java/com/genexus/sap/DocumentReceiver.java +++ b/java/src/main/java/com/genexus/sap/DocumentReceiver.java @@ -17,10 +17,9 @@ public class DocumentReceiver { - private static final int BLOB_LENGTH = 1022; - private String serverName = ""; - private String repositoryName = ""; - private ModelContext _context = null; + private String serverName; + private String repositoryName; + private ModelContext _context; JCoServer receiver = null; @@ -40,7 +39,7 @@ public void start() } catch (JCoException ex) { - Log.error("GX SAP - Error Starting " + ex.toString()) ; + Log.error("GX SAP - Error Starting " + ex) ; } } @@ -75,7 +74,7 @@ public void stop() } catch (JCoException ex) { - Log.error("GX SAP - Error Stopping " + ex.toString()) ; + Log.error("GX SAP - Error Stopping " + ex) ; } } @@ -99,7 +98,7 @@ public JCoServer setupServerDownload(String serverName, String repositoryName) t exports.lock(); JCoRecordMetaData tabLine = JCo.createRecordMetaData("BLOB"); - tabLine.add("LINE", JCoMetaData.TYPE_BYTE, BLOB_LENGTH, 0, BLOB_LENGTH, 0); + tabLine.add("LINE", JCoMetaData.TYPE_BYTE, EnterpriseConnect.BLOB_LENGTH, 0, EnterpriseConnect.BLOB_LENGTH, 0); tabLine.lock(); tables = JCo.createListMetaData("TABLES"); tables.add("BLOB", JCoMetaData.TYPE_TABLE, tabLine, 0); diff --git a/java/src/main/java/com/genexus/sap/DocumentSender.java b/java/src/main/java/com/genexus/sap/DocumentSender.java index f8a74797a..72e8617fc 100644 --- a/java/src/main/java/com/genexus/sap/DocumentSender.java +++ b/java/src/main/java/com/genexus/sap/DocumentSender.java @@ -10,8 +10,6 @@ import com.sap.conn.jco.server.JCoServer; import com.sap.conn.jco.server.DefaultServerHandlerFactory; -import com.sap.conn.jco.ext.DestinationDataProvider; -import com.sap.conn.jco.ext.ServerDataProvider; import com.sap.conn.jco.server.JCoServerFactory; import com.sap.conn.jco.JCoCustomRepository; import com.sap.conn.jco.JCoFunctionTemplate; @@ -21,10 +19,9 @@ public class DocumentSender { - private static final int BLOB_LENGTH = 1022; - private String serverName = ""; - private String repositoryName = ""; - private ModelContext _context = null; + private String serverName; + private String repositoryName; + private ModelContext _context; JCoServer sender = null; @@ -45,7 +42,7 @@ public void start() } catch (JCoException ex) { - Log.error("GX SAP - Error Starting " + ex.toString()) ; + Log.error("GX SAP - Error Starting " + ex) ; } } @@ -78,7 +75,7 @@ public void stop() } catch (JCoException ex) { - Log.error("GX SAP - Error Stopping " + ex.toString()) ; + Log.error("GX SAP - Error Stopping " + ex) ; } } @@ -101,7 +98,7 @@ public JCoServer setupServerUpload(String serverName, String repositoryName) thr exports.lock(); JCoRecordMetaData tabLine = JCo.createRecordMetaData("BLOB"); - tabLine.add("LINE", JCoMetaData.TYPE_BYTE, BLOB_LENGTH, 0, BLOB_LENGTH, 0); + tabLine.add("LINE", JCoMetaData.TYPE_BYTE, EnterpriseConnect.BLOB_LENGTH, 0, EnterpriseConnect.BLOB_LENGTH, 0); tabLine.lock(); tables = JCo.createListMetaData("TABLES"); diff --git a/java/src/main/java/com/genexus/sap/EnterpriseConnect.java b/java/src/main/java/com/genexus/sap/EnterpriseConnect.java index 6fa64fd47..898954951 100644 --- a/java/src/main/java/com/genexus/sap/EnterpriseConnect.java +++ b/java/src/main/java/com/genexus/sap/EnterpriseConnect.java @@ -1,6 +1,7 @@ package com.genexus.sap; import java.math.BigDecimal; +import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Iterator; @@ -25,7 +26,8 @@ public class EnterpriseConnect { - static String DESTINATION_NAME = "SAP_SERVER"; + static final String DESTINATION_NAME = "SAP_SERVER"; + static final int BLOB_LENGTH = 1022; JCoFunction function = null; String destinationName = DESTINATION_NAME; @@ -47,14 +49,7 @@ public void setValue(String parameterName, String value) setvalue = true; function.getImportParameterList().setValue(parameterName, value); } - if (setvalue) - { - function.getImportParameterList().setActive(parameterName, true); - } - else - { - function.getImportParameterList().setActive(parameterName, false); - } + function.getImportParameterList().setActive(parameterName, setvalue); } public void setValue(String parameterName, int value) @@ -84,7 +79,7 @@ public void setValue(String parameterName, double value) public void setValue(String parameterName, Date value) { GregorianCalendar calendar = new GregorianCalendar(); - calendar.set(0, 0, 0); + calendar.set(0, Calendar.JANUARY, 0); Date baseDate = calendar.getTime(); if (value != null && value.after(baseDate)) { @@ -99,7 +94,7 @@ public void setValue(String parameterName, Date value) // I/O parameter - public void setValue(String parameterName, GXSimpleCollection[] value, Boolean inOut) + public void setValue(String parameterName, GXSimpleCollection[] value, Boolean inOut) { if (value != null && value.length > 0) { @@ -107,8 +102,7 @@ public void setValue(String parameterName, GXSimpleCollection[] value, Boolean i } } - - public void setValue(String parameterName, GXSimpleCollection[] value) + public void setValue(String parameterName, GXSimpleCollection[] value) { if (value != null && value.length > 0) { @@ -125,16 +119,16 @@ public void setValue(String parameterName, IGxJSONAble[] value) } // ------ - public void setValue(String parameterName, GXSimpleCollection value) + public void setValue(String parameterName, GXSimpleCollection value) { setValue(parameterName, value, false); } - public void setValue(String parameterName, GXSimpleCollection value, Boolean inOut) + public void setValue(String parameterName, GXSimpleCollection value, Boolean inOut) { JCoTable jTable = function.getTableParameterList().getTable(parameterName); - Boolean setValues = false; + boolean setValues = false; try{ for (int i = 1; i <= value.getItemCount(); i++) { @@ -184,7 +178,7 @@ else if (jcoType == JCoMetaData.TYPE_INT2 || jcoType == JCoMetaData.TYPE_INT1 } else { - System.out.println( key + " Invalid Type " + Integer.toString(jcoType)); + System.out.println( key + " Invalid Type " + jcoType); } } } @@ -241,7 +235,7 @@ else if (jcoType == JCoMetaData.TYPE_INT2 || jcoType == JCoMetaData.TYPE_INT1 } else { - System.out.println( key + " Invalid Type " + Integer.toString(jcoType)); + System.out.println( key + " Invalid Type " + jcoType); } } function.getImportParameterList().setActive(parameterName, true); @@ -260,11 +254,11 @@ else if (jcoType == JCoMetaData.TYPE_INT2 || jcoType == JCoMetaData.TYPE_INT1 /* --- Get Return Values --- */ - public void getValue(String parameterName, GXSimpleCollection[] value) + public void getValue(String parameterName, GXSimpleCollection[] value) { if (value.length != 0) { - GXSimpleCollection col = value[0]; + GXSimpleCollection col = value[0]; col.clear(); JCoTable tbl = function.getTableParameterList().getTable(parameterName); JSONArray jCol = new JSONArray(); @@ -386,7 +380,7 @@ public void executeStart(String functionName) } catch (JCoException e) { - throw new RuntimeException("JCoException: " + e.toString()); + throw new RuntimeException("JCoException: " + e); } } @@ -407,7 +401,7 @@ public void executeStart(String functionName, boolean isTransaction) throws JCoE } catch (AbapException e) { - throw new RuntimeException(" ABAP Exception: " + e.toString()); + throw new RuntimeException(" ABAP Exception: " + e); } } @@ -419,7 +413,7 @@ public int executeFunction(String functionName) } catch (JCoException e) { - throw new RuntimeException("JCoException excecuting: " + e.toString()); + throw new RuntimeException("JCoException excecuting: " + e); } } @@ -438,7 +432,7 @@ public int executeFunction(String functionName, boolean isTransaction) throws JC } catch (AbapException e) { - throw new RuntimeException( "ABAP exception executing: " + e.toString()); + throw new RuntimeException( "ABAP exception executing: " + e); } return 0; } diff --git a/java/src/main/java/com/genexus/sap/SessionManager.java b/java/src/main/java/com/genexus/sap/SessionManager.java index 16d9abc0e..a6415aa6f 100644 --- a/java/src/main/java/com/genexus/sap/SessionManager.java +++ b/java/src/main/java/com/genexus/sap/SessionManager.java @@ -89,22 +89,22 @@ public void ConnectInternal(String session, String sessionName, String scope) { errorCode = ex.getGroup(); errorMessage = ex.toString(); - Log.warning("GX SAP - Error Connecting " + sessionName + " " + ex.toString()) ; + Log.warning("GX SAP - Error Connecting " + sessionName + " " + ex) ; } catch (JCoException ex) { if(ex.getGroup() == JCoException.JCO_ERROR_INTERNAL) { - Log.error("GX SAP - Error Connecting " + sessionName + " " + ex.toString()) ; + Log.error("GX SAP - Error Connecting " + sessionName + " " + ex) ; throw new RuntimeException(ex.toString()); } errorCode = ex.getGroup(); errorMessage = ex.toString(); - Log.warning("GX SAP - Error Connecting " + sessionName + " " + ex.toString()) ; + Log.warning("GX SAP - Error Connecting " + sessionName + " " + ex) ; } catch (Exception ex) { - Log.error("GX SAP - Error Connecting " + sessionName + " " + ex.toString()) ; + Log.error("GX SAP - Error Connecting " + sessionName + " " + ex) ; throw new RuntimeException(ex.toString()); } }