Search in sources :

Example 46 with EngineException

use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.

the class Save method getServiceResult.

@Override
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    String qname = request.getParameter("qname");
    DatabaseObject dbo = Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
    Element response = document.createElement("response");
    if (dbo != null) {
        try {
            Engine.theApp.databaseObjectsManager.exportProject(dbo.getProject());
            response.setAttribute("status", "success");
            response.setAttribute("message", "Successfully saved project.");
        } catch (EngineException e) {
            throw e;
        }
    } else {
        throw new EngineException("The project does not exist.");
    }
    document.getDocumentElement().appendChild(response);
}
Also used : Element(org.w3c.dom.Element) EngineException(com.twinsoft.convertigo.engine.EngineException) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Example 47 with EngineException

use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.

the class GoogleAnalyticsTicketManager method prepareHttpClient.

private HttpClient prepareHttpClient(String[] url) throws EngineException, MalformedURLException {
    final Pattern scheme_host_pattern = Pattern.compile("https://(.*?)(?::([\\d]*))?(/.*|$)");
    HttpClient client = new HttpClient();
    HostConfiguration hostConfiguration = client.getHostConfiguration();
    HttpState httpState = new HttpState();
    client.setState(httpState);
    if (proxyManager != null) {
        proxyManager.getEngineProperties();
        proxyManager.setProxy(hostConfiguration, httpState, new URL(url[0]));
    }
    Matcher matcher = scheme_host_pattern.matcher(url[0]);
    if (matcher.matches()) {
        String host = matcher.group(1);
        String sPort = matcher.group(2);
        int port = 443;
        try {
            port = Integer.parseInt(sPort);
        } catch (Exception e) {
        }
        try {
            Protocol myhttps = new Protocol("https", MySSLSocketFactory.getSSLSocketFactory(null, null, null, null, true), port);
            hostConfiguration.setHost(host, port, myhttps);
            url[0] = matcher.group(3);
        } catch (Exception e) {
            e.printStackTrace();
            e.printStackTrace();
        }
    }
    return client;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) HostConfiguration(org.apache.commons.httpclient.HostConfiguration) HttpClient(org.apache.commons.httpclient.HttpClient) HttpState(org.apache.commons.httpclient.HttpState) Protocol(org.apache.commons.httpclient.protocol.Protocol) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) HttpException(org.apache.commons.httpclient.HttpException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 48 with EngineException

use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.

the class DatabaseCacheManager method storeResponse.

protected CacheEntry storeResponse(Document response, String requestString, long expiryDate) throws EngineException {
    try {
        storeWeakResponse(response, requestString);
        Engine.logCacheManager.debug("Trying to store the response in the cache Database");
        sqlRequester.checkConnection();
        StringEx sqlRequest = new StringEx(sqlRequester.getProperty(DatabaseCacheManager.PROPERTIES_SQL_REQUEST_STORE_RESPONSE));
        String cacheTableName = sqlRequester.getProperty(DatabaseCacheManager.PROPERTIES_SQL_CACHE_TABLE_NAME, "CacheTable");
        sqlRequest.replace("CacheTable", cacheTableName);
        String jdbcURL = sqlRequester.getProperty(SqlRequester.PROPERTIES_JDBC_URL);
        boolean isSqlServerDatabase = jdbcURL.indexOf(":sqlserver:") != -1;
        boolean isOracleServerDatabase = jdbcURL.indexOf(":oracle:") != -1;
        if (!isSqlServerDatabase) {
            sqlRequest.replace("[Transaction]", "Transaction");
        }
        String xml = XMLUtils.prettyPrintDOM(response);
        sqlRequest.replace("{Xml}", escapeString(xml));
        sqlRequest.replace("{RequestString}", escapeString(requestString));
        sqlRequest.replace("{ExpiryDate}", Long.toString(expiryDate));
        Element documentElement = response.getDocumentElement();
        String project = documentElement.getAttribute("project");
        sqlRequest.replace("{Project}", project);
        String transaction = documentElement.getAttribute("transaction");
        sqlRequest.replace("{Transaction}", transaction);
        String sSqlRequest = sqlRequest.toString();
        Engine.logCacheManager.debug("SQL: " + sSqlRequest);
        // INSERT INTO CacheTable (Xml, ExpiryDate, RequestString, Project, [Transaction]) VALUES (XMLTYPE(?), {ExpiryDate}, '{RequestString}', '{Project}', '{Transaction}')
        if (isOracleServerDatabase && sSqlRequest.toUpperCase().indexOf("XMLTYPE(?)") != -1) {
            PreparedStatement statement = null;
            java.sql.Clob clb = null;
            try {
                xml = escapeString(xml);
                clb = sqlRequester.connection.createClob();
                clb.setString(1, xml);
                statement = sqlRequester.connection.prepareStatement(sSqlRequest);
                statement.setClob(1, clb);
                int nResult = statement.executeUpdate();
                Engine.logCacheManager.debug(nResult + " row(s) inserted (Xml length=" + xml.length() + ").");
            } finally {
                if (clb != null) {
                    clb.free();
                }
                if (statement != null) {
                    statement.close();
                }
            }
        } else // Other cases
        // INSERT INTO CacheTable (Xml, ExpiryDate, RequestString, Project, [Transaction]) VALUES ('{Xml}', {ExpiryDate}, '{RequestString}', '{Project}', '{Transaction}')
        {
            Statement statement = null;
            try {
                statement = sqlRequester.connection.createStatement();
                int nResult = statement.executeUpdate(sSqlRequest);
                Engine.logCacheManager.debug(nResult + " row(s) inserted.");
            } finally {
                if (statement != null) {
                    statement.close();
                }
            }
        }
        DatabaseCacheEntry cacheEntry = new DatabaseCacheEntry();
        cacheEntry.requestString = requestString;
        cacheEntry.id = getId(requestString);
        cacheEntry.expiryDate = expiryDate;
        Engine.logCacheManager.debug("The response has been stored: [" + cacheEntry + "]");
        storeWeakEntry(cacheEntry);
        return cacheEntry;
    } catch (Exception e) {
        throw new EngineException("Unable to store the response! (requestString: " + requestString + ")", e);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Element(org.w3c.dom.Element) EngineException(com.twinsoft.convertigo.engine.EngineException) PreparedStatement(java.sql.PreparedStatement) StringEx(com.twinsoft.util.StringEx) IOException(java.io.IOException) SQLException(java.sql.SQLException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 49 with EngineException

use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.

the class DatabaseCacheManager method init.

public void init() throws EngineException {
    super.init();
    try {
        sqlRequester = new SqlRequester(DB_PROP_FILE_NAME);
        sqlRequester.open();
    } catch (IOException e) {
        throw new EngineException("[DatabaseCacheManager] Unable to load the SQLRequester properties file: " + DB_PROP_FILE_NAME, e);
    } catch (SQLException e) {
        throw new EngineException("[DatabaseCacheManager] Unable to establish connection with the dataBase.", e);
    } catch (ClassNotFoundException e) {
        throw new EngineException("[DatabaseCacheManager] Unable to load JDBC Driver.", e);
    }
}
Also used : SQLException(java.sql.SQLException) EngineException(com.twinsoft.convertigo.engine.EngineException) SqlRequester(com.twinsoft.convertigo.engine.util.SqlRequester) IOException(java.io.IOException)

Example 50 with EngineException

use of com.twinsoft.convertigo.engine.EngineException in project convertigo by convertigo.

the class FileCacheManager method removeStoredResponseImpl.

protected synchronized void removeStoredResponseImpl(CacheEntry cacheEntry) throws EngineException {
    FileCacheEntry fileCacheEntry = (FileCacheEntry) cacheEntry;
    // Cache entry for index? Then ignore
    if (cacheEntry.requestString == null)
        return;
    File file = new File(fileCacheEntry.fileName);
    if ((file.exists()) && (!file.delete())) {
        throw new EngineException("Unable to remove the cache entry [" + cacheEntry.toString() + "] from the cache!");
    }
    Engine.logCacheManager.debug("The cache entry [" + cacheEntry.toString() + "] has been successfully removed.");
}
Also used : EngineException(com.twinsoft.convertigo.engine.EngineException) File(java.io.File)

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