Search in sources :

Example 1 with RecordStructure

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

the class SessionStructure method addStructure.

private static RecordStructure addStructure(Session session, String host, HttpMessage msg, List<String> paths, int size, int historyId) throws DatabaseException, URIException {
    //String nodeUrl = pathsToUrl(host, paths, size);
    String nodeName = getNodeName(session, host, msg, paths, size);
    String parentName = pathsToUrl(host, paths, size - 1);
    String url = "";
    if (msg != null) {
        url = msg.getRequestHeader().getURI().toString();
        String params = getParams(session, msg);
        if (params.length() > 0) {
            nodeName = nodeName + " " + params;
        }
    }
    String method = HttpRequestHeader.GET;
    if (msg != null) {
        method = msg.getRequestHeader().getMethod();
    }
    RecordStructure msgRs = Model.getSingleton().getDb().getTableStructure().find(session.getSessionId(), nodeName, method);
    if (msgRs == null) {
        long parentId = -1;
        if (!nodeName.equals("Root")) {
            HttpMessage tmpMsg = null;
            int parentHistoryId = -1;
            if (!parentName.equals("Root")) {
                tmpMsg = getTempHttpMessage(session, parentName, msg);
                parentHistoryId = tmpMsg.getHistoryRef().getHistoryId();
            }
            RecordStructure parentRs = addStructure(session, host, tmpMsg, paths, size - 1, parentHistoryId);
            parentId = parentRs.getStructureId();
        }
        msgRs = Model.getSingleton().getDb().getTableStructure().insert(session.getSessionId(), parentId, historyId, nodeName, url, method);
    }
    return msgRs;
}
Also used : RecordStructure(org.parosproxy.paros.db.RecordStructure) HttpMessage(org.parosproxy.paros.network.HttpMessage)

Example 2 with RecordStructure

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

the class ParosTableStructure method read.

/* (non-Javadoc)
	 * @see org.parosproxy.paros.db.paros.TableParam#read(long)
	 */
@Override
public synchronized RecordStructure read(long sessionId, long urlId) throws DatabaseException {
    try {
        psRead.setLong(1, sessionId);
        psRead.setLong(2, urlId);
        try (ResultSet rs = psRead.executeQuery()) {
            RecordStructure result = build(rs);
            return result;
        }
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : RecordStructure(org.parosproxy.paros.db.RecordStructure) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 3 with RecordStructure

use of org.parosproxy.paros.db.RecordStructure 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 4 with RecordStructure

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

the class SqlTableStructure method getChildren.

@Override
public List<RecordStructure> getChildren(long sessionId, long parentId) throws DatabaseException {
    SqlPreparedStatementWrapper psGetChildren = null;
    try {
        psGetChildren = DbSQL.getSingleton().getPreparedStatement("structure.ps.getchildren");
        psGetChildren.getPs().setLong(1, sessionId);
        psGetChildren.getPs().setLong(2, parentId);
        List<RecordStructure> result = new ArrayList<>();
        try (ResultSet rs = psGetChildren.getPs().executeQuery()) {
            while (rs.next()) {
                result.add(build(rs));
            }
        }
        return result;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbSQL.getSingleton().releasePreparedStatement(psGetChildren);
    }
}
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 5 with RecordStructure

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

the class SqlTableStructure method read.

/* (non-Javadoc)
	 * @see org.parosproxy.paros.db.paros.TableParam#read(long)
	 */
@Override
public synchronized RecordStructure read(long sessionId, long urlId) throws DatabaseException {
    SqlPreparedStatementWrapper psRead = null;
    try {
        psRead = DbSQL.getSingleton().getPreparedStatement("structure.ps.read");
        psRead.getPs().setLong(1, sessionId);
        psRead.getPs().setLong(2, urlId);
        try (ResultSet rs = psRead.getPs().executeQuery()) {
            RecordStructure result = null;
            if (rs.next()) {
                result = build(rs);
            }
            return result;
        }
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbSQL.getSingleton().releasePreparedStatement(psRead);
    }
}
Also used : RecordStructure(org.parosproxy.paros.db.RecordStructure) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Aggregations

RecordStructure (org.parosproxy.paros.db.RecordStructure)8 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 DatabaseException (org.parosproxy.paros.db.DatabaseException)4 ArrayList (java.util.ArrayList)2 InvalidParameterException (java.security.InvalidParameterException)1 NoSuchElementException (java.util.NoSuchElementException)1 Model (org.parosproxy.paros.model.Model)1 SiteNode (org.parosproxy.paros.model.SiteNode)1 HttpMessage (org.parosproxy.paros.network.HttpMessage)1