Search in sources :

Example 31 with DatabaseException

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

the class ParosTableContext method reconnect.

@Override
protected void reconnect(Connection conn) throws DatabaseException {
    try {
        if (!DbUtils.hasTable(conn, TABLE_NAME)) {
            // Need to create the table
            DbUtils.executeAndClose(conn.prepareStatement("CREATE cached TABLE CONTEXT_DATA (dataid bigint generated by default as identity (start with 1), contextId int not null, type int not null, data varchar(8192) default '')"));
        }
        psRead = conn.prepareStatement("SELECT * FROM CONTEXT_DATA WHERE " + DATAID + " = ?");
        psInsert = conn.prepareStatement("INSERT INTO CONTEXT_DATA (" + CONTEXTID + "," + TYPE + "," + DATA + ") VALUES (?, ?, ?)");
        psGetIdLastInsert = conn.prepareCall("CALL IDENTITY();");
        psDeleteData = conn.prepareStatement("DELETE FROM CONTEXT_DATA WHERE " + CONTEXTID + " = ? AND " + TYPE + " = ? AND " + DATA + " = ?");
        psDeleteAllDataForContext = conn.prepareStatement("DELETE FROM CONTEXT_DATA WHERE " + CONTEXTID + " = ?");
        psDeleteAllDataForContextAndType = conn.prepareStatement("DELETE FROM CONTEXT_DATA WHERE " + CONTEXTID + " = ? AND " + TYPE + " = ?");
        psGetAllData = conn.prepareStatement("SELECT * FROM CONTEXT_DATA");
        psGetAllDataForContext = conn.prepareStatement("SELECT * FROM CONTEXT_DATA WHERE " + CONTEXTID + " = ?");
        psGetAllDataForContextAndType = conn.prepareStatement("SELECT * FROM CONTEXT_DATA WHERE " + CONTEXTID + " = ? AND " + TYPE + " = ?");
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : SQLException(java.sql.SQLException) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 32 with DatabaseException

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

the class ParosTableContext method deleteAllDataForContextAndType.

/* (non-Javadoc)
	 * @see org.parosproxy.paros.db.paros.TableContext#deleteAllDataForContextAndType(int, int)
	 */
@Override
public synchronized void deleteAllDataForContextAndType(int contextId, int type) throws DatabaseException {
    try {
        psDeleteAllDataForContextAndType.setInt(1, contextId);
        psDeleteAllDataForContextAndType.setInt(2, type);
        psDeleteAllDataForContextAndType.executeUpdate();
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : SQLException(java.sql.SQLException) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 33 with DatabaseException

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

the class ParosTableContext method getDataForContext.

/* (non-Javadoc)
	 * @see org.parosproxy.paros.db.paros.TableContext#getDataForContext(int)
	 */
@Override
public synchronized List<RecordContext> getDataForContext(int contextId) throws DatabaseException {
    try {
        List<RecordContext> result = new ArrayList<>();
        psGetAllDataForContext.setInt(1, contextId);
        try (ResultSet rs = psGetAllDataForContext.executeQuery()) {
            while (rs.next()) {
                result.add(new RecordContext(rs.getLong(DATAID), rs.getInt(CONTEXTID), rs.getInt(TYPE), rs.getString(DATA)));
            }
        }
        return result;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) RecordContext(org.parosproxy.paros.db.RecordContext) ResultSet(java.sql.ResultSet) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 34 with DatabaseException

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

the class MenuFileControl method openDbBasedSession.

private void openDbBasedSession() {
    try {
        List<String> sessionList = new ArrayList<String>();
        for (RecordSession rs : model.getDb().getTableSession().listSessions()) {
            sessionList.add("" + rs.getSessionId());
        }
        SessionTableSelectDialog ssd = new SessionTableSelectDialog(View.getSingleton().getMainFrame(), sessionList);
        ssd.setVisible(true);
        if (ssd.getSelectedSession() != null) {
            waitMessageDialog = view.getWaitMessageDialog(Constant.messages.getString("menu.file.loadSession"));
            control.openSession(ssd.getSelectedSession(), this);
            waitMessageDialog.setVisible(true);
        }
    } catch (DatabaseException e) {
        log.error(e.getMessage(), e);
    }
}
Also used : ArrayList(java.util.ArrayList) SessionTableSelectDialog(org.zaproxy.zap.view.SessionTableSelectDialog) RecordSession(org.parosproxy.paros.db.RecordSession) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 35 with DatabaseException

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

the class ActiveScan method notifyNewMessage.

@Override
public void notifyNewMessage(final HttpMessage msg) {
    HistoryReference hRef = msg.getHistoryRef();
    if (hRef == null) {
        try {
            hRef = new HistoryReference(Model.getSingleton().getSession(), HistoryReference.TYPE_SCANNER_TEMPORARY, msg);
            msg.setHistoryRef(null);
            hRefs.add(Integer.valueOf(hRef.getHistoryId()));
        } catch (HttpMalformedHeaderException | DatabaseException e) {
            log.error(e.getMessage(), e);
        }
    } else {
        hRefs.add(Integer.valueOf(hRef.getHistoryId()));
    }
    this.rcTotals.incResponseCodeCount(msg.getResponseHeader().getStatusCode());
    if (hRef != null && this.rcTotals.getTotal() <= this.maxResultsToList) {
        // Very large lists significantly impact the UI responsiveness
        // limiting them makes large scans _much_ quicker
        addHistoryReference(hRef);
    }
}
Also used : HistoryReference(org.parosproxy.paros.model.HistoryReference) HttpMalformedHeaderException(org.parosproxy.paros.network.HttpMalformedHeaderException) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Aggregations

DatabaseException (org.parosproxy.paros.db.DatabaseException)153 SQLException (java.sql.SQLException)113 ResultSet (java.sql.ResultSet)61 ArrayList (java.util.ArrayList)28 HttpMalformedHeaderException (org.parosproxy.paros.network.HttpMalformedHeaderException)19 PreparedStatement (java.sql.PreparedStatement)11 Session (org.parosproxy.paros.model.Session)11 HttpMessage (org.parosproxy.paros.network.HttpMessage)11 RecordHistory (org.parosproxy.paros.db.RecordHistory)9 RecordAlert (org.parosproxy.paros.db.RecordAlert)7 RecordContext (org.parosproxy.paros.db.RecordContext)7 Vector (java.util.Vector)6 URIException (org.apache.commons.httpclient.URIException)6 IOException (java.io.IOException)5 TableHistory (org.parosproxy.paros.db.TableHistory)5 HistoryReference (org.parosproxy.paros.model.HistoryReference)5 StructuralSiteNode (org.zaproxy.zap.model.StructuralSiteNode)5 Matcher (java.util.regex.Matcher)4 PatternSyntaxException (java.util.regex.PatternSyntaxException)4 JSONException (net.sf.json.JSONException)4