Skip to content

Commit

Permalink
Fix InterruptedException while stopping the spider
Browse files Browse the repository at this point in the history
Append the messages to output tab and add the messages to History tab
asynchronously in the EDT, preventing the exceptions (and "hanging" the
spider worker threads more time than needed).

More detailed changes:
 - AuthenticationHelper, append the authentication status messages
 to the OutputPanel and add the authentication messages to the
 ExtensionHistory, asynchronously (for the latter also check if the View
 is initialised, otherwise there's no point adding it);
 - OutputPanel, add a convenience method that adds a message
 asynchronously to the panel itself.

Fix zaproxy#2429 - InterruptedExceptions while stopping the spider with user
authentication
  • Loading branch information
thc202 committed Apr 22, 2016
1 parent 6baff51 commit a882e19
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
17 changes: 17 additions & 0 deletions src/org/parosproxy/paros/view/OutputPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,21 @@ private void doAppend(String message){
getTxtOutput().append(message);
}

/**
* Appends the given {@code message} to the panel, asynchronously in the EDT.
*
* @param message the message to append to the output panel
* @since TODO add version
* @see EventQueue#invokeLater(Runnable)
*/
public void appendAsync(final String message) {
EventQueue.invokeLater(new Runnable() {

@Override
public void run() {
doAppend(message);
}
});
}

} // @jve:decl-index=0:visual-constraint="10,10"
24 changes: 17 additions & 7 deletions src/org/zaproxy/zap/authentication/AuthenticationHelper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.zaproxy.zap.authentication;

import java.awt.EventQueue;
import java.io.IOException;

import org.apache.commons.httpclient.HttpState;
Expand Down Expand Up @@ -57,7 +58,7 @@ public static void notifyOutputAuthSuccessful(HttpMessage msg) {
// Let the user know it worked
if (View.isInitialised()) {
View.getSingleton().getOutputPanel()
.append(Constant.messages.getString("authentication.output.success") + "\n");
.appendAsync(Constant.messages.getString("authentication.output.success") + "\n");
}
}

Expand All @@ -71,7 +72,7 @@ public static void notifyOutputAuthFailure(HttpMessage msg) {
// Let the user know it failed
if (View.isInitialised()) {
View.getSingleton().getOutputPanel()
.append(Constant.messages.getString("authentication.output.failure") + "\n");
.appendAsync(Constant.messages.getString("authentication.output.failure") + "\n");
}
}

Expand All @@ -84,13 +85,22 @@ public HttpState getCorrespondingHttpState() {
public static void addAuthMessageToHistory(HttpMessage msg) {
// Add message to history
try {
HistoryReference ref = new HistoryReference(Model.getSingleton().getSession(),
final HistoryReference ref = new HistoryReference(Model.getSingleton().getSession(),
HistoryReference.TYPE_AUTHENTICATION, msg);
ref.addTag(HISTORY_TAG_AUTHENTICATION);
ExtensionHistory extHistory = Control.getSingleton().getExtensionLoader()
.getExtension(ExtensionHistory.class);
if (extHistory != null) {
extHistory.addHistory(ref);
if (View.isInitialised()) {
final ExtensionHistory extHistory = Control.getSingleton()
.getExtensionLoader()
.getExtension(ExtensionHistory.class);
if (extHistory != null) {
EventQueue.invokeLater(new Runnable() {

@Override
public void run() {
extHistory.addHistory(ref);
}
});
}
}
} catch (Exception ex) {
log.error("Cannot add authentication message to History tab.", ex);
Expand Down

0 comments on commit a882e19

Please sign in to comment.