/** * Method to safely execute a function. * * @param connection * @param input The MappedRecord containing the input arguments. * @return The MappedRecord containing the results or null if the call fails. */ public MappedRecord executeFunction(String returnTableKey) { /* * Create the connection and interaction */ createConnectionInteraction(); /* * Retrieve the mapped record */ MappedRecord outputRecord = null; try { if (inputRecord == null) { getInputRecord(); } outputRecord = (MappedRecord) interaction.execute(null, inputRecord); } catch (ResourceException e) { TransactionHelper.logAndThrowDataException( callingFunctionName, "Failure executing function: ", e); } if (outputRecord == null) { TransactionHelper.logAndThrowDataException(callingFunctionName, "Output record null ", null); } /* * Check for BAPI errors */ TransactionHelper.errorMessagesReturned( validationMap, outputRecord, returnTableKey, this.callingFunctionName); return outputRecord; }
/** * This method opens a connection and the interaction. * * @return True if successful, false if not. */ public void createConnectionInteraction() { if (this.connectionFactory == null) { TransactionHelper.logAndThrowDataException( callingFunctionName, "Failure looking up a connection factory for resource name: " + resourceName, null); } try { /* * Get a connection from the connection factory. Requires that * setupConnectionFactory was called successfully beforehand. */ connection = connectionFactory.getConnection(); /* * Create an interaction object to make a call to an SAP system * where you can send your business data and receive data back: */ interaction = connection.createInteraction(); } catch (Throwable e) { TransactionHelper.logAndThrowDataException( callingFunctionName, "Failure getting connection for resource name: " + resourceName, e); } }
/** * This method safely looks up a record factory from the connection factory. * * <p>If the JRA connection is going to fail, it will fail in this step. For example, if the * service account password expires, then there will be an authorization error in the * createMappedRecord call. * * @param transactionObject * @param functionName The BAPI name for which we get the mapped record. * @return A RecordFactory object or null if there is an error. */ public MappedRecord getInputRecord() { try { if (null == inputRecord) { inputRecord = recordFactory.createMappedRecord(functionName); } } catch (Throwable e) { /* * Experience has shown that, if the JRA connection fails, it fails * in this method. Usually the problem is that the service account * is no longer authenticating. */ TransactionHelper.logAndThrowDataException( callingFunctionName, "Failure getting a mapped record for function: " + functionName + " in resource: ", e); } return inputRecord; }
/** * Added by Kunal Jaggi Method to safely execute a function. * * @param input The MappedRecord containing the input arguments. * @return The MappedRecord containing the results or null if the call fails. */ public MappedRecord executeFunction(MappedRecord input) { /* * Create the connection and interaction */ createConnectionInteraction(); /* * Retrieve the mapped record */ MappedRecord outputRecord = null; try { outputRecord = (MappedRecord) interaction.execute(null, input); } catch (ResourceException e) { TransactionHelper.logAndThrowDataException( callingFunctionName, "Failure executing function: " + functionName + " in resource: " + resourceName, e); } return outputRecord; }