Search in sources :

Example 16 with CerberusException

use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.

the class TestCaseExecutionDAO method updateTCExecution.

@Override
public void updateTCExecution(TestCaseExecution tCExecution) throws CerberusException {
    boolean throwEx = false;
    final String query = "UPDATE testcaseexecution SET test = ?, testcase = ?, description = ?, build = ?, revision = ?, environment = ?, environmentData = ?, country = ?" + ", browser = ?, application = ?, ip = ?, url = ?, port = ?, tag = ?, status = ?" + ", start = ?, end = ? , controlstatus = ?, controlMessage = ?, crbversion = ? " + ", browserFullVersion = ?, version = ?, platform = ?, executor = ?, screensize = ? " + ", ConditionOper = ?, ConditionVal1Init = ?, ConditionVal2Init = ?, ConditionVal1 = ?, ConditionVal2 = ?, ManualExecution = ?, UserAgent = ?, queueId = ?, testCaseVersion = ?, system = ? , robotdecli = ? WHERE id = ?";
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query);
        LOG.debug("SQL.param.id : " + tCExecution.getId());
    }
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            int i = 1;
            preStat.setString(i++, tCExecution.getTest());
            preStat.setString(i++, tCExecution.getTestCase());
            preStat.setString(i++, tCExecution.getDescription());
            preStat.setString(i++, tCExecution.getBuild());
            preStat.setString(i++, tCExecution.getRevision());
            preStat.setString(i++, tCExecution.getEnvironment());
            preStat.setString(i++, tCExecution.getEnvironmentData());
            preStat.setString(i++, tCExecution.getCountry());
            preStat.setString(i++, tCExecution.getBrowser());
            preStat.setString(i++, tCExecution.getApplicationObj().getApplication());
            preStat.setString(i++, tCExecution.getIp());
            preStat.setString(i++, tCExecution.getUrl());
            preStat.setString(i++, tCExecution.getPort());
            preStat.setString(i++, tCExecution.getTag());
            preStat.setString(i++, tCExecution.getStatus());
            preStat.setTimestamp(i++, new Timestamp(tCExecution.getStart()));
            if (tCExecution.getEnd() != 0) {
                preStat.setTimestamp(i++, new Timestamp(tCExecution.getEnd()));
            } else {
                preStat.setString(i++, "1970-01-01 01:01:01");
            }
            preStat.setString(i++, tCExecution.getControlStatus());
            preStat.setString(i++, StringUtil.getLeftString(tCExecution.getControlMessage(), 500));
            preStat.setString(i++, tCExecution.getCrbVersion());
            preStat.setString(i++, tCExecution.getBrowserFullVersion());
            preStat.setString(i++, tCExecution.getVersion());
            preStat.setString(i++, tCExecution.getPlatform());
            preStat.setString(i++, tCExecution.getExecutor());
            preStat.setString(i++, tCExecution.getScreenSize());
            preStat.setString(i++, tCExecution.getConditionOper());
            preStat.setString(i++, StringUtil.getLeftString(tCExecution.getConditionVal1Init(), 65000));
            preStat.setString(i++, StringUtil.getLeftString(tCExecution.getConditionVal2Init(), 65000));
            preStat.setString(i++, StringUtil.getLeftString(tCExecution.getConditionVal1(), 65000));
            preStat.setString(i++, StringUtil.getLeftString(tCExecution.getConditionVal2(), 65000));
            preStat.setString(i++, tCExecution.getManualExecution());
            preStat.setString(i++, tCExecution.getUserAgent());
            preStat.setLong(i++, tCExecution.getQueueID());
            preStat.setInt(i++, tCExecution.getTestCaseVersion());
            preStat.setString(i++, tCExecution.getSystem());
            preStat.setString(i++, tCExecution.getRobotDecli());
            preStat.setLong(i++, tCExecution.getId());
            preStat.executeUpdate();
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
            throwEx = true;
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    if (throwEx) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.EXECUTION_FA));
    }
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp)

Example 17 with CerberusException

use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.

the class TestCaseExecutionDAO method insertTCExecution.

