use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.
the class Control method newSession.
public Session newSession() throws Exception {
log.info("New Session");
closeSessionAndCreateAndOpenUntitledDb();
final Session session = createNewSession();
getExtensionLoader().databaseOpen(model.getDb());
getExtensionLoader().sessionChangedAllPlugin(session);
if (View.isInitialised()) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
view.getSiteTreePanel().getTreeSite().setModel(session.getSiteTree());
view.getSiteTreePanel().reloadContextTree();
}
});
// refresh display
view.getMainFrame().setTitle(session.getSessionName());
view.getOutputPanel().clear();
}
try {
model.getDb().getTableSession().insert(session.getSessionId(), session.getSessionName());
} catch (DatabaseException e) {
log.error(e.getMessage(), e);
}
return session;
}
use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.
the class HttpBreakpointsUiManagerInterface method showAddDialog.
private void showAddDialog(Message aMessage) {
HttpBreakpointMessage.Match match = HttpBreakpointMessage.Match.regex;
HttpMessage msg = (HttpMessage) aMessage;
String regex = "";
if (msg.getHistoryRef() != null && msg.getHistoryRef().getSiteNode() != null) {
try {
regex = new StructuralSiteNode(msg.getHistoryRef().getSiteNode()).getRegexPattern(false);
} catch (DatabaseException e) {
// Ignore
}
}
if (regex.length() == 0 && msg.getRequestHeader().getURI() != null) {
// Just use the escaped url
regex = msg.getRequestHeader().getURI().toString();
match = HttpBreakpointMessage.Match.contains;
}
this.showAddDialog(regex, match);
}
use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.
the class ParosTableHistory method getHistoryIdsExceptOfHistType.
/**
* Returns all the history record IDs of the given session except the ones with the given history types.
**
* @param sessionId the ID of session of the history records
* @param histTypes the history types of the history records that should be excluded
* @return a {@code List} with all the history IDs of the given session and history types, never {@code null}
* @throws DatabaseException if an error occurred while getting the history IDs
* @since 2.3.0
* @see #getHistoryIdsOfHistType(long, int...)
*/
@Override
public List<Integer> getHistoryIdsExceptOfHistType(long sessionId, int... histTypes) throws DatabaseException {
try {
boolean hasHistTypes = histTypes != null && histTypes.length > 0;
int strLength = hasHistTypes ? 102 : 68;
StringBuilder sb = new StringBuilder(strLength);
sb.append("SELECT ").append(HISTORYID);
sb.append(" FROM ").append(TABLE_NAME).append(" WHERE ").append(SESSIONID).append(" = ?");
if (hasHistTypes) {
sb.append(" AND ").append(HISTTYPE).append(" NOT IN ( UNNEST(?) )");
}
sb.append(" ORDER BY ").append(HISTORYID);
try (PreparedStatement psReadSession = getConnection().prepareStatement(sb.toString())) {
psReadSession.setLong(1, sessionId);
if (hasHistTypes) {
Array arrayHistTypes = getConnection().createArrayOf("INTEGER", ArrayUtils.toObject(histTypes));
psReadSession.setArray(2, arrayHistTypes);
}
try (ResultSet rs = psReadSession.executeQuery()) {
ArrayList<Integer> ids = new ArrayList<>();
while (rs.next()) {
ids.add(Integer.valueOf(rs.getInt(HISTORYID)));
}
ids.trimToSize();
return ids;
}
}
} catch (SQLException e) {
throw new DatabaseException(e);
}
}
use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.
the class ParosTableHistory method delete.
@Override
public synchronized void delete(int historyId) throws DatabaseException {
try {
psDelete.setInt(1, historyId);
psDelete.executeUpdate();
} catch (SQLException e) {
throw new DatabaseException(e);
}
}
use of org.parosproxy.paros.db.DatabaseException in project zaproxy by zaproxy.
the class ParosTableHistory method reconnect.
@Override
protected void reconnect(Connection conn) throws DatabaseException {
try {
//ZAP: Allow the request and response body sizes to be user-specifiable as far as possible
//re-load the configuration data from file, to get the configured length of the request and response bodies
//this will later be compared to the actual lengths of these fields in the database (in updateTable(Connection c))
DatabaseParam dbparams = new DatabaseParam();
dbparams.load(Constant.getInstance().FILE_CONFIG);
this.configuredrequestbodysize = dbparams.getRequestBodySize();
this.configuredresponsebodysize = dbparams.getResponseBodySize();
bodiesAsBytes = true;
updateTable(conn);
isExistStatusCode = DbUtils.hasColumn(conn, TABLE_NAME, STATUSCODE);
psRead = conn.prepareStatement("SELECT TOP 1 * FROM HISTORY WHERE " + HISTORYID + " = ?");
// updatable recordset does not work in hsqldb jdbc impelementation!
//psWrite = mConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
psDelete = conn.prepareStatement("DELETE FROM HISTORY WHERE " + HISTORYID + " = ?");
psDeleteTemp = conn.prepareStatement("DELETE FROM HISTORY WHERE " + HISTTYPE + " IN (?) LIMIT 1000");
psContainsURI = conn.prepareStatement("SELECT TOP 1 HISTORYID FROM HISTORY WHERE URI = ? AND METHOD = ? AND REQBODY = ? AND SESSIONID = ? AND HISTTYPE = ?");
// ZAP: Added support for the tag when creating a history record
if (isExistStatusCode) {
psInsert = conn.prepareStatement("INSERT INTO HISTORY (" + SESSIONID + "," + HISTTYPE + "," + TIMESENTMILLIS + "," + TIMEELAPSEDMILLIS + "," + METHOD + "," + URI + "," + REQHEADER + "," + REQBODY + "," + RESHEADER + "," + RESBODY + "," + TAG + ", " + STATUSCODE + "," + NOTE + ", " + RESPONSE_FROM_TARGET_HOST + ") VALUES (?, ? ,?, ?, ?, ?, ?, ? ,? , ?, ?, ?, ?, ?)");
} else {
psInsert = conn.prepareStatement("INSERT INTO HISTORY (" + SESSIONID + "," + HISTTYPE + "," + TIMESENTMILLIS + "," + TIMEELAPSEDMILLIS + "," + METHOD + "," + URI + "," + REQHEADER + "," + REQBODY + "," + RESHEADER + "," + RESBODY + "," + TAG + "," + NOTE + ", " + RESPONSE_FROM_TARGET_HOST + ") VALUES (?, ? ,?, ?, ?, ?, ?, ? ,? , ? , ?, ?, ?)");
}
psGetIdLastInsert = conn.prepareCall("CALL IDENTITY();");
// psUpdateTag = conn.prepareStatement("UPDATE HISTORY SET TAG = ? WHERE HISTORYID = ?");
psUpdateNote = conn.prepareStatement("UPDATE HISTORY SET NOTE = ? WHERE HISTORYID = ?");
int currentIndex = 0;
PreparedStatement stmt = null;
try {
stmt = conn.prepareStatement("SELECT TOP 1 HISTORYID FROM HISTORY ORDER BY HISTORYID DESC");
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
currentIndex = rs.getInt(1);
}
}
} finally {
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
if (log.isDebugEnabled()) {
log.debug(e.getMessage(), e);
}
}
}
}
lastInsertedIndex = currentIndex;
} catch (SQLException e) {
throw new DatabaseException(e);
}
}
Aggregations