Search in sources :

Example 81 with DatabaseException

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

the class ParosTableStructure method getChildren.

@Override
public List<RecordStructure> getChildren(long sessionId, long parentId) throws DatabaseException {
    try {
        psGetChildren.setLong(1, sessionId);
        psGetChildren.setLong(2, parentId);
        List<RecordStructure> result = new ArrayList<>();
        try (ResultSet rs = psGetChildren.executeQuery()) {
            while (rs.next()) {
                result.add(build(rs));
            }
        }
        return result;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : RecordStructure(org.parosproxy.paros.db.RecordStructure) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 82 with DatabaseException

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

the class ParosTableTag 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 TAG (tagid bigint generated by default as identity (start with 1), historyid bigint not null, tag varchar(1024) default '')"));
        }
        psRead = conn.prepareStatement("SELECT * FROM TAG WHERE " + TAGID + " = ?");
        psInsertTag = conn.prepareStatement("INSERT INTO TAG (" + HISTORYID + "," + TAG + ") VALUES (?, ?)");
        psGetIdLastInsert = conn.prepareCall("CALL IDENTITY();");
        psDeleteTag = conn.prepareStatement("DELETE FROM TAG WHERE " + HISTORYID + " = ? AND " + TAG + " = ?");
        psGetTagsForHistoryId = conn.prepareStatement("SELECT * FROM TAG WHERE " + HISTORYID + " = ?");
        psDeleteTagsForHistoryId = conn.prepareStatement("DELETE FROM TAG WHERE " + HISTORYID + " = ?");
        psGetAllTags = conn.prepareStatement("SELECT DISTINCT TAG FROM TAG ORDER BY TAG");
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : SQLException(java.sql.SQLException) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 83 with DatabaseException

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

the class ParosTableHistory method read.

@Override
public synchronized RecordHistory read(int historyId) throws HttpMalformedHeaderException, DatabaseException {
    try {
        psRead.setInt(1, historyId);
        psRead.execute();
        RecordHistory result = null;
        try (ResultSet rs = psRead.getResultSet()) {
            result = build(rs);
        }
        return result;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) RecordHistory(org.parosproxy.paros.db.RecordHistory) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 84 with DatabaseException

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

the class ParosTableHistory method updateNote.

@Override
public synchronized void updateNote(int historyId, String note) throws DatabaseException {
    try {
        psUpdateNote.setString(1, note);
        psUpdateNote.setInt(2, historyId);
        psUpdateNote.execute();
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : SQLException(java.sql.SQLException) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 85 with DatabaseException

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

the class ParosTableHistory method write.

@Override
public synchronized RecordHistory write(long sessionId, int histType, HttpMessage msg) throws HttpMalformedHeaderException, DatabaseException {
    try {
        String reqHeader = "";
        byte[] reqBody = new byte[0];
        String resHeader = "";
        byte[] resBody = reqBody;
        String method = "";
        String uri = "";
        int statusCode = 0;
        String note = msg.getNote();
        if (!msg.getRequestHeader().isEmpty()) {
            reqHeader = msg.getRequestHeader().toString();
            reqBody = msg.getRequestBody().getBytes();
            method = msg.getRequestHeader().getMethod();
            uri = msg.getRequestHeader().getURI().toString();
        }
        if (!msg.getResponseHeader().isEmpty()) {
            resHeader = msg.getResponseHeader().toString();
            resBody = msg.getResponseBody().getBytes();
            statusCode = msg.getResponseHeader().getStatusCode();
        }
        //return write(sessionId, histType, msg.getTimeSentMillis(), msg.getTimeElapsedMillis(), method, uri, statusCode, reqHeader, reqBody, resHeader, resBody, msg.getTag());
        return write(sessionId, histType, msg.getTimeSentMillis(), msg.getTimeElapsedMillis(), method, uri, statusCode, reqHeader, reqBody, resHeader, resBody, null, note, msg.isResponseFromTargetHost());
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : SQLException(java.sql.SQLException) 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