Thank you in advance for taking a look.
Answers to your questions:
Eclipse Juno Version: 4.2.2
AAOD 7.0.1.0804
Teradata jars not required. I am just doing a stock JNDI lookup and you should be able to insert your own DB connection to whatever JNDI DB connection you may have. The "Test" variable is expected to be in the form of "java:comp/env/jdbc/<your_db_here>"
I have set up the JNDI Resources in the tomcat server.xml and context.xml appropriately and know they are working. Tomcat version is 7.0.55 but I don't think that will matter.
Code follows:
package flow;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import com.avaya.sce.runtimecommon.IVariableField;
/**
* A basic servlet which allows a user to define their code, generate any
* output, and to select where to transition to next. Last generated by
* Orchestration Designer at: 2016-JAN-06 01:44:39 PM
*/
public class TeradataDB extends com.avaya.sce.runtime.BasicServlet {
// {{START:CLASS:FIELDS
// }}END:CLASS:FIELDS
/**
* Default constructor Last generated by Orchestration Designer at:
* 2016-JAN-06 01:44:39 PM
*/
public TeradataDB() {
// {{START:CLASS:CONSTRUCTOR
super();
// }}END:CLASS:CONSTRUCTOR
}
/**
* This method allows for custom integration with other Java components. You
* may use Java for sophisticated logic or to integrate with custom
* connectors (i.e. JMS, custom web services, sockets, XML, JAXB, etc.)
*
* Any custom code added here should work as efficiently as possible to
* prevent delays. It's important to design your callflow so that the voice
* browser (Voice Portal/IR) is not waiting too long for a response as this
* can lead to a poor caller experience. Additionally, if the response to
* the client voice browser exceeds the configured timeout, the platform may
* throw an "error.badfetch".
*
* Using this method, you have access to all session variables through the
* SCESession object.
*
* The code generator will *** NOT *** overwrite this method in the future.
* Last generated by Orchestration Designer at: 2016-JAN-06 01:44:39 PM
*/
public void servletImplementation(
com.avaya.sce.runtimecommon.SCESession mySession) {
System.out.println("Test started. \n");
IVariableField ENV = mySession
.getVariableField(IProjectVariables.VAR__ENVIRONMENT);
String Environment = ENV.getStringValue();
IVariableField TURL = mySession
.getVariableField(IProjectVariables.VAR__URLTEST);
String Test = TURL.getStringValue();
IVariableField PURL = mySession
.getVariableField(IProjectVariables.VAR__URLPROD);
String Prod = PURL.getStringValue();
System.out.println("\n Test connection string = " + Test);
System.out.println("\n Prod connection string = " + Prod);
final String sMacroExec = "select id from foobar";
try (Connection con = getJNDIConnection(Test);
PreparedStatement stmt = con.prepareStatement(sMacroExec);
ResultSet rs = stmt.executeQuery()) {
int rowCount = 0;
while (rs.next()) {
rowCount++;
}
System.out.println("\n " + rowCount + " row(s) returned.");
IVariableField rows = mySession
.getVariableField(IProjectVariables.VAR__RETURN);
rows.setValue(rowCount);
} catch (SQLException se) {
System.out.println("SQLException occured");
}
}
/**
* Builds the list of branches that are defined for this servlet object.
* This list is built automatically by defining Goto nodes in the call flow
* editor. It is the programmer's responsibilty to provide at least one
* enabled Goto.<BR>
*
* The user should override updateBranches() to determine which Goto that
* the framework will activate. If there is not at least one enabled Goto
* item, the framework will throw a runtime exception.<BR>
*
* This method is generated automatically and changes to it may be
* overwritten next time code is generated. To modify the list of branches
* for the flow item, override:
* <code>updateBranches(Collection branches, SCESession mySession)</code>
*
* @return a Collection of <code>com.avaya.sce.runtime.Goto</code> objects
* that will be evaluated at runtime. If there are no gotos defined
* in the Servlet node, then this returns null. Last generated by
* Orchestration Designer at: 2016-JAN-11 01:12:41 PM
*/
public java.util.Collection getBranches(
com.avaya.sce.runtimecommon.SCESession mySession) {
java.util.List list = null;
com.avaya.sce.runtime.Goto aGoto = null;
list = new java.util.ArrayList(1);
aGoto = new com.avaya.sce.runtime.Goto("annResult", 0, true, "Default");
list.add(aGoto);
return list;
}
private Connection getJNDIConnection(String JNDIDatasource) {
Connection result = null;
try {
Context initialContext = new InitialContext();
DataSource datasource = (DataSource) initialContext
.lookup(JNDIDatasource);
result = datasource.getConnection();
} catch (SQLException se) {
System.out.println("Can not get dataSource (SQLException)");
return null;
} catch (NamingException ne) {
System.out.println("Can not get datasource (NamingException)");
return null;
}
return result;
}
}
|