Skip to content

Commit

Permalink
replace printStackTrace with logger
Browse files Browse the repository at this point in the history
  • Loading branch information
thestinger committed Mar 13, 2021
1 parent 8625fe9 commit 5a856d7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
9 changes: 5 additions & 4 deletions src/main/java/app/attestation/server/AlertDispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import jakarta.mail.internet.MimeMessage;

import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Properties;

Expand Down Expand Up @@ -172,7 +173,7 @@ protected PasswordAuthentication getPasswordAuthentication() {
updateExpired.reset();
}
} catch (final MessagingException e) {
e.printStackTrace();
logger.log(Level.WARNING, "email error", e);
}
}
selectEmails.reset();
Expand Down Expand Up @@ -205,14 +206,14 @@ protected PasswordAuthentication getPasswordAuthentication() {

Transport.send(message);
} catch (final MessagingException e) {
e.printStackTrace();
logger.log(Level.WARNING, "email error", e);
}
}
selectEmails.reset();
}
}
} catch (final SQLiteException e) {
e.printStackTrace();
logger.log(Level.WARNING, "database error", e);
} finally {
try {
selectConfiguration.reset();
Expand All @@ -222,7 +223,7 @@ protected PasswordAuthentication getPasswordAuthentication() {
selectFailed.reset();
selectEmails.reset();
} catch (final SQLiteException e) {
e.printStackTrace();
logger.log(Level.WARNING, "database error", e);
}
}
}
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/app/attestation/server/AttestationServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.util.Base64;
import java.util.EnumMap;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;
Expand Down Expand Up @@ -369,7 +370,7 @@ public final void handle(final HttpExchange exchange) throws IOException {
}
handlePost(exchange);
} catch (final Exception e) {
e.printStackTrace();
logger.log(Level.SEVERE, "unhandled error handling request", e);
exchange.sendResponseHeaders(500, -1);
} finally {
exchange.close();
Expand Down Expand Up @@ -569,7 +570,7 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx
username = object.getString("username");
password = object.getString("password");
} catch (final ClassCastException | JsonException | NullPointerException e) {
e.printStackTrace();
logger.log(Level.INFO, "invalid request", e);
exchange.sendResponseHeaders(400, -1);
return;
}
Expand All @@ -580,7 +581,7 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx
exchange.sendResponseHeaders(409, -1);
return;
} catch (final GeneralSecurityException e) {
e.printStackTrace();
logger.log(Level.INFO, "invalid request", e);
exchange.sendResponseHeaders(400, -1);
return;
}
Expand All @@ -600,7 +601,7 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx
currentPassword = object.getString("currentPassword");
newPassword = object.getString("newPassword");
} catch (final ClassCastException | JsonException | NullPointerException e) {
e.printStackTrace();
logger.log(Level.INFO, "invalid request", e);
exchange.sendResponseHeaders(400, -1);
return;
}
Expand All @@ -613,7 +614,7 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx
try {
changePassword(account.userId, currentPassword, newPassword);
} catch (final GeneralSecurityException e) {
e.printStackTrace();
logger.log(Level.INFO, "invalid request", e);
exchange.sendResponseHeaders(400, -1);
return;
}
Expand All @@ -631,7 +632,7 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx
username = object.getString("username");
password = object.getString("password");
} catch (final ClassCastException | JsonException | NullPointerException e) {
e.printStackTrace();
logger.log(Level.INFO, "invalid request", e);
exchange.sendResponseHeaders(400, -1);
return;
}
Expand All @@ -643,7 +644,7 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx
exchange.sendResponseHeaders(400, -1);
return;
} catch (final GeneralSecurityException e) {
e.printStackTrace();
logger.log(Level.INFO, "invalid login information", e);
exchange.sendResponseHeaders(403, -1);
return;
}
Expand Down Expand Up @@ -917,7 +918,7 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx
alertDelay = object.getInt("alertDelay");
email = object.getString("email").trim();
} catch (final ClassCastException | JsonException | NullPointerException e) {
e.printStackTrace();
logger.log(Level.INFO, "invalid request", e);
exchange.sendResponseHeaders(400, -1);
return;
}
Expand Down Expand Up @@ -999,7 +1000,7 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx
requestToken = object.getString("requestToken");
fingerprint = object.getString("fingerprint");
} catch (final ClassCastException | JsonException | NullPointerException e) {
e.printStackTrace();
logger.log(Level.INFO, "invalid request", e);
exchange.sendResponseHeaders(400, -1);
return;
}
Expand Down Expand Up @@ -1168,7 +1169,7 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx
writeAttestationHistoryJson(exchange, fingerprint, account, offsetId);
} catch (final ClassCastException | JsonException | NullPointerException | NumberFormatException |
DataFormatException | GeneralSecurityException e) {
e.printStackTrace();
logger.log(Level.INFO, "invalid request", e);
exchange.sendResponseHeaders(400, -1);
return;
}
Expand Down Expand Up @@ -1300,7 +1301,7 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx
try {
AttestationProtocol.verifySerialized(attestationResult, pendingChallenges, userId, subscribeKey == null);
} catch (final BufferUnderflowException | NegativeArraySizeException | DataFormatException | GeneralSecurityException | IOException e) {
e.printStackTrace();
logger.log(Level.INFO, "invalid request", e);
final byte[] response = "Error\n".getBytes();
exchange.sendResponseHeaders(400, response.length);
try (final OutputStream output = exchange.getResponseBody()) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/app/attestation/server/Maintenance.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.almworks.sqlite4java.SQLiteStatement;

import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;

class Maintenance implements Runnable {
Expand Down Expand Up @@ -75,14 +76,14 @@ public void run() {
}
}
} catch (final SQLiteException e) {
e.printStackTrace();
logger.log(Level.WARNING, "database error", e);
} finally {
try {
deleteDeletedDevices.reset();
selectBackups.reset();
updateBackups.reset();
} catch (final SQLiteException e) {
e.printStackTrace();
logger.log(Level.WARNING, "database error", e);
}
}
}
Expand Down

0 comments on commit 5a856d7

Please sign in to comment.