Search in sources :

Example 1 with DatabaseException

use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.

the class SqlTableHistory method getHistoryIdsExceptOfHistType.

/* (non-Javadoc)
	 * @see org.parosproxy.paros.db.TbleHistoryIf#getHistoryIdsExceptOfHistType(long, int)
	 */
@Override
public List<Integer> getHistoryIdsExceptOfHistType(long sessionId, int... histTypes) throws DatabaseException {
    if (histTypes == null || histTypes.length == 0) {
        return getHistoryIds(sessionId);
    }
    SqlPreparedStatementWrapper psGetAllHistoryIdsExcTypes = null;
    try {
        List<Integer> v = new ArrayList<>();
        psGetAllHistoryIdsExcTypes = DbSQL.getSingleton().getPreparedStatement("history.ps.gethistoryidsnottypes");
        psGetAllHistoryIdsExcTypes.getPs().setLong(1, sessionId);
        DbSQL.setSetValues(psGetAllHistoryIdsExcTypes.getPs(), 2, histTypes);
        try (ResultSet rs = psGetAllHistoryIdsExcTypes.getPs().executeQuery()) {
            while (rs.next()) {
                v.add(Integer.valueOf(rs.getInt(HISTORYID)));
            }
        }
        return v;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbSQL.getSingleton().releasePreparedStatement(psGetAllHistoryIdsExcTypes);
    }
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 2 with DatabaseException

use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.

the class SqlTableHistory method getHistoryIds.

/* (non-Javadoc)
	 * @see org.parosproxy.paros.db.TbleHistoryIf#getHistoryIds(long)
	 */
@Override
public List<Integer> getHistoryIds(long sessionId) throws DatabaseException {
    SqlPreparedStatementWrapper psGetAllHistoryIds = null;
    try {
        psGetAllHistoryIds = DbSQL.getSingleton().getPreparedStatement("history.ps.gethistoryids");
        List<Integer> v = new ArrayList<>();
        psGetAllHistoryIds.getPs().setLong(1, sessionId);
        try (ResultSet rs = psGetAllHistoryIds.getPs().executeQuery()) {
            while (rs.next()) {
                v.add(Integer.valueOf(rs.getInt(HISTORYID)));
            }
        }
        return v;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbSQL.getSingleton().releasePreparedStatement(psGetAllHistoryIds);
    }
//return getHistoryIdsOfHistType(sessionId, null);
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 3 with DatabaseException

use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.

the class CoreAPI method processAlerts.

private void processAlerts(String baseUrl, int start, int count, Processor<Alert> processor) throws ApiException {
    List<Alert> alerts = new ArrayList<>();
    try {
        TableAlert tableAlert = Model.getSingleton().getDb().getTableAlert();
        // TODO this doesnt work, but should be used when its fixed :/
        //Vector<Integer> v = tableAlert.getAlertListBySession(Model.getSingleton().getSession().getSessionId());
        Vector<Integer> v = tableAlert.getAlertList();
        PaginationConstraintsChecker pcc = new PaginationConstraintsChecker(start, count);
        for (int i = 0; i < v.size(); i++) {
            int alertId = v.get(i).intValue();
            RecordAlert recAlert = tableAlert.read(alertId);
            Alert alert = new Alert(recAlert);
            if (alert.getConfidence() != Alert.CONFIDENCE_FALSE_POSITIVE && !alerts.contains(alert)) {
                if (baseUrl != null && !alert.getUri().startsWith(baseUrl)) {
                    // Not subordinate to the specified URL
                    continue;
                }
                pcc.recordProcessed();
                alerts.add(alert);
                if (!pcc.hasPageStarted()) {
                    continue;
                }
                processor.process(alert);
                if (pcc.hasPageEnded()) {
                    break;
                }
            }
        }
    } catch (DatabaseException e) {
        logger.error(e.getMessage(), e);
        throw new ApiException(ApiException.Type.INTERNAL_ERROR);
    }
}
Also used : TableAlert(org.parosproxy.paros.db.TableAlert) ArrayList(java.util.ArrayList) Alert(org.parosproxy.paros.core.scanner.Alert) RecordAlert(org.parosproxy.paros.db.RecordAlert) ExtensionAlert(org.zaproxy.zap.extension.alert.ExtensionAlert) TableAlert(org.parosproxy.paros.db.TableAlert) DatabaseException(org.parosproxy.paros.db.DatabaseException) RecordAlert(org.parosproxy.paros.db.RecordAlert)

Example 4 with DatabaseException

use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.

the class SqlTableSession method listSessions.

@Override
public List<RecordSession> listSessions() throws DatabaseException {
    SqlPreparedStatementWrapper psList = null;
    try {
        psList = DbSQL.getSingleton().getPreparedStatement("session.ps.list");
        List<RecordSession> result = new ArrayList<>();
        try (ResultSet rs = psList.getPs().executeQuery()) {
            RecordSession ra = build(rs);
            while (ra != null) {
                result.add(ra);
                ra = build(rs);
            }
        }
        return result;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbSQL.getSingleton().releasePreparedStatement(psList);
    }
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) RecordSession(org.parosproxy.paros.db.RecordSession) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 5 with DatabaseException

use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.

the class SqlTableStructure method getChildCount.

@Override
public long getChildCount(long sessionId, long parentId) throws DatabaseException {
    SqlPreparedStatementWrapper psGetChildCount = null;
    try {
        psGetChildCount = DbSQL.getSingleton().getPreparedStatement("structure.ps.getchildcount");
        psGetChildCount.getPs().setLong(1, sessionId);
        psGetChildCount.getPs().setLong(2, parentId);
        try (ResultSet rs = psGetChildCount.getPs().executeQuery()) {
            if (rs.next()) {
                return rs.getLong(1);
            }
        }
        return 0;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbSQL.getSingleton().releasePreparedStatement(psGetChildCount);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Aggregations

DatabaseException (org.parosproxy.paros.db.DatabaseException)182 SQLException (java.sql.SQLException)132 ResultSet (java.sql.ResultSet)70 ArrayList (java.util.ArrayList)31 HttpMalformedHeaderException (org.parosproxy.paros.network.HttpMalformedHeaderException)25 Session (org.parosproxy.paros.model.Session)13 HttpMessage (org.parosproxy.paros.network.HttpMessage)13 PreparedStatement (java.sql.PreparedStatement)12 IOException (java.io.IOException)10 HistoryReference (org.parosproxy.paros.model.HistoryReference)9 URIException (org.apache.commons.httpclient.URIException)8 RecordHistory (org.parosproxy.paros.db.RecordHistory)8 RecordAlert (org.parosproxy.paros.db.RecordAlert)7 RecordContext (org.parosproxy.paros.db.RecordContext)7 HashMap (java.util.HashMap)6 Vector (java.util.Vector)6 Alert (org.parosproxy.paros.core.scanner.Alert)6 ApiException (org.zaproxy.zap.extension.api.ApiException)6 SiteNode (org.parosproxy.paros.model.SiteNode)5 StructuralSiteNode (org.zaproxy.zap.model.StructuralSiteNode)5