@Override
public long insertTCExecution(TestCaseExecution tCExecution) throws CerberusException {
    boolean throwEx = false;
    final String query = "INSERT INTO testcaseexecution(test, testcase, description, build, revision, environment, environmentData, country, browser, application, ip, " + "url, port, tag, status, start, controlstatus, controlMessage, crbversion, browserFullVersion, executor, screensize," + "conditionOper, conditionVal1Init, conditionVal2Init, conditionVal1, conditionVal2, manualExecution, UserAgent, queueId, testCaseVersion, system, robotdecli) " + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query);
        LOG.debug("SQL.param.id : " + tCExecution.getId());
    }
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
        try {
            int i = 1;
            preStat.setString(i++, tCExecution.getTest());
            preStat.setString(i++, tCExecution.getTestCase());
            preStat.setString(i++, tCExecution.getDescription());
            preStat.setString(i++, tCExecution.getBuild());
            preStat.setString(i++, tCExecution.getRevision());
            preStat.setString(i++, tCExecution.getEnvironment());
            preStat.setString(i++, tCExecution.getEnvironmentData());
            preStat.setString(i++, tCExecution.getCountry());
            preStat.setString(i++, tCExecution.getBrowser());
            preStat.setString(i++, tCExecution.getApplicationObj().getApplication());
            preStat.setString(i++, tCExecution.getIp());
            preStat.setString(i++, tCExecution.getUrl());
            preStat.setString(i++, tCExecution.getPort());
            preStat.setString(i++, tCExecution.getTag());
            preStat.setString(i++, tCExecution.getStatus());
            preStat.setTimestamp(i++, new Timestamp(tCExecution.getStart()));
            preStat.setString(i++, tCExecution.getControlStatus());
            preStat.setString(i++, StringUtil.getLeftString(tCExecution.getControlMessage(), 500));
            preStat.setString(i++, tCExecution.getCrbVersion());
            preStat.setString(i++, tCExecution.getBrowserFullVersion());
            preStat.setString(i++, tCExecution.getExecutor());
            preStat.setString(i++, tCExecution.getScreenSize());
            preStat.setString(i++, tCExecution.getConditionOper());
            preStat.setString(i++, StringUtil.getLeftString(tCExecution.getConditionVal1Init(), 65000));
            preStat.setString(i++, StringUtil.getLeftString(tCExecution.getConditionVal2Init(), 65000));
            preStat.setString(i++, StringUtil.getLeftString(tCExecution.getConditionVal1(), 65000));
            preStat.setString(i++, StringUtil.getLeftString(tCExecution.getConditionVal2(), 65000));
            preStat.setString(i++, tCExecution.getManualExecution());
            preStat.setString(i++, tCExecution.getUserAgent());
            preStat.setLong(i++, tCExecution.getQueueID());
            preStat.setInt(i++, tCExecution.getTestCaseVersion());
            preStat.setString(i++, tCExecution.getSystem());
            preStat.setString(i++, tCExecution.getRobotDecli());
            preStat.executeUpdate();
            ResultSet resultSet = preStat.getGeneratedKeys();
            try {
                if (resultSet.first()) {
                    return resultSet.getInt(1);
                }
            } catch (SQLException exception) {
                LOG.error("Unable to execute query : " + exception.toString());
                throwEx = true;
            } finally {
                resultSet.close();
            }
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
            throwEx = true;
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
        throwEx = true;
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    if (throwEx) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.EXECUTION_FA));
    }
    return 0;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp)

Example 18 with CerberusException

use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.

the class SoapService method callSOAP.

