From d0ee991d9ba982e43acd036c2d0592976ba9e9ff Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sun, 31 Jul 2016 14:17:14 +0200 Subject: [PATCH] chg: Avoid dirtying the environment with Thread Interruption exceptions if nobody handles them anyway Change-Id: I8fd3ced25e058c24752776702425888576397c92 --- .../cacert/gigi/api/CreateCertificate.java | 2 -- .../cacert/gigi/api/RevokeCertificate.java | 31 ++++++++++--------- src/org/cacert/gigi/dbObjects/Job.java | 9 ++++-- .../account/certs/CertificateIssueForm.java | 2 -- .../certs/CertificateModificationForm.java | 14 +++------ .../org/cacert/gigi/pages/Manager.java | 3 -- 6 files changed, 28 insertions(+), 33 deletions(-) diff --git a/src/org/cacert/gigi/api/CreateCertificate.java b/src/org/cacert/gigi/api/CreateCertificate.java index 0d5a27e0..1c589379 100644 --- a/src/org/cacert/gigi/api/CreateCertificate.java +++ b/src/org/cacert/gigi/api/CreateCertificate.java @@ -79,8 +79,6 @@ public class CreateCertificate extends APIPoint { resp.setStatus(500); PrintWriter wr = resp.getWriter(); e.formatPlain(wr); - } catch (InterruptedException e) { - resp.sendError(500, "Interrupted"); } } } diff --git a/src/org/cacert/gigi/api/RevokeCertificate.java b/src/org/cacert/gigi/api/RevokeCertificate.java index 404d73ce..2f15511a 100644 --- a/src/org/cacert/gigi/api/RevokeCertificate.java +++ b/src/org/cacert/gigi/api/RevokeCertificate.java @@ -21,31 +21,32 @@ public class RevokeCertificate extends APIPoint { resp.sendError(500, "Error, POST required."); return; } + if (req.getQueryString() != null) { resp.sendError(500, "Error, no query String allowed."); return; } + String tserial = req.getParameter("serial"); if (tserial == null) { resp.sendError(500, "Error, no Serial found"); return; } - try { - Certificate c = Certificate.getBySerial(tserial); - if (c == null || c.getOwner() != u) { - resp.sendError(403, "Access Denied"); - return; - } - Job job = c.revoke(); - job.waitFor(60000); - if (c.getStatus() != CertificateStatus.REVOKED) { - resp.sendError(510, "Error, issuing timed out"); - return; - } - resp.getWriter().println("OK"); + + Certificate c = Certificate.getBySerial(tserial); + if (c == null || c.getOwner() != u) { + resp.sendError(403, "Access Denied"); + return; + } + + Job job = c.revoke(); + job.waitFor(60000); + if (c.getStatus() != CertificateStatus.REVOKED) { + resp.sendError(510, "Error, issuing timed out"); return; - } catch (InterruptedException e) { - e.printStackTrace(); } + + resp.getWriter().println("OK"); + } } diff --git a/src/org/cacert/gigi/dbObjects/Job.java b/src/org/cacert/gigi/dbObjects/Job.java index bb357a8d..a48e44ac 100644 --- a/src/org/cacert/gigi/dbObjects/Job.java +++ b/src/org/cacert/gigi/dbObjects/Job.java @@ -51,7 +51,7 @@ public class Job implements IdCachable { } } - public synchronized boolean waitFor(int max) throws InterruptedException { + public synchronized boolean waitFor(int max) { long start = System.currentTimeMillis(); try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT 1 FROM `jobs` WHERE id=? AND state='open'")) { ps.setInt(1, id); @@ -61,7 +61,12 @@ public class Job implements IdCachable { if (max != 0 && System.currentTimeMillis() - start > max) { return false; } - Thread.sleep((long) (2000 + Math.random() * 2000)); + try { + this.wait((long) (2000 + Math.random() * 2000)); + } catch (InterruptedException ie) { + // Ignore the interruption + ie.printStackTrace(); + } rs = ps.executeQuery(); } } diff --git a/src/org/cacert/gigi/pages/account/certs/CertificateIssueForm.java b/src/org/cacert/gigi/pages/account/certs/CertificateIssueForm.java index c32fc716..eecb31fe 100644 --- a/src/org/cacert/gigi/pages/account/certs/CertificateIssueForm.java +++ b/src/org/cacert/gigi/pages/account/certs/CertificateIssueForm.java @@ -104,8 +104,6 @@ public class CertificateIssueForm extends Form { } catch (GeneralSecurityException e) { e.printStackTrace(); throw new GigiApiException("Certificate Request format is invalid."); - } catch (InterruptedException e) { - e.printStackTrace(); } } catch (GigiApiException e) { e.format(out, Page.getLanguage(req)); diff --git a/src/org/cacert/gigi/pages/account/certs/CertificateModificationForm.java b/src/org/cacert/gigi/pages/account/certs/CertificateModificationForm.java index 6553a773..a58f3a6c 100644 --- a/src/org/cacert/gigi/pages/account/certs/CertificateModificationForm.java +++ b/src/org/cacert/gigi/pages/account/certs/CertificateModificationForm.java @@ -48,15 +48,11 @@ public class CertificateModificationForm extends Form { } long start = System.currentTimeMillis(); for (Job job : revokes) { - try { - int toWait = (int) (60000 + start - System.currentTimeMillis()); - if (toWait > 0) { - job.waitFor(toWait); - } else { - break; // canceled... waited too log - } - } catch (InterruptedException e) { - e.printStackTrace(); + int toWait = (int) (60000 + start - System.currentTimeMillis()); + if (toWait > 0) { + job.waitFor(toWait); + } else { + break; // canceled... waited too log } } diff --git a/util-testing/org/cacert/gigi/pages/Manager.java b/util-testing/org/cacert/gigi/pages/Manager.java index 21b7e432..f6de409b 100644 --- a/util-testing/org/cacert/gigi/pages/Manager.java +++ b/util-testing/org/cacert/gigi/pages/Manager.java @@ -352,9 +352,6 @@ public class Manager extends Page { resp.getWriter().println("error"); } catch (GigiApiException e) { e.format(resp.getWriter(), Language.getInstance(Locale.ENGLISH)); - } catch (InterruptedException e) { - e.printStackTrace(); - resp.getWriter().println("interrupted"); } } else if (req.getParameter("addExDom") != null) { -- 2.39.2