use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class SqlConnector method prepareForTransaction.
public void prepareForTransaction(Context context) throws EngineException {
SqlTransaction sqlTransaction = null;
try {
sqlTransaction = (SqlTransaction) context.requestedObject;
} catch (ClassCastException e) {
throw new EngineException("Requested object is not a SQL transaction", e);
}
if (Engine.isEngineMode() && KeyManager.getCV(Session.EmulIDSQL) < 1) {
String msg;
if (KeyManager.has(Session.EmulIDSQL) && KeyManager.hasExpired(Session.EmulIDSQL)) {
Engine.logEngine.error(msg = "Key expired for the SQL connector.");
throw new KeyExpiredException(msg);
}
Engine.logEngine.error(msg = "No key for the SQL connector.");
throw new MaxCvsExceededException(msg);
}
// Overwrites JDBC url, user and password if needed (#369)
String variableValue = sqlTransaction.getParameterStringValue(Parameter.ConnectorConnectionString.getName());
if (variableValue != null && !variableValue.isEmpty()) {
if (!variableValue.equals(getJdbcURL()) && !variableValue.equals(getOverJdbcURL())) {
setOverJdbcURL(variableValue);
Engine.logBeans.debug("(SqlConnector) Connection string overriden!");
}
}
Engine.logBeans.debug("(SqlConnector) JDBC URL: " + getConnectionJdbcURL());
}
use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class SqlConnector method executeSearch.
public static Document executeSearch(SqlConnector sqlConnector, String pattern) throws EngineException, ClassNotFoundException, SQLException {
Document doc = SqlTransaction.createDOM("UTF-8");
if (sqlConnector != null) {
sqlConnector.open();
ResultSet rs = null;
try {
Connection connection = sqlConnector.connection;
DatabaseMetaData dmd = connection.getMetaData();
String catalog = connection.getCatalog();
Element item, child;
Element root = (Element) doc.appendChild(doc.createElement("items"));
// Retrieve all stored procedures
rs = dmd.getProcedures(catalog, null, pattern);
if (rs != null) {
while (rs.next()) {
item = (Element) root.appendChild(doc.createElement("item"));
String callableName = rs.getString("PROCEDURE_NAME");
int index = callableName.indexOf(";");
if (index != -1) {
// seen for ms sql server
callableName = callableName.substring(0, index);
}
child = (Element) item.appendChild(doc.createElement("NAME"));
child.appendChild(doc.createTextNode(callableName));
try {
child.setAttribute("specific_name", rs.getString("SPECIFIC_NAME"));
} catch (Exception e) {
}
String callableDesc = rs.getString("REMARKS");
child = (Element) item.appendChild(doc.createElement("REMARKS"));
child.appendChild(doc.createTextNode(callableDesc));
child = (Element) item.appendChild(doc.createElement("TYPE"));
child.appendChild(doc.createTextNode(index == -1 ? "PROCEDURE" : "FUNCTION"));
}
rs.close();
rs = null;
}
// Retrieve all stored functions
rs = dmd.getFunctions(catalog, null, pattern);
if (rs != null) {
while (rs.next()) {
item = (Element) root.appendChild(doc.createElement("item"));
// "FUNCTION_NAME");
String callableName = rs.getString(3);
child = (Element) item.appendChild(doc.createElement("NAME"));
child.appendChild(doc.createTextNode(callableName));
try {
child.setAttribute("specific_name", rs.getString("SPECIFIC_NAME"));
} catch (Exception e) {
}
String callableDesc = rs.getString("REMARKS");
child = (Element) item.appendChild(doc.createElement("REMARKS"));
child.appendChild(doc.createTextNode(callableDesc));
child = (Element) item.appendChild(doc.createElement("TYPE"));
child.appendChild(doc.createTextNode("FUNCTION"));
}
rs.close();
rs = null;
}
} catch (Throwable t) {
t.printStackTrace();
} finally {
if (rs != null) {
rs.close();
}
rs = null;
}
sqlConnector.close();
// System.out.println(XMLUtils.prettyPrintDOM(doc));
}
return doc;
}
use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class SqlConnector method configure.
@Override
public void configure(Element element) throws Exception {
super.configure(element);
String version = element.getAttribute("version");
if (version == null) {
String s = XMLUtils.prettyPrintDOM(element);
EngineException ee = new EngineException("Unable to find version number for the database object \"" + getName() + "\".\n" + "XML data: " + s);
throw ee;
}
if (VersionUtils.compare(version, "4.6.0") < 0) {
if ((jdbcURL.startsWith("jdbc:hsqldb:file:")) && (jdbcURL.indexOf("/WEB-INF/minime/") != -1)) {
StringEx sx = new StringEx(jdbcURL);
sx.replace("/WEB-INF/minime/", "/WEB-INF/databases/");
jdbcURL = sx.toString();
hasChanged = true;
Engine.logBeans.warn("[SqlConnector] Successfully updated connection string for \"" + getName() + "\" (v 4.6.0)");
}
}
}
use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class SequenceStep method configure.
@Override
public void configure(Element element) throws Exception {
super.configure(element);
String version = element.getAttribute("version");
if (version == null) {
String s = XMLUtils.prettyPrintDOM(element);
EngineException ee = new EngineException("Unable to find version number for the database object \"" + getName() + "\".\nXML data: " + s);
throw ee;
}
try {
if (VersionUtils.compare(version, "6.0.3") < 0) {
String projectName = (String) XMLUtils.findPropertyValue(element, "projectName");
// Handle wrong project name
if (projectName.equals("")) {
projectName = "unknown_project";
}
String sequenceName = (String) XMLUtils.findPropertyValue(element, "sequenceName");
// Handle wrong sequence name
if (sequenceName.equals("")) {
sequenceName = "unknown_sequence";
}
String sourceSequence = projectName + SequenceStep.SOURCE_SEPARATOR + sequenceName;
setSourceSequence(sourceSequence);
hasChanged = true;
Engine.logBeans.warn("[SequenceStpe] The object \"" + getName() + "\" has been updated to version 6.0.3; source sequence: " + sourceSequence);
}
} catch (Exception e) {
throw new EngineException("Unable to migrate the source definition for CallSequence step \"" + getName() + "\".", e);
}
}
use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.
the class SequenceStep method prepareForRequestable.
protected void prepareForRequestable(Context javascriptContext, Scriptable scope) throws MalformedURLException, EngineException {
Sequence targetSequence = getTargetSequence();
if (Engine.isStudioMode()) {
if (targetSequence != null) {
if (sequence.getOriginal().equals(targetSequence.getOriginal())) {
throw new EngineException("Execution of recursive sequence is not allowed in Studio mode!");
}
}
}
String ctxName = getContextName(javascriptContext, scope);
boolean useSequenceJSession = sequence.useSameJSessionForSteps();
boolean maintainContext = useSequenceJSession && !ctxName.startsWith("Container-");
boolean maintainSession = useSequenceJSession;
boolean inheritContex = inheritTransactionCtx && sequence.equals(getTransactionContextMaintainer());
String inheritedCxtName = sequence.getInheritedContextName();
inheritedCxtName = (inheritContex && (inheritedCxtName == null)) ? sequence.getContextName() : inheritedCxtName;
inheritedCxtName = (inheritedCxtName == null) ? "" : inheritedCxtName;
if (isInternalInvoke()) {
request.put(Parameter.Project.getName(), new String[] { projectName });
request.put(Parameter.MotherSequenceContext.getName(), new String[] { sequence.context.contextID });
request.put(Parameter.Sequence.getName(), new String[] { targetSequence.getName() });
request.put(Parameter.Context.getName(), new String[] { sequence.addStepContextName(ctxName) });
request.put(Parameter.SequenceInheritedTransactionContext.getName(), inheritContex ? new String[] { inheritedCxtName } : new String[] { "" });
if (!maintainContext)
request.put(Parameter.RemoveContext.getName(), new String[] { "" });
if (!maintainSession)
request.put(Parameter.RemoveSession.getName(), new String[] { "" });
getPostQuery(scope);
} else {
targetUrl = EnginePropertiesManager.getProperty(PropertyName.APPLICATION_SERVER_CONVERTIGO_URL);
targetUrl += "/projects/" + projectName + "/.xml?";
URL url = new URL(targetUrl);
String host = url.getHost();
int port = url.getPort();
Engine.logBeans.trace("(SequenceStep) Host: " + host + ":" + port);
hostConfiguration.setHost(host, port);
// Retrieves new HttpState!!
// This will force a new http session on convertigo server : new context for sequence
httpState = sequence.getNewHttpState();
method = new PostMethod(targetUrl);
method.setRequestHeader("Content-Type", MimeType.WwwForm.value());
// Set transaction sessionId from context maintainer
String sessionId = getTransactionSessionId();
if (useSequenceJSession) {
Engine.logBeans.trace("(SequenceStep) JSESSIONID required : " + sessionId);
if (sessionId != null) {
method.setRequestHeader("Cookie", "JSESSIONID=" + sessionId + ";");
Engine.logBeans.trace("(SequenceStep) JSESSIONID used : " + sessionId);
} else {
Engine.logBeans.trace("(SequenceStep) JSESSIONID is null");
}
} else {
if (sessionId != null) {
method.addRequestHeader("Transaction-JSessionId", sessionId);
Engine.logBeans.trace("(SequenceStep) Transaction JSESSIONID used : " + sessionId);
} else {
Engine.logBeans.trace("(SequenceStep) Transaction JSESSIONID is null");
}
}
String postQuery = getPostQuery(scope);
if (!maintainContext && (postQuery.indexOf(Parameter.RemoveContext.getName()) == -1))
postQuery = addParamToPostQuery(Parameter.RemoveContext.getName(), "", postQuery);
if (!maintainSession && (postQuery.indexOf(Parameter.RemoveSession.getName()) == -1))
postQuery = addParamToPostQuery(Parameter.RemoveSession.getName(), "", postQuery);
if (postQuery.indexOf(Parameter.SequenceInheritedTransactionContext.getName()) == -1)
postQuery = addParamToPostQuery(Parameter.SequenceInheritedTransactionContext.getName(), inheritContex ? inheritedCxtName : "", postQuery);
if (postQuery.indexOf(Parameter.Sequence.getName()) == -1)
postQuery = addParamToPostQuery(Parameter.Sequence.getName(), targetSequence.getName(), postQuery);
if (postQuery.indexOf(Parameter.Context.getName()) == -1)
postQuery = addParamToPostQuery(Parameter.Context.getName(), sequence.addStepContextName(ctxName), postQuery);
if (postQuery.indexOf(Parameter.MotherSequenceContext.getName()) == -1)
postQuery = addParamToPostQuery(Parameter.MotherSequenceContext.getName(), sequence.context.contextID, postQuery);
if (Engine.logBeans.isTraceEnabled())
Engine.logBeans.trace("(SequenceStep) postQuery :" + Visibility.Logs.replaceVariables(getVariables(), postQuery));
try {
method.setRequestEntity(new StringRequestEntity(postQuery, null, "UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new EngineException("Encoding error", e);
}
}
}
Aggregations