@Override
public AnswerItem<AppService> callSOAP(String envelope, String servicePath, String soapOperation, String attachmentUrl, List<AppServiceHeader> header, String token, int timeOutMs, String system) {
    AnswerItem result = new AnswerItem();
    String unescapedEnvelope = StringEscapeUtils.unescapeXml(envelope);
    boolean is12SoapVersion = SOAP_1_2_NAMESPACE_PATTERN.matcher(unescapedEnvelope).matches();
    AppService serviceSOAP = factoryAppService.create("", AppService.TYPE_SOAP, null, "", "", envelope, "", servicePath, "", soapOperation, "", null, "", null);
    serviceSOAP.setTimeoutms(timeOutMs);
    ByteArrayOutputStream out = null;
    MessageEvent message = null;
    if (StringUtil.isNullOrEmpty(servicePath)) {
        message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSOAP_SERVICEPATHMISSING);
        result.setResultMessage(message);
        return result;
    }
    if (StringUtil.isNullOrEmpty(envelope)) {
        message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSOAP_ENVELOPEMISSING);
        result.setResultMessage(message);
        return result;
    }
    // If header is null we create the list empty.
    if (header == null) {
        header = new ArrayList<>();
    }
    // We feed the header with token + Standard SOAP header.
    if (token != null) {
        header.add(factoryAppServiceHeader.create(null, "cerberus-token", token, "Y", 0, "", "", null, "", null));
    }
    if (StringUtil.isNullOrEmpty(soapOperation)) {
        header.add(factoryAppServiceHeader.create(null, "SOAPAction", "", "Y", 0, "", "", null, "", null));
    } else {
        header.add(factoryAppServiceHeader.create(null, "SOAPAction", "\"" + soapOperation + "\"", "Y", 0, "", "", null, "", null));
    }
    header.add(factoryAppServiceHeader.create(null, "Content-Type", is12SoapVersion ? SOAPConstants.SOAP_1_2_CONTENT_TYPE : SOAPConstants.SOAP_1_1_CONTENT_TYPE, "Y", 0, "", "", null, "", null));
    serviceSOAP.setHeaderList(header);
    SOAPConnectionFactory soapConnectionFactory;
    SOAPConnection soapConnection = null;
    try {
        // Initialize SOAP Connection
        soapConnectionFactory = SOAPConnectionFactory.newInstance();
        soapConnection = soapConnectionFactory.createConnection();
        LOG.debug("Connection opened");
        // Create SOAP Request
        LOG.debug("Create request");
        SOAPMessage input = createSoapRequest(envelope, soapOperation, header, token);
        // Add attachment File if specified
        if (!StringUtil.isNullOrEmpty(attachmentUrl)) {
            this.addAttachmentPart(input, attachmentUrl);
            // Store the SOAP Call
            out = new ByteArrayOutputStream();
            input.writeTo(out);
            LOG.debug("WS call with attachement : " + out.toString());
            serviceSOAP.setServiceRequest(out.toString());
        } else {
            // Store the SOAP Call
            out = new ByteArrayOutputStream();
            input.writeTo(out);
            LOG.debug("WS call : " + out.toString());
        }
        // We already set the item in order to keep the request message in case of failure of SOAP calls.
        serviceSOAP.setService(servicePath);
        result.setItem(serviceSOAP);
        // Call the WS
        LOG.debug("Calling WS.");
        // Reset previous Authentification.
        Authenticator.setDefault(null);
        serviceSOAP.setProxyWithCredential(false);
        serviceSOAP.setProxyUser(null);
        SOAPMessage soapResponse = null;
        if (proxyService.useProxy(servicePath, system)) {
            // Get Proxy host and port from parameters.
            String proxyHost = parameterService.getParameterStringByKey("cerberus_proxy_host", system, DEFAULT_PROXY_HOST);
            int proxyPort = parameterService.getParameterIntegerByKey("cerberus_proxy_port", system, DEFAULT_PROXY_PORT);
            serviceSOAP.setProxy(true);
            serviceSOAP.setProxyHost(proxyHost);
            serviceSOAP.setProxyPort(proxyPort);
            // Create the Proxy.
            SocketAddress sockaddr = new InetSocketAddress(proxyHost, proxyPort);
            try (Socket socket = new Socket()) {
                socket.connect(sockaddr, 10000);
                Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(socket.getInetAddress(), proxyPort));
                if (parameterService.getParameterBooleanByKey("cerberus_proxyauthentification_active", system, DEFAULT_PROXYAUTHENT_ACTIVATE)) {
                    // Get the credentials from parameters.
                    String proxyUser = parameterService.getParameterStringByKey("cerberus_proxyauthentification_user", system, DEFAULT_PROXYAUTHENT_USER);
                    String proxyPass = parameterService.getParameterStringByKey("cerberus_proxyauthentification_password", system, DEFAULT_PROXYAUTHENT_PASSWORD);
                    serviceSOAP.setProxyWithCredential(true);
                    serviceSOAP.setProxyUser(proxyUser);
                    // Define the credential to the proxy.
                    initializeProxyAuthenticator(proxyUser, proxyPass);
                }
                // Call with Proxy.
                soapResponse = sendSOAPMessage(input, servicePath, proxy, timeOutMs);
            } catch (Exception e) {
                LOG.warn(e.toString());
            }
        } else {
            serviceSOAP.setProxy(false);
            serviceSOAP.setProxyHost(null);
            serviceSOAP.setProxyPort(0);
            // Call without proxy.
            soapResponse = sendSOAPMessage(input, servicePath, null, timeOutMs);
        // soapResponse = soapConnection.call(input, servicePath);
        }
        LOG.debug("Called WS.");
        out = new ByteArrayOutputStream();
        // Store the response
        soapResponse.writeTo(out);
        LOG.debug("WS response received.");
        LOG.debug("WS response : " + out.toString());
        message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CALLSOAP);
        message.setDescription(message.getDescription().replace("%SERVICEPATH%", servicePath).replace("%SOAPMETHOD%", soapOperation));
        result.setResultMessage(message);
        // soapResponse.getSOAPPart().getEnvelope().getBody().getFault().getFaultCode();
        // We save convert to string the final response from SOAP request.
        serviceSOAP.setResponseHTTPBody(SoapUtil.convertSoapMessageToString(soapResponse));
        // Get result Content Type.
        serviceSOAP.setResponseHTTPBodyContentType(appServiceService.guessContentType(serviceSOAP, AppService.RESPONSEHTTPBODYCONTENTTYPE_XML));
        result.setItem(serviceSOAP);
    } catch (SOAPException | UnsupportedOperationException | IOException | SAXException | ParserConfigurationException | CerberusException e) {
        LOG.error(e.toString());
        message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSOAP);
        message.setDescription(message.getDescription().replace("%SERVICEPATH%", servicePath).replace("%SOAPMETHOD%", soapOperation).replace("%DESCRIPTION%", e.getMessage()));
        result.setResultMessage(message);
        return result;
    } finally {
        try {
            if (soapConnection != null) {
                soapConnection.close();
            }
            if (out != null) {
                out.close();
            }
        } catch (SOAPException | IOException ex) {
            LOG.error(ex);
        } finally {
            result.setResultMessage(message);
        }
    }
    return result;
}
Also used : SOAPConnectionFactory(javax.xml.soap.SOAPConnectionFactory) IFactoryAppService(org.cerberus.crud.factory.IFactoryAppService) AppService(org.cerberus.crud.entity.AppService) CerberusException(org.cerberus.exception.CerberusException) MessageEvent(org.cerberus.engine.entity.MessageEvent) InetSocketAddress(java.net.InetSocketAddress) SOAPConnection(javax.xml.soap.SOAPConnection) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) AnswerItem(org.cerberus.util.answer.AnswerItem) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPException(javax.xml.soap.SOAPException) CerberusException(org.cerberus.exception.CerberusException) SAXException(org.xml.sax.SAXException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) Proxy(java.net.Proxy) SOAPException(javax.xml.soap.SOAPException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Socket(java.net.Socket)

Example 19 with CerberusException

use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.

the class SQLService method executeCallableStatement.

@Override
public MessageEvent executeCallableStatement(String system, String country, String environment, String database, String sql) {
    String connectionName;
    CountryEnvironmentDatabase countryEnvironmentDatabase;
    MessageEvent msg = new MessageEvent(MessageEventEnum.ACTION_FAILED);
    try {
        countryEnvironmentDatabase = this.countryEnvironmentDatabaseService.convert(this.countryEnvironmentDatabaseService.readByKey(system, country, environment, database));
        if (countryEnvironmentDatabase != null) {
            connectionName = countryEnvironmentDatabase.getConnectionPoolName();
            msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_GENERIC);
            msg.setDescription(msg.getDescription().replace("%JDBC%", "jdbc/" + connectionName));
            if (!(StringUtil.isNullOrEmpty(connectionName))) {
                if (connectionName.contains("cerberus")) {
                    return new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_AGAINST_CERBERUS);
                } else {
                    try (Connection connection = this.databaseSpring.connect(connectionName);
                        CallableStatement cs = connection.prepareCall(sql)) {
                        Integer sqlTimeout = parameterService.getParameterIntegerByKey("cerberus_actionexecutesqlstoredprocedure_timeout", system, 60);
                        cs.setQueryTimeout(sqlTimeout);
                        try {
                            cs.execute();
                            int nbUpdate = cs.getUpdateCount();
                            msg = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_EXECUTESQLSTOREDPROCEDURE).resolveDescription("NBROWS", String.valueOf(nbUpdate)).resolveDescription("JDBC", connectionName).resolveDescription("SQL", sql);
                        } catch (SQLTimeoutException exception) {
                            LOG.warn(exception.toString());
                            msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_TIMEOUT);
                            msg.setDescription(msg.getDescription().replace("%SQL%", sql));
                            msg.setDescription(msg.getDescription().replace("%TIMEOUT%", String.valueOf(sqlTimeout)));
                            msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));
                        } catch (SQLException exception) {
                            LOG.warn(exception.toString());
                            msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_ERROR);
                            msg.setDescription(msg.getDescription().replace("%SQL%", sql));
                            msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));
                        } finally {
                            cs.close();
                        }
                    } catch (SQLException exception) {
                        LOG.warn(exception.toString());
                        msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_ERROR);
                        msg.setDescription(msg.getDescription().replace("%SQL%", sql));
                        msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));
                    } catch (NullPointerException exception) {
                        LOG.warn(exception.toString());
                        msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_CANNOTACCESSJDBC);
                        msg.setDescription(msg.getDescription().replace("%JDBC%", "jdbc/" + connectionName));
                        msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));
                    }
                }
            } else {
                msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_DATABASECONFIGUREDBUTJDBCPOOLEMPTY);
                msg.setDescription(msg.getDescription().replace("%SYSTEM%", system));
                msg.setDescription(msg.getDescription().replace("%COUNTRY%", country));
                msg.setDescription(msg.getDescription().replace("%ENV%", environment));
                msg.setDescription(msg.getDescription().replace("%DATABASE%", database));
            }
        } else {
            msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_DATABASENOTCONFIGURED);
            msg.setDescription(msg.getDescription().replace("%SYSTEM%", system));
            msg.setDescription(msg.getDescription().replace("%COUNTRY%", country));
            msg.setDescription(msg.getDescription().replace("%ENV%", environment));
            msg.setDescription(msg.getDescription().replace("%DATABASE%", database));
        }
    } catch (CerberusException ex) {
        LOG.error(ex.toString());
    }
    return msg;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) SQLTimeoutException(java.sql.SQLTimeoutException) CountryEnvironmentDatabase(org.cerberus.crud.entity.CountryEnvironmentDatabase)

