Search in sources :

Example 21 with EngineException

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());
}
Also used : KeyExpiredException(com.twinsoft.convertigo.engine.KeyExpiredException) EngineException(com.twinsoft.convertigo.engine.EngineException) SqlTransaction(com.twinsoft.convertigo.beans.transactions.SqlTransaction) MaxCvsExceededException(com.twinsoft.convertigo.engine.MaxCvsExceededException)

Example 22 with EngineException

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;
}
Also used : Element(org.w3c.dom.Element) ResultSet(java.sql.ResultSet) Connection(java.sql.Connection) Document(org.w3c.dom.Document) DatabaseMetaData(java.sql.DatabaseMetaData) NamingException(javax.naming.NamingException) SQLException(java.sql.SQLException) MaxCvsExceededException(com.twinsoft.convertigo.engine.MaxCvsExceededException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) KeyExpiredException(com.twinsoft.convertigo.engine.KeyExpiredException) EngineException(com.twinsoft.convertigo.engine.EngineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 23 with EngineException

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)");
        }
    }
}
Also used : EngineException(com.twinsoft.convertigo.engine.EngineException) StringEx(com.twinsoft.util.StringEx)

Example 24 with EngineException

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);
    }
}
Also used : EngineException(com.twinsoft.convertigo.engine.EngineException) URIException(org.apache.commons.httpclient.URIException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) EngineException(com.twinsoft.convertigo.engine.EngineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 25 with EngineException

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);
        }
    }
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) PostMethod(org.apache.commons.httpclient.methods.PostMethod) EngineException(com.twinsoft.convertigo.engine.EngineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Sequence(com.twinsoft.convertigo.beans.core.Sequence) GenericSequence(com.twinsoft.convertigo.beans.sequences.GenericSequence) URL(java.net.URL)

Aggregations

EngineException (com.twinsoft.convertigo.engine.EngineException)426 IOException (java.io.IOException)155 File (java.io.File)117 Element (org.w3c.dom.Element)84 NodeList (org.w3c.dom.NodeList)64 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)62 Document (org.w3c.dom.Document)43 JSONObject (org.codehaus.jettison.json.JSONObject)41 Node (org.w3c.dom.Node)40 Project (com.twinsoft.convertigo.beans.core.Project)35 ArrayList (java.util.ArrayList)35 JSONException (org.codehaus.jettison.json.JSONException)33 Sequence (com.twinsoft.convertigo.beans.core.Sequence)31 RequestableVariable (com.twinsoft.convertigo.beans.variables.RequestableVariable)29 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)27 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)25 Connector (com.twinsoft.convertigo.beans.core.Connector)24 HashMap (java.util.HashMap)23 Transaction (com.twinsoft.convertigo.beans.core.Transaction)21 ObjectWithSameNameException (com.twinsoft.convertigo.engine.ObjectWithSameNameException)20