Search in sources :

Example 26 with StringEx

use of com.twinsoft.util.StringEx in project convertigo by convertigo.

the class Supervision method getServiceResult.

@Override
protected String getServiceResult(HttpServletRequest request) throws Exception {
    boolean isConvertigoStarted = Engine.isStarted;
    boolean bCacheDatabase = false;
    String cacheType = EnginePropertiesManager.getProperty(PropertyName.CACHE_MANAGER_CLASS);
    if ("com.twinsoft.convertigo.engine.cache.DatabaseCacheManager".equals(cacheType)) {
        try {
            SqlRequester sqlRequester = new SqlRequester(DatabaseCacheManager.DB_PROP_FILE_NAME);
            sqlRequester.open();
            Statement statement = null;
            ResultSet resultSet = null;
            StringEx sqlRequest = new StringEx(sqlRequester.getProperty(DatabaseCacheManager.PROPERTIES_SQL_REQUEST_GET_CACHE_ENTRY));
            sqlRequest.replace("{RequestString}", "<supervision>");
            String sSqlRequest = sqlRequest.toString();
            try {
                statement = sqlRequester.connection.createStatement();
                resultSet = statement.executeQuery(sSqlRequest);
            } finally {
                if (resultSet != null) {
                    resultSet.close();
                }
                if (statement != null) {
                    statement.close();
                }
                sqlRequester.close();
            }
            bCacheDatabase = true;
        } catch (Exception e) {
            System.err.println("supervision: error while the database access for the Convertigo Cache");
            e.printStackTrace();
        }
    }
    String result = "";
    result += "convertigo.started=" + (isConvertigoStarted ? "OK" : "KO") + "\n";
    result += "convertigo.database.cache=" + (bCacheDatabase ? "OK" : "KO") + "\n";
    return result;
}
Also used : Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) SqlRequester(com.twinsoft.convertigo.engine.util.SqlRequester) StringEx(com.twinsoft.util.StringEx)

Example 27 with StringEx

use of com.twinsoft.util.StringEx in project convertigo by convertigo.

the class RequestableObject method getBackupWsdlTypes.

protected String getBackupWsdlTypes() throws Exception {
    String backupWsdlTypes = null;
    String wsdlBackupDir = getWsdlBackupDir();
    File dir = new File(wsdlBackupDir);
    if (dir.exists()) {
        File file = new File(wsdlBackupDir + "/" + getName() + ".xml");
        if (file.exists()) {
            DocumentBuilder documentBuilder = XMLUtils.getDefaultDocumentBuilder();
            Document document = documentBuilder.parse(file);
            Element fake = document.getDocumentElement();
            StringEx sx = new StringEx(XMLUtils.prettyPrintElement(fake, true, true));
            sx.replace("<" + fake_root + ">", "");
            sx.replace("</" + fake_root + ">", "");
            backupWsdlTypes = sx.toString();
        }
    }
    return backupWsdlTypes;
}
Also used : DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) StringEx(com.twinsoft.util.StringEx) File(java.io.File)

Example 28 with StringEx

use of com.twinsoft.util.StringEx in project convertigo by convertigo.

the class RequestableObject method backupWsdlTypes.

protected void backupWsdlTypes(Element element) throws TransformerFactoryConfigurationError, Exception {
    if (wsdlType.equals(""))
        return;
    StringEx sx = new StringEx(wsdlType);
    sx.replaceAll("<cdata>", "<![CDATA[");
    sx.replaceAll("</cdata>", "]]>");
    String sDom = "<" + fake_root + ">\n" + sx.toString() + "</" + fake_root + ">";
    DocumentBuilder documentBuilder = XMLUtils.getDefaultDocumentBuilder();
    Document document = documentBuilder.parse(new InputSource(new StringReader(sDom)));
    String wsdlBackupDir = getWsdlBackupDir(element);
    File dir = new File(wsdlBackupDir);
    if (!dir.exists())
        dir.mkdirs();
    File file = new File(wsdlBackupDir + "/" + getName() + ".xml");
    XMLUtils.saveXml(document, file);
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) StringEx(com.twinsoft.util.StringEx) Document(org.w3c.dom.Document) File(java.io.File)

Example 29 with StringEx

use of com.twinsoft.util.StringEx in project convertigo by convertigo.

the class RequestableObject method migrateToXsdTypes.