Example 20 with CerberusException

use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.

the class SQLService method executeUpdate.

@Override
public MessageEvent executeUpdate(String system, String country, String environment, String database, String sql) {
    String connectionName;
    CountryEnvironmentDatabase countryEnvironmentDatabase;
    MessageEvent msg = new MessageEvent(MessageEventEnum.ACTION_FAILED);
    try {
        countryEnvironmentDatabase = this.countryEnvironmentDatabaseService.convert(this.countryEnvironmentDatabaseService.readByKey(system, country, environment, database));
        if (countryEnvironmentDatabase != null) {
            connectionName = countryEnvironmentDatabase.getConnectionPoolName();
            msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_GENERIC);
            msg.setDescription(msg.getDescription().replace("%JDBC%", "jdbc/" + connectionName));
            if (!(StringUtil.isNullOrEmpty(connectionName))) {
                if (connectionName.equals("cerberus" + System.getProperty("org.cerberus.environment"))) {
                    return new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_AGAINST_CERBERUS);
                } else {
                    try (Connection connection = this.databaseSpring.connect(connectionName);
                        PreparedStatement preStat = connection.prepareStatement(sql)) {
                        Integer sqlTimeout = parameterService.getParameterIntegerByKey("cerberus_actionexecutesqlupdate_timeout", system, 60);
                        preStat.setQueryTimeout(sqlTimeout);
                        try {
                            LOG.info("Sending to external Database (executeUpdate) : '" + connectionName + "' SQL '" + sql + "'");
                            preStat.executeUpdate();
                            int nbUpdate = preStat.getUpdateCount();
                            msg = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_EXECUTESQLUPDATE).resolveDescription("NBROWS", String.valueOf(nbUpdate)).resolveDescription("JDBC", connectionName).resolveDescription("SQL", sql);
                        } catch (SQLTimeoutException exception) {
                            LOG.warn(exception.toString());
                            msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_TIMEOUT);
                            msg.setDescription(msg.getDescription().replace("%SQL%", sql));
                            msg.setDescription(msg.getDescription().replace("%TIMEOUT%", String.valueOf(sqlTimeout)));
                            msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));
                        } catch (SQLException exception) {
                            LOG.warn(exception.toString());
                            msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_ERROR);
                            msg.setDescription(msg.getDescription().replace("%SQL%", sql));
                            msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));
                        }
                    } catch (SQLException exception) {
                        LOG.warn(exception.toString());
                        msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_ERROR);
                        msg.setDescription(msg.getDescription().replace("%SQL%", sql));
                        msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));
                    } catch (NullPointerException exception) {
                        LOG.warn(exception.toString());
                        msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_CANNOTACCESSJDBC);
                        msg.setDescription(msg.getDescription().replace("%JDBC%", "jdbc/" + connectionName));
                        msg.setDescription(msg.getDescription().replace("%EX%", exception.toString()));
                    }
                }
            } else {
                msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_DATABASECONFIGUREDBUTJDBCPOOLEMPTY);
                msg.setDescription(msg.getDescription().replace("%SYSTEM%", system));
                msg.setDescription(msg.getDescription().replace("%COUNTRY%", country));
                msg.setDescription(msg.getDescription().replace("%ENV%", environment));
                msg.setDescription(msg.getDescription().replace("%DATABASE%", database));
            }
        } else {
            msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_SQL_DATABASENOTCONFIGURED);
            msg.setDescription(msg.getDescription().replace("%SYSTEM%", system));
            msg.setDescription(msg.getDescription().replace("%COUNTRY%", country));
            msg.setDescription(msg.getDescription().replace("%ENV%", environment));
            msg.setDescription(msg.getDescription().replace("%DATABASE%", database));
        }
    } catch (CerberusException ex) {
        LOG.error(ex.toString());
    }
    return msg;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) SQLTimeoutException(java.sql.SQLTimeoutException) PreparedStatement(java.sql.PreparedStatement) CountryEnvironmentDatabase(org.cerberus.crud.entity.CountryEnvironmentDatabase)

Aggregations

CerberusException (org.cerberus.exception.CerberusException)159 MessageEvent (org.cerberus.engine.entity.MessageEvent)64 MessageGeneral (org.cerberus.engine.entity.MessageGeneral)58 ApplicationContext (org.springframework.context.ApplicationContext)58 JSONObject (org.json.JSONObject)54 JSONException (org.json.JSONException)53 Connection (java.sql.Connection)48 SQLException (java.sql.SQLException)48 PreparedStatement (java.sql.PreparedStatement)47 AnswerItem (org.cerberus.util.answer.AnswerItem)41 ArrayList (java.util.ArrayList)37 IOException (java.io.IOException)35 PolicyFactory (org.owasp.html.PolicyFactory)35 ILogEventService (org.cerberus.crud.service.ILogEventService)34 Answer (org.cerberus.util.answer.Answer)34 ServletException (javax.servlet.ServletException)26 ResultSet (java.sql.ResultSet)18 TestCase (org.cerberus.crud.entity.TestCase)16 JSONArray (org.json.JSONArray)16 HashMap (java.util.HashMap)12