Author Message
bhand
Joined: Oct 23, 2015
Messages: 6
Offline
Hello all

I wrote a try with resources block in an AAOD Servlet ( extends com.avaya.sce.runtime.BasicServlet ) that is setting up a connection to a Teradata DB instance that I am trying to query against.

The try with resources is a language feature that works with JDK 7 and 8. All works well in my project when ran in the AAOD simulator.

However, when I go to export the project with a right click on the project -> choose export -> select "Export Orchestration Designer Speech Project" -> Next -> select my project -> select experience portal -> apache tomcat 7.0 -> next -> select regenerate and rebuild application -> next -> finish. I get a javac error that indicates that the build script is running source as 1.6 compatibility. The exact error I get is:

108. ERROR in C:\AAOD7.0.1\workspace\DB_Validation\temp.folder\source\flow\TeradataDB.java (at line 71)
[javac] try (Connection con = getJNDIConnection(Test);
[javac] PreparedStatement stmt = con.prepareStatement(sMacroExec);
[javac] ResultSet rs = stmt.executeQuery()) {
[javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[javac] Resource specification not allowed here for source level below 1.7

I checked the project and workspace settings in AAOD and the compiler is set to 1.7 compliance.

Is there a way to force the export build script/process to run under 1.7 source compatibility?

Thank you for any insights

NeilGoldsmith
Joined: Nov 6, 2013
Messages: 902
Offline
Check your preferences->Ant->runtime settings and make sure they are not pointing to an older version of Java.

Do you only have 1 JRE on your machine?
bhand
Joined: Oct 23, 2015
Messages: 6
Offline
Neil

Thank you for your quick reply.

However, unless I am missing something. Going to preferences -> ant -> runtime -> global entries -> shows jdk 1.7.0_67\lib\tools.jar

I have 64 and 32 bit versions of the jre 7 and 8 and the same with jdk 7 and 8 on my machine. All of which supports try with resources.

I suspect there is a target=1.6 in an ant script somewhere but the export function creates it runs and deletes it before I can see what it may/may not have.

Any other thoughts?

Thanks
NeilGoldsmith
Joined: Nov 6, 2013
Messages: 902
Offline
What version of OD and Eclipse are you running?

Can you show me the full content of the servlet code you wrote? Also, any jars I might need for the Teradata DB? I can try it locally and see what is going on.
bhand
Joined: Oct 23, 2015
Messages: 6
Offline
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;
}
}
NeilGoldsmith
Joined: Nov 6, 2013
Messages: 902
Offline
I tried this in our upcoming 7.1 release using Eclipse 4.4 (Luna) and it works fine. When I went back to Eclipse 4.2 and OD 7.01, I got a similar compatibility error even though I was using the same JDK that I used in Eclipse 4.4. I suspect if you move to Eclipse 4.4 this issue should go away. I do not have a combination of Eclipse 4.4 with OD 7.01 to try it on though.
Go to:   
Mobile view