public String migrateToXsdTypes() {
    String xsdTypes = null;
    try {
        // Retrieve backup wsdlTypes
        String backupWsdlTypes = getBackupWsdlTypes();
        if (backupWsdlTypes != null) {
            StringEx sx = new StringEx(backupWsdlTypes);
            // Replace ccc_xxxResponse by ccc__xxxResponse (Fix ticket #252)
            sx.replace("_" + getName() + "Response\"", "__" + getName() + "Response\"");
            // Fix missing type for sql_output element (SqlTransaction)
            sx.replace("<xsd:element maxOccurs=\"1\" minOccurs=\"0\" name=\"sql_output\"/>", "<xsd:element maxOccurs=\"1\" minOccurs=\"0\" name=\"sql_output\" type=\"xsd:string\"/>");
            // Replace xxxResponse by yyy__xxxResponseData
            sx.replace("\"" + getName() + "Response\"", "\"" + getXsdTypePrefix() + getName() + "ResponseData\"");
            sx.replace(":" + getName() + "Response\"", ":" + getXsdTypePrefix() + getName() + "ResponseData\"");
            sx.replace("__" + getName() + "Response\"", "__" + getName() + "ResponseData\"");
            sx.replaceAll("tns:", getProject().getName() + "_ns:");
            xsdTypes = generateXsdRequestData() + " " + sx.toString();
        }
    } catch (Exception e) {
        Engine.logBeans.error("Unable to migrate to XSD types for requestable \"" + getName() + "\"", e);
    }
    return xsdTypes;
}
Also used : StringEx(com.twinsoft.util.StringEx) NoSuchElementException(java.util.NoSuchElementException) StepException(com.twinsoft.convertigo.beans.steps.StepException) IOException(java.io.IOException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 30 with StringEx

use of com.twinsoft.util.StringEx in project convertigo by convertigo.

the class HtmlTransaction method migrateToXsdTypes.

@Override
public String migrateToXsdTypes() {
    String xsdTypes = null;
    try {
        // Retrieve backup wsdlTypes
        String backupWsdlTypes = getBackupWsdlTypes();
        if (backupWsdlTypes != null) {
            String types = backupWsdlTypes;
            if (isDefault) {
                /* Generate again : correct bug of ref in group */
                types = generateWsdlType(null);
                if (!isPublicAccessibility()) {
                    HtmlConnector connector = (HtmlConnector) getParent();
                    String prefix = (connector.isDefault ? "" : connector.getName() + "__");
                    String transactionName = StringUtils.normalize(prefix + getName(), true) + "Response";
                    /* remove complexType for transaction*/
                    int i = types.indexOf("<xsd:complexType name=\"" + transactionName + "\">");
                    if (i != -1) {
                        int j = types.indexOf("</xsd:complexType>", i);
                        if (j != -1)
                            types = types.substring(0, i) + types.substring(j + "</xsd:complexType>\n".length());
                    }
                }
            }
            // Replace xxxResponse by yyy__xxxResponseData
            StringEx sx = new StringEx(types);
            sx.replace("\"" + getName() + "Response\"", "\"" + getXsdTypePrefix() + getName() + "ResponseData\"");
            sx.replace(":" + getName() + "Response\"", ":" + getXsdTypePrefix() + getName() + "ResponseData\"");
            sx.replace("__" + getName() + "Response\"", "__" + getName() + "ResponseData\"");
            sx.replaceAll("tns:", getProject().getName() + "_ns:");
            xsdTypes = generateXsdRequestData() + " " + sx.toString();
        }
    } catch (Exception e) {
        Engine.logBeans.warn("Unable to migrate to XSD types for requestable \"" + getName() + "\"", e);
    }
    return xsdTypes;
}
Also used : HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) StringEx(com.twinsoft.util.StringEx) EngineException(com.twinsoft.convertigo.engine.EngineException) EvaluatorException(org.mozilla.javascript.EvaluatorException) JavaScriptException(org.mozilla.javascript.JavaScriptException) IOException(java.io.IOException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException)

Aggregations

StringEx (com.twinsoft.util.StringEx)30 EngineException (com.twinsoft.convertigo.engine.EngineException)14 IOException (java.io.IOException)13 Statement (java.sql.Statement)10 SQLException (java.sql.SQLException)9 File (java.io.File)7 PreparedStatement (java.sql.PreparedStatement)7 Document (org.w3c.dom.Document)5 ResultSet (java.sql.ResultSet)4 HttpConnector (com.twinsoft.convertigo.beans.connectors.HttpConnector)3 Element (org.w3c.dom.Element)3 AbstractHttpTransaction (com.twinsoft.convertigo.beans.transactions.AbstractHttpTransaction)2 RequestableHttpVariable (com.twinsoft.convertigo.beans.variables.RequestableHttpVariable)2 RequestableVariable (com.twinsoft.convertigo.beans.variables.RequestableVariable)2 StringReader (java.io.StringReader)2 StringWriter (java.io.StringWriter)2 MalformedURLException (java.net.MalformedURLException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2